Skip to content

Commit 97dada1

Browse files
Merge pull request #257 from omersch381/unbound_to_statefulset
Change Unbound deployment type to StatefulSet
2 parents 21fa99a + 17ae999 commit 97dada1

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

controllers/designate_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
10701070
Log.Info("Deployment Backendbind9 task reconciled")
10711071

10721072
// deploy the unbound reconcilier if necessary
1073-
designateUnbound, op, err := r.unboundDeploymentCreateOrUpdate(ctx, instance)
1073+
designateUnbound, op, err := r.unboundStatefulSetCreateOrUpdate(ctx, instance)
10741074
if err != nil {
10751075
instance.Status.Conditions.Set(condition.FalseCondition(
10761076
designatev1beta1.DesignateUnboundReadyCondition,
@@ -1679,11 +1679,11 @@ func (r *DesignateReconciler) backendbind9StatefulSetCreateOrUpdate(ctx context.
16791679
return statefulSet, op, err
16801680
}
16811681

1682-
func (r *DesignateReconciler) unboundDeploymentCreateOrUpdate(
1682+
func (r *DesignateReconciler) unboundStatefulSetCreateOrUpdate(
16831683
ctx context.Context,
16841684
instance *designatev1beta1.Designate,
16851685
) (*designatev1beta1.DesignateUnbound, controllerutil.OperationResult, error) {
1686-
deployment := &designatev1beta1.DesignateUnbound{
1686+
statefulSet := &designatev1beta1.DesignateUnbound{
16871687
ObjectMeta: metav1.ObjectMeta{
16881688
Name: fmt.Sprintf("%s-unbound", instance.Name),
16891689
Namespace: instance.Namespace,
@@ -1694,22 +1694,22 @@ func (r *DesignateReconciler) unboundDeploymentCreateOrUpdate(
16941694
instance.Spec.DesignateUnbound.NodeSelector = instance.Spec.NodeSelector
16951695
}
16961696

1697-
op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error {
1698-
deployment.Spec = instance.Spec.DesignateUnbound
1697+
op, err := controllerutil.CreateOrUpdate(ctx, r.Client, statefulSet, func() error {
1698+
statefulSet.Spec = instance.Spec.DesignateUnbound
16991699
// Add in transfers from umbrella Designate CR (this instance) spec
17001700
// TODO: Add logic to determine when to set/overwrite, etc
1701-
deployment.Spec.ServiceAccount = instance.RbacResourceName()
1702-
deployment.Spec.NodeSelector = instance.Spec.DesignateUnbound.NodeSelector
1701+
statefulSet.Spec.ServiceAccount = instance.RbacResourceName()
1702+
statefulSet.Spec.NodeSelector = instance.Spec.DesignateUnbound.NodeSelector
17031703

1704-
err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
1704+
err := controllerutil.SetControllerReference(instance, statefulSet, r.Scheme)
17051705
if err != nil {
17061706
return err
17071707
}
17081708

17091709
return nil
17101710
})
17111711

1712-
return deployment, op, err
1712+
return statefulSet, op, err
17131713
}
17141714

17151715
// checkDesignateAPIGeneration -

controllers/designateunbound_controller.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ import (
3636

3737
"github.com/openstack-k8s-operators/lib-common/modules/common"
3838
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
39-
"github.com/openstack-k8s-operators/lib-common/modules/common/deployment"
4039
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
4140
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
4241
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
4342
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
4443
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"
4544
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
45+
"github.com/openstack-k8s-operators/lib-common/modules/common/statefulset"
4646
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
4747
)
4848

@@ -154,7 +154,7 @@ func (r *UnboundReconciler) SetupWithManager(mgr ctrl.Manager) error {
154154
Owns(&corev1.Service{}).
155155
Owns(&corev1.Secret{}).
156156
Owns(&corev1.ConfigMap{}).
157-
Owns(&appsv1.Deployment{}).
157+
Owns(&appsv1.StatefulSet{}).
158158
Complete(r)
159159
}
160160

@@ -317,14 +317,16 @@ func (r *UnboundReconciler) reconcileNormal(ctx context.Context, instance *desig
317317
return ctrlResult, nil
318318
}
319319

320-
depl := deployment.NewDeployment(
321-
designateunbound.Deployment(instance, inputHash, serviceLabels, serviceAnnotations),
320+
// Define a new Unbound StatefulSet object
321+
statefulSetDef := designateunbound.StatefulSet(instance, inputHash, serviceLabels, serviceAnnotations)
322+
statefulSet := statefulset.NewStatefulSet(
323+
statefulSetDef,
322324
time.Duration(5)*time.Second,
323325
)
324326

325327
r.Log.Info("deploying the unbound pod")
326328

327-
ctrlResult, err = depl.CreateOrPatch(ctx, helper)
329+
ctrlResult, err = statefulSet.CreateOrPatch(ctx, helper)
328330
if err != nil {
329331
instance.Status.Conditions.Set(condition.FalseCondition(
330332
condition.DeploymentReadyCondition,
@@ -342,8 +344,8 @@ func (r *UnboundReconciler) reconcileNormal(ctx context.Context, instance *desig
342344
return ctrlResult, nil
343345
}
344346

345-
if depl.GetDeployment().Generation == depl.GetDeployment().Status.ObservedGeneration {
346-
instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas
347+
if statefulSet.GetStatefulSet().Generation == statefulSet.GetStatefulSet().Status.ObservedGeneration {
348+
instance.Status.ReadyCount = statefulSet.GetStatefulSet().Status.ReadyReplicas
347349

348350
r.Log.Info("verifying network attachments")
349351
// verify if network attachment matches expectations
@@ -382,7 +384,7 @@ func (r *UnboundReconciler) reconcileNormal(ctx context.Context, instance *desig
382384
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
383385
}
384386
}
385-
// create Deployment - end
387+
// create StatefulSet - end
386388

387389
// We reached the end of the Reconcile, update the Ready condition based on
388390
// the sub conditions

pkg/designateunbound/deployment.go renamed to pkg/designateunbound/statefulset.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ const (
3232
configVolume = "designateunbound-config"
3333
)
3434

35-
// Deployment func
36-
func Deployment(instance *designatev1beta1.DesignateUnbound,
35+
// StatefulSet func
36+
func StatefulSet(instance *designatev1beta1.DesignateUnbound,
3737
configHash string,
3838
labels map[string]string,
3939
annotations map[string]string,
40-
) *appsv1.Deployment {
40+
) *appsv1.StatefulSet {
4141
var configMode int32 = 0640
4242

4343
volumes := []corev1.Volume{
@@ -63,7 +63,7 @@ func Deployment(instance *designatev1beta1.DesignateUnbound,
6363
// TODO might need tuning
6464
TimeoutSeconds: 15,
6565
PeriodSeconds: 13,
66-
InitialDelaySeconds: 10,
66+
InitialDelaySeconds: 15,
6767
}
6868
readinessProbe := &corev1.Probe{
6969
// TODO might need tuning
@@ -92,12 +92,12 @@ func Deployment(instance *designatev1beta1.DesignateUnbound,
9292
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
9393
envVars["CONFIG_HASH"] = env.SetValue(configHash)
9494

95-
deployment := &appsv1.Deployment{
95+
statefulSet := &appsv1.StatefulSet{
9696
ObjectMeta: metav1.ObjectMeta{
9797
Name: instance.Name,
9898
Namespace: instance.Namespace,
9999
},
100-
Spec: appsv1.DeploymentSpec{
100+
Spec: appsv1.StatefulSetSpec{
101101
Replicas: instance.Spec.Replicas,
102102
Selector: &metav1.LabelSelector{
103103
MatchLabels: labels,
@@ -139,16 +139,16 @@ func Deployment(instance *designatev1beta1.DesignateUnbound,
139139
// If possible two pods of the same service should not
140140
// run on the same worker node. If this is not possible
141141
// the get still created on the same worker node.
142-
deployment.Spec.Template.Spec.Affinity = affinity.DistributePods(
142+
statefulSet.Spec.Template.Spec.Affinity = affinity.DistributePods(
143143
common.AppSelector,
144144
[]string{
145145
designate.ServiceName,
146146
},
147147
corev1.LabelHostname,
148148
)
149149
if instance.Spec.NodeSelector != nil {
150-
deployment.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
150+
statefulSet.Spec.Template.Spec.NodeSelector = *instance.Spec.NodeSelector
151151
}
152152

153-
return deployment
153+
return statefulSet
154154
}

0 commit comments

Comments
 (0)