Skip to content

Commit b2e08e3

Browse files
Merge pull request #832 from cynepco3hahue/bz_1976379
Bug 1976379: UPSTREAM: <carry>: Reject the pod creation when we can not decide the cluster type
2 parents 9c5c895 + 212d17f commit b2e08e3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

openshift-kube-apiserver/admission/autoscaling/managementcpusoverride/admission.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ func (a *managementCPUsOverride) Admit(ctx context.Context, attr admission.Attri
180180
return admission.NewForbidden(attr, err) // can happen due to informer latency
181181
}
182182

183+
// we can not decide the cluster type without status.controlPlaneTopology and status.infrastructureTopology
184+
if clusterInfra.Status.ControlPlaneTopology == "" || clusterInfra.Status.InfrastructureTopology == "" {
185+
return admission.NewForbidden(attr, fmt.Errorf("%s infrastructure resource has empty status.controlPlaneTopology or status.infrastructureTopology", PluginName))
186+
}
187+
183188
// not the SNO cluster, skip mutation
184189
// TODO: currently we supports only SNO use case because we have not yet worked out the best approach to determining whether the feature
185190
// should be on or off in a multi-node cluster, and computing that state incorrectly could lead to breaking running clusters.

openshift-kube-apiserver/admission/autoscaling/managementcpusoverride/admission_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ func TestAdmit(t *testing.T) {
168168
infra: testClusterSNOInfra(),
169169
expectedError: fmt.Errorf(`failed to get workload annotation effect: the workload annotation value map["test":"test"] does not have "effect" key`),
170170
},
171+
{
172+
name: "should return admission error when the infrastructure resource status has empty ControlPlaneTopology",
173+
pod: testManagedPod("", "250m", "500Mi", "250Mi"),
174+
expectedCpuRequest: resource.MustParse("250m"),
175+
namespace: testManagedNamespace(),
176+
nodes: []*corev1.Node{testNodeWithManagementResource()},
177+
infra: testClusterInfraWithoutControlPlaneTopology(),
178+
expectedError: fmt.Errorf("%s infrastructure resource has empty status.controlPlaneTopology or status.infrastructureTopology", PluginName),
179+
},
180+
{
181+
name: "should return admission error when the infrastructure resource status has empty InfrastructureTopology",
182+
pod: testManagedPod("", "250m", "500Mi", "250Mi"),
183+
expectedCpuRequest: resource.MustParse("250m"),
184+
namespace: testManagedNamespace(),
185+
nodes: []*corev1.Node{testNodeWithManagementResource()},
186+
infra: testClusterInfraWithoutInfrastructureTopology(),
187+
expectedError: fmt.Errorf("%s infrastructure resource has empty status.controlPlaneTopology or status.infrastructureTopology", PluginName),
188+
},
171189
{
172190
name: "should delete CPU requests and update workload CPU annotations for the burstable pod with managed annotation",
173191
pod: testManagedPod("", "250m", "500Mi", "250Mi"),
@@ -687,3 +705,15 @@ func testClusterSNOInfra() *configv1.Infrastructure {
687705
},
688706
}
689707
}
708+
709+
func testClusterInfraWithoutControlPlaneTopology() *configv1.Infrastructure {
710+
infra := testClusterSNOInfra()
711+
infra.Status.ControlPlaneTopology = ""
712+
return infra
713+
}
714+
715+
func testClusterInfraWithoutInfrastructureTopology() *configv1.Infrastructure {
716+
infra := testClusterSNOInfra()
717+
infra.Status.InfrastructureTopology = ""
718+
return infra
719+
}

0 commit comments

Comments
 (0)