Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch cinder-api to a statefulset #309

Merged
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
12 changes: 0 additions & 12 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ rules:
- list
- update
- watch
- apiGroups:
- apps
resources:
- deployments
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
Expand Down
20 changes: 10 additions & 10 deletions controllers/cinderapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ import (
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/deployment"
"github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
"github.com/openstack-k8s-operators/lib-common/modules/common/statefulset"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
)

Expand Down Expand Up @@ -97,7 +97,7 @@ var (
// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;create;update;patch;delete;watch
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;create;update;patch;delete;watch
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;create;update;patch;delete;watch
// +kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=get;list;create;update;patch;delete;watch
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneservices,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneendpoints,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=k8s.cni.cncf.io,resources=network-attachment-definitions,verbs=get;list;watch
Expand Down Expand Up @@ -255,7 +255,7 @@ func (r *CinderAPIReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&cinderv1beta1.CinderAPI{}).
Owns(&keystonev1.KeystoneService{}).
Owns(&keystonev1.KeystoneEndpoint{}).
Owns(&appsv1.Deployment{}).
Owns(&appsv1.StatefulSet{}).
Owns(&corev1.Service{}).
// watch the secrets we don't own
Watches(&source.Kind{Type: &corev1.Secret{}},
Expand Down Expand Up @@ -658,14 +658,14 @@ func (r *CinderAPIReconciler) reconcileNormal(ctx context.Context, instance *cin
// normal reconcile tasks
//

// Define a new Deployment object
deplDef := cinderapi.Deployment(instance, inputHash, serviceLabels, serviceAnnotations)
depl := deployment.NewDeployment(
deplDef,
// Deploy a statefulset
ssDef := cinderapi.StatefulSet(instance, inputHash, serviceLabels, serviceAnnotations)
ss := statefulset.NewStatefulSet(
ssDef,
time.Duration(5)*time.Second,
)

ctrlResult, err = depl.CreateOrPatch(ctx, helper)
ctrlResult, err = ss.CreateOrPatch(ctx, helper)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DeploymentReadyCondition,
Expand All @@ -682,7 +682,7 @@ func (r *CinderAPIReconciler) reconcileNormal(ctx context.Context, instance *cin
condition.DeploymentReadyRunningMessage))
return ctrlResult, nil
}
instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas
instance.Status.ReadyCount = ss.GetStatefulSet().Status.ReadyReplicas

// verify if network attachment matches expectations
networkReady := false
Expand Down Expand Up @@ -720,7 +720,7 @@ func (r *CinderAPIReconciler) reconcileNormal(ctx context.Context, instance *cin
if instance.Status.ReadyCount > 0 {
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
}
// create Deployment - end
// create StatefulSet - end

r.Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name))
return ctrl.Result{}, nil
Expand Down
18 changes: 9 additions & 9 deletions pkg/cinderapi/deployment.go → pkg/cinderapi/statefuleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ const (
ServiceCommand = "/usr/local/bin/kolla_set_configs && /usr/local/bin/kolla_start"
)

// Deployment func
func Deployment(
// StatefulSet func
func StatefulSet(
instance *cinderv1beta1.CinderAPI,
configHash string,
labels map[string]string,
annotations map[string]string,
) *appsv1.Deployment {
) *appsv1.StatefulSet {
runAsUser := int64(0)

livenessProbe := &corev1.Probe{
Expand Down Expand Up @@ -80,13 +80,13 @@ func Deployment(
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
envVars["CONFIG_HASH"] = env.SetValue(configHash)

deployment := &appsv1.Deployment{
statefulset := &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: instance.Name,
Namespace: instance.Namespace,
Labels: labels,
},
Spec: appsv1.DeploymentSpec{
Spec: appsv1.StatefulSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Expand Down Expand Up @@ -144,24 +144,24 @@ func Deployment(
},
},
}
deployment.Spec.Template.Spec.Volumes = GetVolumes(
statefulset.Spec.Template.Spec.Volumes = GetVolumes(
cinder.GetOwningCinderName(instance),
instance.Name,
instance.Spec.ExtraMounts)

// If possible two pods of the same service should not
// run on the same worker node. If this is not possible
// the get still created on the same worker node.
deployment.Spec.Template.Spec.Affinity = affinity.DistributePods(
statefulset.Spec.Template.Spec.Affinity = affinity.DistributePods(
common.AppSelector,
[]string{
cinder.ServiceName,
},
corev1.LabelHostname,
)
if instance.Spec.NodeSelector != nil && len(instance.Spec.NodeSelector) > 0 {
deployment.Spec.Template.Spec.NodeSelector = instance.Spec.NodeSelector
statefulset.Spec.Template.Spec.NodeSelector = instance.Spec.NodeSelector
}

return deployment
return statefulset
}
2 changes: 1 addition & 1 deletion test/functional/cinder_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ var _ = Describe("Cinder controller", func() {
keystone.SimulateKeystoneServiceReady(cinderTest.CinderKeystoneService)
})
It("Check the resulting endpoints of the generated sub-CRs", func() {
th.SimulateDeploymentReadyWithPods(
th.SimulateStatefulSetReplicaReadyWithPods(
cinderTest.CinderAPI,
map[string][]string{cinderName.Namespace + "/internalapi": {"10.0.0.1"}},
)
Expand Down
13 changes: 6 additions & 7 deletions test/kuttl/common/assert_sample_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
replicas: 1
---
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
name: cinder-api
ownerReferences:
Expand All @@ -31,18 +31,13 @@ metadata:
kind: CinderAPI
name: cinder-api
spec:
progressDeadlineSeconds: 600
podManagementPolicy: OrderedReady
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
component: cinder-api
service: cinder
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
Expand Down Expand Up @@ -162,6 +157,10 @@ spec:
name: config-data-custom
- emptyDir: {}
name: logs
updateStrategy:
rollingUpdate:
partition: 0
type: RollingUpdate
status:
availableReplicas: 1
replicas: 1
Expand Down