Skip to content

Commit d95129c

Browse files
authored
Exclude some fields to calculate STS hash (#1156)
Signed-off-by: Alexey Makhov <[email protected]> Signed-off-by: makhov <[email protected]>
1 parent d5dcb3d commit d95129c

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

internal/controller/k0smotron.io/k0smotroncluster_statefulset.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,6 @@ func (r *ClusterReconciler) generateStatefulSet(kmc *km.Cluster) (apps.StatefulS
142142
},
143143
}},
144144
Resources: kmc.Spec.Resources,
145-
ReadinessProbe: &v1.Probe{
146-
InitialDelaySeconds: 60,
147-
PeriodSeconds: 10,
148-
FailureThreshold: 15,
149-
ProbeHandler: v1.ProbeHandler{Exec: &v1.ExecAction{Command: []string{"k0s", "status"}}},
150-
},
151-
LivenessProbe: &v1.Probe{
152-
InitialDelaySeconds: 90,
153-
FailureThreshold: 10,
154-
PeriodSeconds: 10,
155-
ProbeHandler: v1.ProbeHandler{Exec: &v1.ExecAction{Command: []string{"k0s", "status"}}},
156-
},
157145
VolumeMounts: []v1.VolumeMount{{
158146
Name: kmc.GetEntrypointConfigMapName(),
159147
MountPath: "/k0smotron-entrypoint.sh",
@@ -320,8 +308,25 @@ data:
320308

321309
err := ctrl.SetControllerReference(kmc, &statefulSet, r.Scheme)
322310

311+
// We calculate the hash of the statefulset template and store it in the annotations
312+
// This is used to detect changes in the statefulset template and trigger a rollout
313+
// We exclude some fields below from the hash calculation to avoid unnecessary rollouts
314+
annotationHash := controller.ComputeHash(&statefulSet.Spec.Template, statefulSet.Status.CollisionCount)
315+
statefulSet.Spec.Template.Spec.Containers[0].ReadinessProbe = &v1.Probe{
316+
InitialDelaySeconds: 60,
317+
PeriodSeconds: 10,
318+
FailureThreshold: 15,
319+
ProbeHandler: v1.ProbeHandler{Exec: &v1.ExecAction{Command: []string{"k0s", "status"}}},
320+
}
321+
statefulSet.Spec.Template.Spec.Containers[0].LivenessProbe = &v1.Probe{
322+
InitialDelaySeconds: 90,
323+
FailureThreshold: 10,
324+
PeriodSeconds: 10,
325+
ProbeHandler: v1.ProbeHandler{Exec: &v1.ExecAction{Command: []string{"k0s", "status"}}},
326+
}
327+
323328
statefulSet.Annotations = map[string]string{
324-
statefulSetAnnotation: controller.ComputeHash(&statefulSet.Spec.Template, statefulSet.Status.CollisionCount),
329+
statefulSetAnnotation: annotationHash,
325330
}
326331
for k, v := range annotations {
327332
statefulSet.Annotations[k] = v

0 commit comments

Comments
 (0)