Skip to content

Commit 4c7bec6

Browse files
authored
fix: add tolerations and nodeAffinity overrides for registry addon (#1183)
**What problem does this PR solve?**: Adds antiAffinity to ensure that registry pods are scheduled on the control plane nodes. Adds tolerations and nodeAffinity to the registry pods to ensure that they are scheduled on the control plane nodes. **Which issue(s) this PR fixes**: Fixes # **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> - E2E tests - Manual tests **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent 629a4bb commit 4c7bec6

File tree

5 files changed

+96
-1
lines changed

5 files changed

+96
-1
lines changed

charts/cluster-api-runtime-extensions-nutanix/addons/registry/cncf-distribution/values-template.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,26 @@ statefulSet:
2525
cpu: 100m
2626
memory: 75Mi
2727
tlsSecretName: {{ .TLSSecretName }}
28+
tolerations:
29+
- key: "node-role.kubernetes.io/control-plane"
30+
operator: Exists
31+
effect: "NoSchedule"
32+
33+
podLabels:
34+
cncf-distribution-registry: "true" # ensure the labels match with pod AntiAffinity.
35+
36+
affinity:
37+
nodeAffinity:
38+
requiredDuringSchedulingIgnoredDuringExecution:
39+
nodeSelectorTerms:
40+
- matchExpressions:
41+
- key: node-role.kubernetes.io/control-plane
42+
operator: Exists
43+
podAntiAffinity:
44+
preferredDuringSchedulingIgnoredDuringExecution:
45+
- weight: 100
46+
podAffinityTerm:
47+
labelSelector:
48+
matchLabels:
49+
cncf-distribution-registry: "true"
50+
topologyKey: kubernetes.io/hostname

test/e2e/quick_start_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,15 @@ var _ = Describe("Quick start", func() {
315315
ClusterProxy: proxy,
316316
},
317317
)
318+
319+
EnsureAntiAffnityForRegistryAddon(
320+
ctx,
321+
EnsureAntiAffnityForRegistryAddonInput{
322+
Registry: addonsConfig.Registry,
323+
WorkloadCluster: workloadCluster,
324+
ClusterProxy: proxy,
325+
},
326+
)
318327
},
319328
}
320329
})

test/e2e/registry.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,57 @@ func EnsureClusterCAForRegistryAddon(
101101
const caCrtKey = "ca.crt"
102102
Expect(rootCASecret.Data[caCrtKey]).To(Equal(rootCASecret.Data[caCrtKey]))
103103
}
104+
105+
type EnsureAntiAffnityForRegistryAddonInput struct {
106+
Registry *v1alpha1.RegistryAddon
107+
WorkloadCluster *clusterv1.Cluster
108+
ClusterProxy framework.ClusterProxy
109+
}
110+
111+
func EnsureAntiAffnityForRegistryAddon(
112+
ctx context.Context,
113+
input EnsureAntiAffnityForRegistryAddonInput,
114+
) {
115+
if input.Registry == nil {
116+
return
117+
}
118+
Log("Ensuring anti-affinity for registry addon in workload cluster")
119+
workloadClusterClient := input.ClusterProxy.GetWorkloadCluster(
120+
ctx, input.WorkloadCluster.Namespace, input.WorkloadCluster.Name,
121+
).GetClient()
122+
123+
sts := &appsv1.StatefulSet{
124+
ObjectMeta: metav1.ObjectMeta{
125+
Name: "cncf-distribution-registry-docker-registry",
126+
Namespace: "registry-system",
127+
},
128+
}
129+
err := workloadClusterClient.Get(ctx, ctrlclient.ObjectKeyFromObject(sts), sts)
130+
Expect(err).NotTo(HaveOccurred())
131+
Expect(sts.Spec.Template.Spec.Affinity).ToNot(BeNil())
132+
Expect(sts.Spec.Template.Spec.Affinity.PodAntiAffinity).ToNot(BeNil())
133+
podAntiAffinity := sts.Spec.Template.Spec.Affinity.PodAntiAffinity
134+
Expect(
135+
podAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution,
136+
).ToNot(BeEmpty())
137+
Expect(
138+
podAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].Weight,
139+
).To(Equal(int32(100)))
140+
podAffinityTerm := podAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution[0].PodAffinityTerm
141+
Expect(podAffinityTerm).ToNot(BeNil())
142+
Expect(podAffinityTerm.TopologyKey).To(Equal("kubernetes.io/hostname"))
143+
Expect(podAffinityTerm.LabelSelector).ToNot(BeNil())
144+
affinityLabels := podAffinityTerm.LabelSelector.MatchLabels
145+
Expect(
146+
affinityLabels["cncf-distribution-registry"],
147+
).To(Equal("true")) // Ensure the label matches the pod AntiAffinity.
148+
149+
// test node affinity
150+
nodeAffinity := sts.Spec.Template.Spec.Affinity.NodeAffinity
151+
Expect(nodeAffinity).ToNot(BeNil())
152+
Expect(nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution).ToNot(BeNil())
153+
nodeSelectorTerm := nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms[0]
154+
Expect(nodeSelectorTerm).ToNot(BeNil())
155+
Expect(nodeSelectorTerm.MatchExpressions).ToNot(BeEmpty())
156+
Expect(nodeSelectorTerm.MatchExpressions[0].Key).To(Equal("node-role.kubernetes.io/control-plane"))
157+
}

test/e2e/self_hosted_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ var _ = Describe("Self-hosted", Serial, func() {
177177
ClusterProxy: proxy,
178178
},
179179
)
180+
181+
EnsureAntiAffnityForRegistryAddon(
182+
ctx,
183+
EnsureAntiAffnityForRegistryAddonInput{
184+
Registry: addonsConfig.Registry,
185+
WorkloadCluster: workloadCluster,
186+
ClusterProxy: proxy,
187+
},
188+
)
180189
},
181190
}
182191
},

test/e2e/statefulset_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type WaitForStatefulSetAvailableInput struct {
2121
StatefulSet *appsv1.StatefulSet
2222
}
2323

24-
// WaitForStatefulSetsAvailable waits until the Deployment has observedGeneration equal to generation and
24+
// WaitForStatefulSetsAvailable waits until the Statefulset has observedGeneration equal to generation and
2525
// status.Available = True, that signals that all the desired replicas are in place.
2626
func WaitForStatefulSetsAvailable(
2727
ctx context.Context, input WaitForStatefulSetAvailableInput, intervals ...interface{},

0 commit comments

Comments
 (0)