Skip to content

Commit bcca1ea

Browse files
committed
Clean up unused labels and functions that remained after troubleshooting.
1 parent 335ded6 commit bcca1ea

File tree

1 file changed

+12
-90
lines changed

1 file changed

+12
-90
lines changed

test/e2e/route_monitor_operator_tests.go

Lines changed: 12 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import (
2929
corev1 "k8s.io/api/core/v1"
3030
kubev1 "k8s.io/api/core/v1"
3131
k8serrors "k8s.io/apimachinery/pkg/api/errors"
32-
"k8s.io/apimachinery/pkg/labels"
3332
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3433
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
34+
"k8s.io/apimachinery/pkg/labels"
3535
"k8s.io/apimachinery/pkg/runtime"
3636
"k8s.io/apimachinery/pkg/runtime/schema"
3737
"k8s.io/apimachinery/pkg/util/intstr"
@@ -423,26 +423,15 @@ var _ = Describe("RHOBS Synthetic Monitoring", Ordered, func() {
423423
environment = provider.Environment() // Returns "int", "stage", or "prod"
424424
}
425425

426-
// Fetch OIDC credentials from environment variables
427-
By("fetching OIDC credentials")
428-
429-
// Log which credential source is available for debugging
430-
if os.Getenv("EXTERNAL_SECRET_OIDC_CLIENT_ID") != "" {
431-
GinkgoLogr.Info("EXTERNAL_SECRET_ credentials detected")
432-
} else {
433-
GinkgoLogr.Info("No EXTERNAL_SECRET_ credentials found, test will fail")
434-
}
435-
436426
// Get OIDC credentials from ConfigMap first, fall back to env vars if needed
437427
// This checks ConfigMap first, then environment variables, then creates/updates ConfigMap
438428
By("getting OIDC credentials from ConfigMap or environment variables")
439-
creds, err := getOrCreateOIDCCredentials(ctx, k8s, environment)
429+
oidcCredentials, err = getOrCreateOIDCCredentials(ctx, k8s, environment)
440430
Expect(err).ShouldNot(HaveOccurred(), "failed to fetch credentials")
441-
oidcCredentials = creds // Store for use in listRHOBSProbes
442431

443432
// Set RHOBS API URL (from credentials or environment)
444-
if creds.ProbeAPIURL != "" {
445-
rhobsAPIURL = creds.ProbeAPIURL
433+
if oidcCredentials.ProbeAPIURL != "" {
434+
rhobsAPIURL = oidcCredentials.ProbeAPIURL
446435
} else {
447436
rhobsAPIURL = getRHOBSAPIURL(environment)
448437
}
@@ -452,19 +441,12 @@ var _ = Describe("RHOBS Synthetic Monitoring", Ordered, func() {
452441
pollingDuration = 3 * time.Minute
453442
probeActivationTimeout = 5 * time.Minute
454443

455-
// Label the test cluster as a management cluster
456-
By("labeling test cluster as management-cluster")
457-
err = labelTestClusterAsManagementCluster(ctx, k8s)
458-
if err != nil {
459-
GinkgoLogr.Info("Warning: could not label test cluster as management cluster", "error", err)
460-
}
461-
462444
GinkgoLogr.Info("RHOBS Synthetic Monitoring test suite initialized",
463445
"environment", environment,
464446
"probeAPIURL", rhobsAPIURL,
465447
"tenant", rhobsTenant,
466448
"testNamespace", testNamespace,
467-
"oidcConfigured", creds.ClientID != "")
449+
"oidcConfigured", oidcCredentials.ClientID != "")
468450
})
469451

470452
// Phase 1 Test 1: Verify RHOBS monitoring configuration
@@ -511,7 +493,7 @@ var _ = Describe("RHOBS Synthetic Monitoring", Ordered, func() {
511493
err := k8s.Create(ctx, ns)
512494
Expect(err).ShouldNot(HaveOccurred(), "failed to create namespace")
513495

514-
By(fmt.Sprintf("creating public HostedControlPlane with cluster ID: %s", clusterID))
496+
By(fmt.Sprintf("creating public HostedControlPlane with cluster ID: %s", clusterID))
515497
hcp := createMCStyleHCP(clusterID, hcpName, namespace, hypershiftv1beta1.Public)
516498

517499
err = k8s.Create(ctx, hcp)
@@ -588,7 +570,7 @@ By(fmt.Sprintf("creating public HostedControlPlane with cluster ID: %s", cluster
588570
GinkgoLogr.Info("Warning: failed to delete HCP", "error", err)
589571
}
590572

591-
By("verifying probe is deleted from RHOBS API")
573+
By("verifying probe is deleted from RHOBS API")
592574
err = wait.PollUntilContextTimeout(ctx, 5*time.Second, 2*time.Minute, false, func(ctx context.Context) (bool, error) {
593575
probes, err := listRHOBSProbes(rhobsAPIURL, fmt.Sprintf("cluster-id=%s", clusterID), oidcCredentials)
594576
if err != nil {
@@ -721,7 +703,7 @@ By("verifying probe is deleted from RHOBS API")
721703
err := k8s.Create(ctx, ns)
722704
Expect(err).ShouldNot(HaveOccurred(), "failed to create namespace")
723705

724-
By(fmt.Sprintf("creating HostedControlPlane for deletion test with cluster ID: %s", clusterID))
706+
By(fmt.Sprintf("creating HostedControlPlane for deletion test with cluster ID: %s", clusterID))
725707
hcp := createMCStyleHCP(clusterID, hcpName, namespace, hypershiftv1beta1.Public)
726708

727709
err = k8s.Create(ctx, hcp)
@@ -787,7 +769,7 @@ By(fmt.Sprintf("creating HostedControlPlane for deletion test with cluster ID: %
787769
err = wait.PollUntilContextTimeout(ctx, 2*time.Second, 1*time.Minute, false, func(ctx context.Context) (bool, error) {
788770
hcpCheck := &hypershiftv1beta1.HostedControlPlane{}
789771
err := k8s.Get(ctx, hcpName, namespace, hcpCheck)
790-
if err != nil && isNotFoundError(err) {
772+
if err != nil && k8serrors.IsNotFound(err) {
791773
GinkgoLogr.Info("HostedControlPlane fully deleted", "name", hcpName)
792774
return true, nil
793775
}
@@ -946,18 +928,6 @@ func getRHOBSAPIURL(environment string) string {
946928
}
947929
}
948930

949-
func contains(s, substr string) bool {
950-
return strings.Contains(s, substr)
951-
}
952-
953-
func isAlreadyExistsError(err error) bool {
954-
return k8serrors.IsAlreadyExists(err)
955-
}
956-
957-
func isNotFoundError(err error) bool {
958-
return k8serrors.IsNotFound(err)
959-
}
960-
961931
func setHostedControlPlaneAvailable(ctx context.Context, k8s *openshift.Client, hcp *hypershiftv1beta1.HostedControlPlane) error {
962932
// Update the status to simulate HyperShift controller behavior
963933
// RMO only processes HCPs with Available=true status
@@ -1002,7 +972,7 @@ func setHostedControlPlaneAvailable(ctx context.Context, k8s *openshift.Client,
1002972

1003973
// Check if it's a conflict error
1004974
if strings.Contains(err.Error(), "object has been modified") ||
1005-
strings.Contains(err.Error(), "the object has been modified") {
975+
strings.Contains(err.Error(), "the object has been modified") {
1006976
// Retry after a short delay
1007977
GinkgoLogr.V(1).Info("HCP was modified, retrying status update", "attempt", attempt+1, "maxRetries", maxRetries)
1008978
time.Sleep(100 * time.Millisecond)
@@ -1131,8 +1101,8 @@ func restartRMODeployment(ctx context.Context, k8s *openshift.Client) error {
11311101
// ensureCRDsInstalled checks if required CRDs exist and installs them if missing
11321102
func ensureCRDsInstalled(ctx context.Context, k8s *openshift.Client) error {
11331103
crdsToInstall := []struct {
1134-
name string
1135-
yamlDef string
1104+
name string
1105+
yamlDef string
11361106
}{
11371107
{
11381108
name: "hostedcontrolplanes.hypershift.openshift.io",
@@ -1377,51 +1347,3 @@ func createRMOConfigMap(ctx context.Context, k8s *openshift.Client, creds *OIDCC
13771347

13781348
return nil
13791349
}
1380-
1381-
// labelTestClusterAsManagementCluster labels the cluster the test is running on as a management cluster
1382-
func labelTestClusterAsManagementCluster(ctx context.Context, k8s *openshift.Client) error {
1383-
GinkgoLogr.Info("Looking for ClusterDeployment to label as management-cluster")
1384-
1385-
// List all ClusterDeployments to find the one for this cluster
1386-
cdList := &unstructured.UnstructuredList{}
1387-
cdList.SetAPIVersion("hive.openshift.io/v1")
1388-
cdList.SetKind("ClusterDeploymentList")
1389-
1390-
err := k8s.List(ctx, cdList)
1391-
if err != nil {
1392-
return fmt.Errorf("failed to list ClusterDeployments: %w", err)
1393-
}
1394-
1395-
if len(cdList.Items) == 0 {
1396-
return fmt.Errorf("no ClusterDeployments found in cluster")
1397-
}
1398-
1399-
// Label all ClusterDeployments we find (typically there should only be one for the test cluster)
1400-
for idx := range cdList.Items {
1401-
cd := &cdList.Items[idx]
1402-
1403-
// Add the management-cluster label
1404-
labels := cd.GetLabels()
1405-
if labels == nil {
1406-
labels = make(map[string]string)
1407-
}
1408-
labels["ext-hypershift.openshift.io/cluster-type"] = "management-cluster"
1409-
cd.SetLabels(labels)
1410-
1411-
// Update the ClusterDeployment
1412-
err = k8s.Update(ctx, cd)
1413-
if err != nil {
1414-
GinkgoLogr.Info("Warning: failed to update ClusterDeployment",
1415-
"name", cd.GetName(),
1416-
"namespace", cd.GetNamespace(),
1417-
"error", err)
1418-
continue
1419-
}
1420-
1421-
GinkgoLogr.Info("Successfully labeled ClusterDeployment as management-cluster",
1422-
"name", cd.GetName(),
1423-
"namespace", cd.GetNamespace())
1424-
}
1425-
1426-
return nil
1427-
}

0 commit comments

Comments
 (0)