@@ -15,6 +15,7 @@ import (
1515 utilerrors "k8s.io/apimachinery/pkg/util/errors"
1616
1717 "github.com/openshift/origin/pkg/monitortestlibrary/disruptionlibrary"
18+ "github.com/openshift/origin/pkg/test/extensions"
1819 "k8s.io/apimachinery/pkg/labels"
1920 "k8s.io/apimachinery/pkg/selection"
2021
@@ -76,6 +77,9 @@ type InvariantInClusterDisruption struct {
7677 replicas int32
7778 controlPlaneNodes int32
7879
80+ isHypershift bool
81+ isAROHCPCluster bool
82+ isBareMetalHypershift bool
7983 adminRESTConfig * rest.Config
8084 kubeClient kubernetes.Interface
8185}
@@ -86,6 +90,68 @@ func NewInvariantInClusterDisruption(info monitortestframework.MonitorTestInitia
8690 }
8791}
8892
93+ // parseAdminRESTConfigHost parses the adminRESTConfig.Host URL and returns hostname and port
94+ func (i * InvariantInClusterDisruption ) parseAdminRESTConfigHost () (hostname , port string , err error ) {
95+ parsedURL , err := url .Parse (i .adminRESTConfig .Host )
96+ if err != nil {
97+ return "" , "" , fmt .Errorf ("failed to parse adminRESTConfig.Host %q: %v" , i .adminRESTConfig .Host , err )
98+ }
99+
100+ hostname = parsedURL .Hostname ()
101+ if hostname == "" {
102+ return "" , "" , fmt .Errorf ("no hostname found in adminRESTConfig.Host %q" , i .adminRESTConfig .Host )
103+ }
104+
105+ port = parsedURL .Port ()
106+ if port == "" {
107+ port = "6443" // default port
108+ }
109+
110+ return hostname , port , nil
111+ }
112+
113+ // setKubernetesServiceEnvVars sets the KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT environment variables
114+ // based on the cluster type (ARO HCP, bare metal HyperShift, or standard)
115+ func (i * InvariantInClusterDisruption ) setKubernetesServiceEnvVars (envVars []corev1.EnvVar , apiIntHost , apiIntPort string ) []corev1.EnvVar {
116+ // Parse adminRESTConfig.Host once for bare metal HyperShift
117+ var bareMetalHost , bareMetalPort string
118+ var bareMetalErr error
119+ if i .isHypershift && i .isBareMetalHypershift {
120+ bareMetalHost , bareMetalPort , bareMetalErr = i .parseAdminRESTConfigHost ()
121+ if bareMetalErr != nil {
122+ logrus .WithError (bareMetalErr ).Errorf ("Failed to parse adminRESTConfig.Host for bare metal HyperShift" )
123+ }
124+ }
125+
126+ for j , env := range envVars {
127+ switch env .Name {
128+ case "KUBERNETES_SERVICE_HOST" :
129+ if i .isHypershift && i .isBareMetalHypershift {
130+ if bareMetalErr != nil {
131+ envVars [j ].Value = apiIntHost
132+ } else {
133+ envVars [j ].Value = bareMetalHost
134+ }
135+ } else {
136+ envVars [j ].Value = apiIntHost
137+ }
138+ case "KUBERNETES_SERVICE_PORT" :
139+ if i .isHypershift && i .isAROHCPCluster {
140+ envVars [j ].Value = "7443"
141+ } else if i .isHypershift && i .isBareMetalHypershift {
142+ if bareMetalErr != nil {
143+ envVars [j ].Value = apiIntPort
144+ } else {
145+ envVars [j ].Value = bareMetalPort
146+ }
147+ } else {
148+ envVars [j ].Value = apiIntPort
149+ }
150+ }
151+ }
152+ return envVars
153+ }
154+
89155func (i * InvariantInClusterDisruption ) createDeploymentAndWaitToRollout (ctx context.Context , deploymentObj * appsv1.Deployment ) error {
90156 deploymentID := uuid .New ().String ()
91157 deploymentObj = disruptionlibrary .UpdateDeploymentENVs (deploymentObj , deploymentID , "" )
@@ -117,12 +183,14 @@ func (i *InvariantInClusterDisruption) createDeploymentAndWaitToRollout(ctx cont
117183func (i * InvariantInClusterDisruption ) createInternalLBDeployment (ctx context.Context , apiIntHost string ) error {
118184 deploymentObj := resourceread .ReadDeploymentV1OrDie (internalLBDeploymentYaml )
119185 deploymentObj .SetNamespace (i .namespaceName )
120- deploymentObj .Spec .Template .Spec .Containers [0 ].Env [0 ].Value = apiIntHost
121186 // set amount of deployment replicas to make sure it runs on all nodes
122187 deploymentObj .Spec .Replicas = & i .replicas
123188 // we need to use the openshift-tests image of the destination during an upgrade.
124189 deploymentObj .Spec .Template .Spec .Containers [0 ].Image = i .openshiftTestsImagePullSpec
125190
191+ // Set the correct host and port for internal API server based on cluster type
192+ deploymentObj .Spec .Template .Spec .Containers [0 ].Env = i .setKubernetesServiceEnvVars (
193+ deploymentObj .Spec .Template .Spec .Containers [0 ].Env , apiIntHost , apiIntPort )
126194 err := i .createDeploymentAndWaitToRollout (ctx , deploymentObj )
127195 if err != nil {
128196 return err
@@ -332,8 +400,30 @@ func (i *InvariantInClusterDisruption) StartCollection(ctx context.Context, admi
332400 managementOC := exutil .NewHypershiftManagementCLI (hcpNamespace )
333401 if isAROHCPcluster , err = exutil .IsAroHCP (ctx , hcpNamespace , managementOC .AdminKubeClient ()); err != nil {
334402 logrus .WithError (err ).Warning ("Failed to check if ARO HCP, assuming it's not" )
403+ i .isAROHCPCluster = false // Assume not ARO HCP on error
335404 } else if isAROHCPcluster {
336- i .notSupportedReason = "platform Hypershift - ARO HCP not supported"
405+ i .isAROHCPCluster = true
406+ } else {
407+ i .isAROHCPCluster = false
408+ }
409+
410+ // Check if this is a bare metal HyperShift cluster
411+ i .isBareMetalHypershift , err = exutil .IsBareMetalHyperShiftCluster (ctx , managementOC )
412+ if err != nil {
413+ logrus .WithError (err ).Warning ("Failed to check if bare metal HyperShift, assuming it's not" )
414+ i .isBareMetalHypershift = false // Assume not bare metal HyperShift on error
415+ }
416+ }
417+
418+ if len (i .payloadImagePullSpec ) == 0 {
419+ i .payloadImagePullSpec , err = extensions .DetermineReleasePayloadImage ()
420+ if err != nil {
421+ return err
422+ }
423+
424+ if len (i .payloadImagePullSpec ) == 0 {
425+ log .Info ("unable to determine payloadImagePullSpec" )
426+ i .notSupportedReason = "no image pull spec specified."
337427 return nil
338428 }
339429 }
@@ -379,11 +469,25 @@ func (i *InvariantInClusterDisruption) StartCollection(ctx context.Context, admi
379469 return fmt .Errorf ("error getting openshift infrastructure: %v" , err )
380470 }
381471
382- internalAPI , err := url .Parse (infra .Status .APIServerInternalURL )
383- if err != nil {
384- return fmt .Errorf ("error parsing api int url: %v" , err )
472+ var apiIntHost string
473+ var apiIntPort string
474+ if i .isHypershift {
475+ apiIntHost , apiIntPort , err = i .parseAdminRESTConfigHost ()
476+ if err != nil {
477+ return fmt .Errorf ("failed to parse adminRESTConfig.Host: %v" , err )
478+ }
479+ } else {
480+ internalAPI , err := url .Parse (infra .Status .APIServerInternalURL )
481+ if err != nil {
482+ return fmt .Errorf ("error parsing api int url: %v" , err )
483+ }
484+ apiIntHost = internalAPI .Hostname ()
485+ if internalAPI .Port () != "" {
486+ apiIntPort = internalAPI .Port ()
487+ } else {
488+ apiIntPort = "6443" // default port
489+ }
385490 }
386- apiIntHost := internalAPI .Hostname ()
387491
388492 allNodes , err := i .kubeClient .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {})
389493 if err != nil {
0 commit comments