Skip to content

Commit

Permalink
update ds only if ds changed in last version
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Shitrit <[email protected]>
  • Loading branch information
mshitrit committed Aug 1, 2023
1 parent 5bf4b4c commit a7018a1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions controllers/selfnoderemediationconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ import (
"github.com/medik8s/self-node-remediation/pkg/render"
)

const dsName = "self-node-remediation-ds"
const (
dsName = "self-node-remediation-ds"
lastChangedAnnotationKey = "dsLastChangeVersion"
lastChangeAnnotationVal = "rhwa-23.3"
)

// SelfNodeRemediationConfigReconciler reconciles a SelfNodeRemediationConfig object
type SelfNodeRemediationConfigReconciler struct {
Expand Down Expand Up @@ -107,7 +111,7 @@ func (r *SelfNodeRemediationConfigReconciler) syncConfigDaemonSet(ctx context.Co
logger := r.Log.WithName("syncConfigDaemonset")
logger.Info("Start to sync config daemonset")

if err := r.removeOldDS(ctx); err != nil {
if err := r.removeOldDsOnUpdateOperator(ctx); err != nil {
return err
}

Expand Down Expand Up @@ -252,14 +256,19 @@ func (r *SelfNodeRemediationConfigReconciler) convertTolerationsToUnstructed(tol
return convertedTolerations, nil
}

func (r *SelfNodeRemediationConfigReconciler) removeOldDS(ctx context.Context) error {
func (r *SelfNodeRemediationConfigReconciler) removeOldDsOnUpdateOperator(ctx context.Context) error {
ds := &v1.DaemonSet{}
key := types.NamespacedName{
Namespace: r.Namespace,
Name: dsName,
}

if err := r.Client.Get(ctx, key, ds); err == nil {
if lastChangedActualVal, _ := ds.Annotations[lastChangedAnnotationKey]; lastChangedActualVal == lastChangeAnnotationVal {
//ds is up-to-date this is not an update scenario
return nil
}

if err = r.Client.Delete(ctx, ds); err != nil {
r.Log.Error(err, "snr update failed could not delete old daemonset")
return pkgerrors.Wrap(err, "unable to delete old daemon set")
Expand Down
2 changes: 2 additions & 0 deletions install/self-node-remediation-deamonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ metadata:
namespace: {{.Namespace}}
labels:
k8s-app: self-node-remediation
annotations:
dsLastChangeVersion: rhwa-23.3
spec:
selector:
matchLabels:
Expand Down

0 comments on commit a7018a1

Please sign in to comment.