Skip to content

Commit fc9a3a2

Browse files
[release-4.18] OCPBUGS-59897: Update downloads deployment configuration to use master node selector (#1029)
* Update downloads deployment configuration to use master node selector and modify the tests accordingly * gofmt * Update downloads deployment to include master node selector, and keep the linux selector too * Enhance node selector handling for externalized control plane by ensuring only the master node selector is removed if it exists * Add Linux OS node selector to console deployment configuration as well * Fix the unit test * fix: fix the failing unit tests * refactor: rename withConsoleNodeSelector to withNodeSelector * fix: remove Linux OS node selector from console deployment configuration * fix: fix the failing unit test * test: add missing fields to deployment test case --------- Co-authored-by: Leo HC Li <[email protected]>
1 parent 9371d7f commit fc9a3a2

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

bindata/assets/deployments/downloads-deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spec:
2626
spec:
2727
nodeSelector:
2828
kubernetes.io/os: linux
29+
node-role.kubernetes.io/master: ""
2930
terminationGracePeriodSeconds: 0
3031
securityContext:
3132
runAsNonRoot: true

pkg/console/subresource/deployment/deployment.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func DefaultDeployment(
105105
canMountCustomLogo,
106106
)
107107
withConsoleContainerImage(deployment, operatorConfig, proxyConfig)
108-
withConsoleNodeSelector(deployment, infrastructureConfig)
108+
withNodeSelector(deployment, infrastructureConfig)
109109
util.AddOwnerRef(deployment, util.OwnerRefFrom(operatorConfig))
110110
return deployment
111111
}
@@ -121,6 +121,7 @@ func DefaultDownloadsDeployment(
121121
withAffinity(downloadsDeployment, infrastructureConfig, "downloads")
122122
withStrategy(downloadsDeployment, infrastructureConfig)
123123
withDownloadsContainerImage(downloadsDeployment)
124+
withNodeSelector(downloadsDeployment, infrastructureConfig)
124125
util.AddOwnerRef(downloadsDeployment, util.OwnerRefFrom(operatorConfig))
125126
return downloadsDeployment
126127
}
@@ -324,15 +325,18 @@ func withConsoleContainerImage(
324325
deployment.Spec.Template.Spec.Containers[0].Image = util.GetImageEnv("CONSOLE_IMAGE")
325326
}
326327

327-
func withConsoleNodeSelector(
328+
func withNodeSelector(
328329
deployment *appsv1.Deployment,
329330
infrastructureConfig *configv1.Infrastructure,
330331
) {
331332
nodeSelector := deployment.Spec.Template.Spec.NodeSelector
332333

333-
// If running with an externalized control plane, remove the master node selector
334+
// If running with an externalized control plane, remove only the master node selector
334335
if infrastructureConfig.Status.ControlPlaneTopology == configv1.ExternalTopologyMode {
335-
nodeSelector = map[string]string{}
336+
if nodeSelector == nil {
337+
nodeSelector = map[string]string{}
338+
}
339+
delete(nodeSelector, "node-role.kubernetes.io/master")
336340
}
337341

338342
deployment.Spec.Template.Spec.NodeSelector = nodeSelector

pkg/console/subresource/deployment/deployment_test.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,8 @@ func TestDefaultDeployment(t *testing.T) {
237237
Spec: corev1.PodSpec{
238238
ServiceAccountName: "console",
239239
// we want to deploy on master nodes
240-
NodeSelector: map[string]string{
241-
// empty string is correct
242-
"node-role.kubernetes.io/master": "",
243-
},
244-
Affinity: consoleDeploymentAffinity,
240+
NodeSelector: map[string]string{"node-role.kubernetes.io/master": ""},
241+
Affinity: consoleDeploymentAffinity,
245242
// toleration is a taint override. we can and should be scheduled on a master node.
246243
Tolerations: consoleDeploymentTolerations,
247244
PriorityClassName: "system-cluster-critical",
@@ -318,11 +315,8 @@ func TestDefaultDeployment(t *testing.T) {
318315
Spec: corev1.PodSpec{
319316
ServiceAccountName: "console",
320317
// we want to deploy on master nodes
321-
NodeSelector: map[string]string{
322-
// empty string is correct
323-
"node-role.kubernetes.io/master": "",
324-
},
325-
Affinity: consoleDeploymentAffinity,
318+
NodeSelector: map[string]string{"node-role.kubernetes.io/master": ""},
319+
Affinity: consoleDeploymentAffinity,
326320
// toleration is a taint override. we can and should be scheduled on a master node.
327321
Tolerations: consoleDeploymentTolerations,
328322
PriorityClassName: "system-cluster-critical",
@@ -399,11 +393,8 @@ func TestDefaultDeployment(t *testing.T) {
399393
Spec: corev1.PodSpec{
400394
ServiceAccountName: "console",
401395
// we want to deploy on master nodes
402-
NodeSelector: map[string]string{
403-
// empty string is correct
404-
"node-role.kubernetes.io/master": "",
405-
},
406-
Affinity: &corev1.Affinity{},
396+
NodeSelector: map[string]string{"node-role.kubernetes.io/master": ""},
397+
Affinity: &corev1.Affinity{},
407398
// toleration is a taint override. we can and should be scheduled on a master node.
408399
Tolerations: consoleDeploymentTolerations,
409400
PriorityClassName: "system-cluster-critical",
@@ -1414,7 +1405,9 @@ func TestWithConsoleNodeSelector(t *testing.T) {
14141405
Spec: appsv1.DeploymentSpec{
14151406
Template: corev1.PodTemplateSpec{
14161407
Spec: corev1.PodSpec{
1417-
NodeSelector: map[string]string{},
1408+
NodeSelector: map[string]string{
1409+
"foo": "bar",
1410+
},
14181411
},
14191412
},
14201413
},
@@ -1423,7 +1416,7 @@ func TestWithConsoleNodeSelector(t *testing.T) {
14231416
}
14241417
for _, tt := range tests {
14251418
t.Run(tt.name, func(t *testing.T) {
1426-
withConsoleNodeSelector(tt.args.deployment, tt.args.infrastructureConfig)
1419+
withNodeSelector(tt.args.deployment, tt.args.infrastructureConfig)
14271420
if diff := deep.Equal(tt.args.deployment, tt.want); diff != nil {
14281421
t.Error(diff)
14291422
}
@@ -1486,7 +1479,8 @@ func TestDefaultDownloadsDeployment(t *testing.T) {
14861479

14871480
downloadsDeploymentPodSpecSingleReplica := corev1.PodSpec{
14881481
NodeSelector: map[string]string{
1489-
"kubernetes.io/os": "linux",
1482+
"kubernetes.io/os": "linux",
1483+
"node-role.kubernetes.io/master": "",
14901484
},
14911485
Affinity: &corev1.Affinity{},
14921486
Tolerations: []corev1.Toleration{

0 commit comments

Comments
 (0)