Skip to content

Commit 5dcbc86

Browse files
authored
Merge pull request #7571 from dharmicksai/NeedsRollout
🌱 New Filter NeedsRollout to determine if a machine needs rollout.
2 parents 1efbfae + c714cf2 commit 5dcbc86

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
@@ -168,26 +168,16 @@ func (c *ControlPlane) MachinesNeedingRollout() collections.Machines {
168168
machines := c.Machines.Filter(collections.Not(collections.HasDeletionTimestamp))
169169

170170
// Return machines if they are scheduled for rollout or if with an outdated configuration.
171-
return machines.AnyFilter(
172-
// Machines whose certificates are about to expire.
173-
collections.ShouldRolloutBefore(&c.reconciliationTime, c.KCP.Spec.RolloutBefore),
174-
// Machines that are scheduled for rollout (KCP.Spec.RolloutAfter set, the RolloutAfter deadline is expired, and the machine was created before the deadline).
175-
collections.ShouldRolloutAfter(&c.reconciliationTime, c.KCP.Spec.RolloutAfter),
176-
// Machines that do not match with KCP config.
177-
collections.Not(MatchesMachineSpec(c.infraResources, c.kubeadmConfigs, c.KCP)),
171+
return machines.Filter(
172+
NeedsRollout(&c.reconciliationTime, c.KCP.Spec.RolloutAfter, c.KCP.Spec.RolloutBefore, c.infraResources, c.kubeadmConfigs, c.KCP),
178173
)
179174
}
180175

181176
// UpToDateMachines returns the machines that are up to date with the control
182177
// plane's configuration and therefore do not require rollout.
183178
func (c *ControlPlane) UpToDateMachines() collections.Machines {
184179
return c.Machines.Filter(
185-
// Machines that shouldn't be rollout out if their certificates are not about to expire.
186-
collections.Not(collections.ShouldRolloutBefore(&c.reconciliationTime, c.KCP.Spec.RolloutBefore)),
187-
// Machines that shouldn't be rolled out after the deadline has expired.
188-
collections.Not(collections.ShouldRolloutAfter(&c.reconciliationTime, c.KCP.Spec.RolloutAfter)),
189-
// Machines that match with KCP config.
190-
MatchesMachineSpec(c.infraResources, c.kubeadmConfigs, c.KCP),
180+
collections.Not(NeedsRollout(&c.reconciliationTime, c.KCP.Spec.RolloutAfter, c.KCP.Spec.RolloutBefore, c.infraResources, c.kubeadmConfigs, c.KCP)),
191181
)
192182
}
193183

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)