Skip to content

Commit 8933dc6

Browse files
Merge pull request #30006 from bryan-cox/OCPBUGS-59218
OCPBUGS-59218: feat(azure): skip metrics collection for ARO HCP hypershift
2 parents 85efd76 + 73e61b9 commit 8933dc6

File tree

5 files changed

+488
-2
lines changed

5 files changed

+488
-2
lines changed

pkg/monitortests/kubeapiserver/disruptioninclusterapiserver/monitortest.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,28 @@ func (i *InvariantInClusterDisruption) PrepareCollection(ctx context.Context, ad
303303
func (i *InvariantInClusterDisruption) StartCollection(ctx context.Context, adminRESTConfig *rest.Config, _ monitorapi.RecorderWriter) error {
304304
var err error
305305
log := logrus.WithField("monitorTest", "apiserver-incluster-availability").WithField("namespace", i.namespaceName).WithField("func", "StartCollection")
306+
307+
// Check for ARO HCP and skip if detected
308+
oc := exutil.NewCLI("apiserver-incluster-availability").AsAdmin()
309+
var isAROHCPcluster bool
310+
isHypershift, _ := exutil.IsHypershift(ctx, oc.AdminConfigClient())
311+
if isHypershift {
312+
_, hcpNamespace, err := exutil.GetHypershiftManagementClusterConfigAndNamespace()
313+
if err != nil {
314+
logrus.WithError(err).Error("failed to get hypershift management cluster config and namespace")
315+
}
316+
317+
// For Hypershift, only skip if it's specifically ARO HCP
318+
// Use management cluster client to check the control-plane-operator deployment
319+
managementOC := exutil.NewHypershiftManagementCLI(hcpNamespace)
320+
if isAROHCPcluster, err = exutil.IsAroHCP(ctx, hcpNamespace, managementOC.AdminKubeClient()); err != nil {
321+
logrus.WithError(err).Warning("Failed to check if ARO HCP, assuming it's not")
322+
} else if isAROHCPcluster {
323+
i.notSupportedReason = "platform Hypershift - ARO HCP not supported"
324+
return nil
325+
}
326+
}
327+
306328
if len(i.payloadImagePullSpec) == 0 {
307329
i.payloadImagePullSpec, err = extensions.DetermineReleasePayloadImage()
308330
if err != nil {
@@ -319,7 +341,7 @@ func (i *InvariantInClusterDisruption) StartCollection(ctx context.Context, admi
319341
log.Infof("payload image pull spec is %s", i.payloadImagePullSpec)
320342

321343
// Extract the openshift-tests image from the release payload
322-
oc := exutil.NewCLIForMonitorTest("default")
344+
oc = exutil.NewCLIForMonitorTest("default")
323345
i.openshiftTestsImagePullSpec, err = payload.ExtractImageFromReleasePayload(i.payloadImagePullSpec, "tests", oc)
324346
if err != nil {
325347
return fmt.Errorf("unable to determine openshift-tests image: %s: %v", i.payloadImagePullSpec, err)

test/extended/util/managed_services.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package util
22

3-
import "k8s.io/apimachinery/pkg/util/sets"
3+
import (
4+
"context"
5+
6+
"github.com/sirupsen/logrus"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
"k8s.io/apimachinery/pkg/util/sets"
9+
"k8s.io/client-go/kubernetes"
10+
)
411

512
// ManagedServiceNamespaces is the set of namespaces used by managed service platforms
613
// like ROSA, ARO, etc. These are typically exempt from the requirements we impose on
@@ -51,3 +58,40 @@ var ManagedServiceNamespaces = sets.New[string](
5158
"openshift-validation-webhook",
5259
"openshift-velero",
5360
)
61+
62+
// IsAroHCP checks if the HyperShift operator deployment has MANAGED_SERVICE=ARO-HCP environment variable.
63+
func IsAroHCP(ctx context.Context, namespace string, kubeClient kubernetes.Interface) (bool, error) {
64+
// List deployments with the correct label that actually exists on the deployment
65+
deployments, err := kubeClient.AppsV1().Deployments(namespace).List(ctx, metav1.ListOptions{
66+
LabelSelector: "hypershift.openshift.io/managed-by=control-plane-operator",
67+
})
68+
if err != nil {
69+
logrus.Infof("Failed to list deployments in namespace %s: %v", namespace, err)
70+
return false, nil // Not an error if we can't list deployments, just means it's not ARO HCP
71+
}
72+
73+
if len(deployments.Items) == 0 {
74+
logrus.Infof("No control-plane-operator deployments found in namespace %s", namespace)
75+
return false, nil
76+
}
77+
78+
logrus.Infof("Found %d control-plane-operator deployments in namespace %s", len(deployments.Items), namespace)
79+
80+
// Look through all matching deployments
81+
for _, deployment := range deployments.Items {
82+
83+
// Look for the control-plane-operator container directly in the deployment spec
84+
for _, container := range deployment.Spec.Template.Spec.Containers {
85+
if container.Name == "control-plane-operator" {
86+
logrus.Infof("Found container 'control-plane-operator' in deployment %s", deployment.Name)
87+
88+
result := HasEnvVar(&container, "MANAGED_SERVICE", "ARO-HCP")
89+
logrus.Infof("hasEnvVar result for MANAGED_SERVICE=ARO-HCP: %v", result)
90+
return result, nil
91+
}
92+
}
93+
}
94+
95+
logrus.Infof("No deployment found with control-plane-operator container in namespace %s", namespace)
96+
return false, nil
97+
}

0 commit comments

Comments
 (0)