Skip to content

Commit f14a9a6

Browse files
Merge pull request openstack-k8s-operators#353 from ASBishop/node-selector-hash
Restart services when their NodeSelector changes
2 parents c46d63a + df33f3e commit f14a9a6

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

controllers/cinderapi_controller.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,20 @@ func (r *CinderAPIReconciler) reconcileNormal(ctx context.Context, instance *cin
706706
// all cert input checks out so report InputReady
707707
instance.Status.Conditions.MarkTrue(condition.TLSInputReadyCondition, condition.InputReadyMessage)
708708

709+
//
710+
// Hash the nodeSelector so the pod is recreated when it changes
711+
//
712+
err = cinder.AddNodeSelectorHash(instance.Spec.NodeSelector, &configVars)
713+
if err != nil {
714+
instance.Status.Conditions.Set(condition.FalseCondition(
715+
condition.ServiceConfigReadyCondition,
716+
condition.ErrorReason,
717+
condition.SeverityWarning,
718+
condition.ServiceConfigReadyErrorMessage,
719+
err.Error()))
720+
return ctrl.Result{}, err
721+
}
722+
709723
//
710724
// Create secrets required as input for the Service and calculate an overall hash of hashes
711725
//

controllers/cinderbackup_controller.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,20 @@ func (r *CinderBackupReconciler) reconcileNormal(ctx context.Context, instance *
410410
// all cert input checks out so report InputReady
411411
instance.Status.Conditions.MarkTrue(condition.TLSInputReadyCondition, condition.InputReadyMessage)
412412

413+
//
414+
// Hash the nodeSelector so the pod is recreated when it changes
415+
//
416+
err = cinder.AddNodeSelectorHash(instance.Spec.NodeSelector, &configVars)
417+
if err != nil {
418+
instance.Status.Conditions.Set(condition.FalseCondition(
419+
condition.ServiceConfigReadyCondition,
420+
condition.ErrorReason,
421+
condition.SeverityWarning,
422+
condition.ServiceConfigReadyErrorMessage,
423+
err.Error()))
424+
return ctrl.Result{}, err
425+
}
426+
413427
//
414428
// Create secrets required as input for the Service and calculate an overall hash of hashes
415429
//

controllers/cinderscheduler_controller.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,20 @@ func (r *CinderSchedulerReconciler) reconcileNormal(ctx context.Context, instanc
409409
// all cert input checks out so report InputReady
410410
instance.Status.Conditions.MarkTrue(condition.TLSInputReadyCondition, condition.InputReadyMessage)
411411

412+
//
413+
// Hash the nodeSelector so the pod is recreated when it changes
414+
//
415+
err = cinder.AddNodeSelectorHash(instance.Spec.NodeSelector, &configVars)
416+
if err != nil {
417+
instance.Status.Conditions.Set(condition.FalseCondition(
418+
condition.ServiceConfigReadyCondition,
419+
condition.ErrorReason,
420+
condition.SeverityWarning,
421+
condition.ServiceConfigReadyErrorMessage,
422+
err.Error()))
423+
return ctrl.Result{}, err
424+
}
425+
412426
//
413427
// Create ConfigMaps required as input for the Service and calculate an overall hash of hashes
414428
//

controllers/cindervolume_controller.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,20 @@ func (r *CinderVolumeReconciler) reconcileNormal(ctx context.Context, instance *
434434
return ctrl.Result{}, err
435435
}
436436

437+
//
438+
// Hash the nodeSelector so the pod is recreated when it changes
439+
//
440+
err = cinder.AddNodeSelectorHash(instance.Spec.NodeSelector, &configVars)
441+
if err != nil {
442+
instance.Status.Conditions.Set(condition.FalseCondition(
443+
condition.ServiceConfigReadyCondition,
444+
condition.ErrorReason,
445+
condition.SeverityWarning,
446+
condition.ServiceConfigReadyErrorMessage,
447+
err.Error()))
448+
return ctrl.Result{}, err
449+
}
450+
437451
//
438452
// create hash over all the different input resources to identify if any those changed
439453
// and a restart/recreate is required.

pkg/cinder/funcs.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cinder
33
import (
44
common "github.com/openstack-k8s-operators/lib-common/modules/common"
55
"github.com/openstack-k8s-operators/lib-common/modules/common/affinity"
6+
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
7+
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
68

79
corev1 "k8s.io/api/core/v1"
810
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -47,3 +49,12 @@ func GetPodAffinity(componentName string) *corev1.Affinity {
4749
corev1.LabelHostname,
4850
)
4951
}
52+
53+
// AddNodeSelectorHash - Adds a hash of a nodeSelector map to the envVars.
54+
func AddNodeSelectorHash(nodeSelector map[string]string, envVars *map[string]env.Setter) error {
55+
hash, err := util.ObjectHash(nodeSelector)
56+
if err != nil {
57+
(*envVars)["NodeSelectorHash"] = env.SetValue(hash)
58+
}
59+
return err
60+
}

0 commit comments

Comments
 (0)