Skip to content

Commit c714cf2

Browse files
committed
New Filter NeedsRollout to determine if a machine needs rollout.
Previously MachinesNeedingRollout and the UpToDateMachines functions in controlplane/kubeadm/internal/ used multiple filters to determine if machine needs rollout. Now the NeedsRollout filter is used in both functions to determine if a machine needs rollout.
1 parent c148261 commit c714cf2

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

controlplane/kubeadm/internal/control_plane.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,26 +256,16 @@ func (c *ControlPlane) MachinesNeedingRollout() collections.Machines {
256256
machines := c.Machines.Filter(collections.Not(collections.HasDeletionTimestamp))
257257

258258
// Return machines if they are scheduled for rollout or if with an outdated configuration.
259-
return machines.AnyFilter(
260-
// Machines whose certificates are about to expire.
261-
collections.ShouldRolloutBefore(&c.reconciliationTime, c.KCP.Spec.RolloutBefore),
262-
// Machines that are scheduled for rollout (KCP.Spec.RolloutAfter set, the RolloutAfter deadline is expired, and the machine was created before the deadline).
263-
collections.ShouldRolloutAfter(&c.reconciliationTime, c.KCP.Spec.RolloutAfter),
264-
// Machines that do not match with KCP config.
265-
collections.Not(MatchesMachineSpec(c.infraResources, c.kubeadmConfigs, c.KCP)),
259+
return machines.Filter(
260+
NeedsRollout(&c.reconciliationTime, c.KCP.Spec.RolloutAfter, c.KCP.Spec.RolloutBefore, c.infraResources, c.kubeadmConfigs, c.KCP),
266261
)
267262
}
268263

269264
// UpToDateMachines returns the machines that are up to date with the control
270265
// plane's configuration and therefore do not require rollout.
271266
func (c *ControlPlane) UpToDateMachines() collections.Machines {
272267
return c.Machines.Filter(
273-
// Machines that shouldn't be rollout out if their certificates are not about to expire.
274-
collections.Not(collections.ShouldRolloutBefore(&c.reconciliationTime, c.KCP.Spec.RolloutBefore)),
275-
// Machines that shouldn't be rolled out after the deadline has expired.
276-
collections.Not(collections.ShouldRolloutAfter(&c.reconciliationTime, c.KCP.Spec.RolloutAfter)),
277-
// Machines that match with KCP config.
278-
MatchesMachineSpec(c.infraResources, c.kubeadmConfigs, c.KCP),
268+
collections.Not(NeedsRollout(&c.reconciliationTime, c.KCP.Spec.RolloutAfter, c.KCP.Spec.RolloutBefore, c.infraResources, c.kubeadmConfigs, c.KCP)),
279269
)
280270
}
281271

controlplane/kubeadm/internal/filters.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
"reflect"
2222

23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2425
"sigs.k8s.io/controller-runtime/pkg/client"
2526

@@ -42,6 +43,18 @@ func MatchesMachineSpec(infraConfigs map[string]*unstructured.Unstructured, mach
4243
)
4344
}
4445

46+
// NeedsRollout returns a filter to determine if a machine needs rollout.
47+
func NeedsRollout(reconciliationTime, rolloutAfter *metav1.Time, rolloutBefore *controlplanev1.RolloutBefore, infraConfigs map[string]*unstructured.Unstructured, machineConfigs map[string]*bootstrapv1.KubeadmConfig, kcp *controlplanev1.KubeadmControlPlane) func(machine *clusterv1.Machine) bool {
48+
return collections.Or(
49+
// Machines whose certificates are about to expire.
50+
collections.ShouldRolloutBefore(reconciliationTime, rolloutBefore),
51+
// Machines that are scheduled for rollout (KCP.Spec.RolloutAfter set, the RolloutAfter deadline is expired, and the machine was created before the deadline).
52+
collections.ShouldRolloutAfter(reconciliationTime, rolloutAfter),
53+
// Machines that do not match with KCP config.
54+
collections.Not(MatchesMachineSpec(infraConfigs, machineConfigs, kcp)),
55+
)
56+
}
57+
4558
// MatchesTemplateClonedFrom returns a filter to find all machines that match a given KCP infra template.
4659
func MatchesTemplateClonedFrom(infraConfigs map[string]*unstructured.Unstructured, kcp *controlplanev1.KubeadmControlPlane) collections.Func {
4760
return func(machine *clusterv1.Machine) bool {

0 commit comments

Comments
 (0)