Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ linters:
- tagliatelle
- varnamelen
- nilnil
- godot

issues:
exclude-rules:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [unpublished]
- Add ability to specify key in failover password secret
- Improve leader election logic

## [1.0.0-rc1]

### Added
Expand Down
39 changes: 32 additions & 7 deletions apis/v1beta1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v1beta1

import (
"github.com/tarantool/tarantool-operator/pkg/api"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -121,7 +120,7 @@ type FailoverEtcd2 struct {

// Password for etcd2 connection
// +optional
Password corev1.SecretReference `json:"password"`
Password SecretKeyReference `json:"password"`

// LockDelay - Timeout (in seconds), determines lock’s time-to-live (default: 10)
// +kubebuilder:default=10
Expand All @@ -141,8 +140,8 @@ func (in *FailoverEtcd2) GetUsername() string {
return in.Username
}

func (in *FailoverEtcd2) GetPassword() corev1.SecretReference {
return in.Password
func (in *FailoverEtcd2) GetPassword() api.SecretKeyReference {
return &in.Password
}

func (in *FailoverEtcd2) GetLockDelay() int32 {
Expand All @@ -162,15 +161,41 @@ type FailoverStateboard struct {

// Password for etcd2 connection
// +optional
Password corev1.SecretReference `json:"password"`
Password SecretKeyReference `json:"password"`
}

func (in *FailoverStateboard) GetURI() string {
return in.URI
}

func (in *FailoverStateboard) GetPassword() corev1.SecretReference {
return in.Password
func (in *FailoverStateboard) GetPassword() api.SecretKeyReference {
return &in.Password
}

// SecretKeyReference represents a reference to filed in Secret. It has enough information to retrieve a value secret in any namespace.
// +structType=atomic
type SecretKeyReference struct {
// Namespace defines the space within which the secret name must be unique.
// +optional
Namespace string `json:"namespace"`
// Name is unique within a namespace to reference a secret resource.
// +optional
Name string `json:"name"`
// Key is unique within a Secret to reference a value.
// +optional
Key string `json:"key"`
}

func (in *SecretKeyReference) GetNamespace() string {
return in.Namespace
}

func (in *SecretKeyReference) GetName() string {
return in.Name
}

func (in *SecretKeyReference) GetKey() string {
return in.Key
}

// ClusterPhase is a label for the condition of a Cluster at the current time.
Expand Down
12 changes: 8 additions & 4 deletions apis/v1beta1/role_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,17 @@ type RoleStatus struct {
// Phase of roles
// +kubebuilder:default=Pending
Phase RolePhase `json:"phase"`

// ReadyPods a string in format "ready_pods_count/total_pods_count" for printable column
ReadyPods string `json:"readyPods"`
}

// Role is the Schema for the roles API
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",priority=0
// +kubebuilder:printcolumn:name="Replicasets",type="number",JSONPath=".status.replicasets",priority=1
// +kubebuilder:printcolumn:name="Ready replicasets",type="number",JSONPath=".status.readyReplicasets",priority=1
// +kubebuilder:printcolumn:name="Replicas",type="number",JSONPath=".status.replicas",priority=1
// +kubebuilder:printcolumn:name="Ready replicas",type="number",JSONPath=".status.readyReplicas",priority=1
// +kubebuilder:printcolumn:name="Pods",type="number",JSONPath=".status.readyPods",priority=1
// +kubebuilder:printcolumn:name="Weight",type="number",JSONPath=".status.weight",priority=0
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",priority=0
// +k8s:openapi-gen=true
Expand Down Expand Up @@ -171,6 +171,10 @@ func (in *Role) ResetStatus() {
in.Status = RoleStatus{}
}

func (in *Role) SetReadyPodsCount(count int32) {
in.Status.ReadyPods = fmt.Sprintf("%d/%d", count, in.GetReplicasets()*in.GetReplicas())
}

func (in *Role) SetPhase(phase RolePhase) {
in.Status.Phase = phase
}
Expand Down
15 changes: 15 additions & 0 deletions apis/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config/crd/bases/tarantool.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ spec:
type: integer
password:
properties:
key:
type: string
name:
type: string
namespace:
Expand Down Expand Up @@ -152,6 +154,8 @@ spec:
properties:
password:
properties:
key:
type: string
name:
type: string
namespace:
Expand Down
19 changes: 5 additions & 14 deletions config/crd/bases/tarantool.io_roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3459,20 +3459,8 @@ spec:
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .status.replicasets
name: Replicasets
priority: 1
type: number
- jsonPath: .status.readyReplicasets
name: Ready replicasets
priority: 1
type: number
- jsonPath: .status.replicas
name: Replicas
priority: 1
type: number
- jsonPath: .status.readyReplicas
name: Ready replicas
- jsonPath: .status.readyPods
name: Pods
priority: 1
type: number
- jsonPath: .status.weight
Expand Down Expand Up @@ -6833,8 +6821,11 @@ spec:
phase:
default: Pending
type: string
readyPods:
type: string
required:
- phase
- readyPods
type: object
required:
- metadata
Expand Down
1 change: 1 addition & 0 deletions controllers/cartridgeconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func NewCartridgeConfigReconciler(mgr Manager) *CartridgeConfigReconciler {
Client: k8sClient,
Recorder: eventsRecorder,
ResourcesManager: resourcesManager,
Topology: luaTopology,
},
ResourcesManager: resourcesManager,
EventsRecorder: eventsRecorder,
Expand Down
2 changes: 2 additions & 0 deletions controllers/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func NewClusterReconciler(mgr Manager) *ClusterReconciler {
Client: k8sClient,
Recorder: eventsRecorder,
ResourcesManager: resourcesManager,
Topology: luaTopology,
},
ResourcesManager: resourcesManager,
EventsRecorder: eventsRecorder,
Expand Down Expand Up @@ -144,6 +145,7 @@ func (r *ClusterReconciler) SetupWithManager(mgr Manager) error {
return NewControllerManagedBy(mgr).
For(&Cluster{}).
Owns(&v1.Service{}).
Watches(&source.Kind{Type: &v1.Secret{}}, &handler.EnqueueRequestForOwner{OwnerType: &Cluster{}, IsController: false}).
Watches(&source.Kind{Type: &Role{}}, handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
role, ok := obj.(*Role)
if !ok {
Expand Down
10 changes: 9 additions & 1 deletion controllers/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var _ = Describe("cluster_controller unit testing", func() {
Client: fakeClient,
Recorder: eventsRecorder,
ResourcesManager: resourcesManager,
Topology: fakeTopologyService,
},
ResourcesManager: resourcesManager,
LabelsManager: labelsManager,
Expand Down Expand Up @@ -122,13 +123,17 @@ var _ = Describe("cluster_controller unit testing", func() {
It("Must bootstrap cluster if all roles ready", func() {
cartridge.
WithAllRolesInPhase(v1beta1.RoleWaitingForBootstrap).
WithAllPodsReady()
WithAllPodsRunning()

fakeTopologyService.
On("BootstrapVshard", mock.Anything, mock.Anything).
Return(nil).
Once()

fakeTopologyService.
On("IsCartridgeStarted", mock.Anything, mock.Anything).
Return(true, nil)

fakeClient := cartridge.BuildFakeClient()

resourcesManager := &ResourcesManager{
Expand Down Expand Up @@ -158,6 +163,7 @@ var _ = Describe("cluster_controller unit testing", func() {
Client: fakeClient,
Recorder: eventsRecorder,
ResourcesManager: resourcesManager,
Topology: fakeTopologyService,
},
ResourcesManager: resourcesManager,
LabelsManager: labelsManager,
Expand Down Expand Up @@ -208,6 +214,7 @@ var _ = Describe("cluster_controller unit testing", func() {
Client: fakeClient,
Recorder: eventsRecorder,
ResourcesManager: resourcesManager,
Topology: fakeTopologyService,
},
ResourcesManager: resourcesManager,
LabelsManager: labelsManager,
Expand Down Expand Up @@ -260,6 +267,7 @@ var _ = Describe("cluster_controller unit testing", func() {
Client: fakeClient,
Recorder: eventsRecorder,
ResourcesManager: resourcesManager,
Topology: fakeTopologyService,
},
ResourcesManager: resourcesManager,
LabelsManager: labelsManager,
Expand Down
1 change: 1 addition & 0 deletions controllers/role_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func NewRoleReconciler(mgr Manager) *RoleReconciler {
Client: k8sClient,
Recorder: eventsRecorder,
ResourcesManager: resourcesManager,
Topology: luaTopology,
},
ResourcesManager: resourcesManager,
EventsRecorder: eventsRecorder,
Expand Down
12 changes: 8 additions & 4 deletions pkg/api/failover.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package api

import v1 "k8s.io/api/core/v1"

type FailoverMode string

const (
Expand Down Expand Up @@ -33,12 +31,18 @@ type FailoverConfig interface {
type FailoverETCD2Config interface {
GetEndpoints() []string
GetUsername() string
GetPassword() v1.SecretReference
GetPassword() SecretKeyReference
GetLockDelay() int32
GetPrefix() string
}

type FailoverStateboardConfig interface {
GetURI() string
GetPassword() v1.SecretReference
GetPassword() SecretKeyReference
}

type SecretKeyReference interface {
GetNamespace() string
GetName() string
GetKey() string
}
2 changes: 2 additions & 0 deletions pkg/api/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Role interface {
GetVShardConfig() VShardConfig

ResetStatus()

SetReadyPodsCount(count int32)
}

type VShardConfig interface {
Expand Down
Loading