|
| 1 | +//go:build e2e |
| 2 | + |
| 3 | +// Copyright 2025 Nutanix. All rights reserved. |
| 4 | +// SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +package e2e |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + "fmt" |
| 11 | + |
| 12 | + . "github.com/onsi/ginkgo/v2" |
| 13 | + appsv1 "k8s.io/api/apps/v1" |
| 14 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 15 | + "k8s.io/utils/ptr" |
| 16 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 17 | + "sigs.k8s.io/cluster-api/test/framework" |
| 18 | + |
| 19 | + "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" |
| 20 | + apivariables "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables" |
| 21 | +) |
| 22 | + |
| 23 | +type WaitForCOSIControllerToBeReadyInWorkloadClusterInput struct { |
| 24 | + COSI *apivariables.COSI |
| 25 | + WorkloadCluster *clusterv1.Cluster |
| 26 | + ClusterProxy framework.ClusterProxy |
| 27 | + DeploymentIntervals []interface{} |
| 28 | + HelmReleaseIntervals []interface{} |
| 29 | +} |
| 30 | + |
| 31 | +func WaitForCOSIControllerToBeReadyInWorkloadCluster( |
| 32 | + ctx context.Context, |
| 33 | + input WaitForCOSIControllerToBeReadyInWorkloadClusterInput, //nolint:gocritic // This hugeParam is OK in tests. |
| 34 | +) { |
| 35 | + if input.COSI == nil { |
| 36 | + return |
| 37 | + } |
| 38 | + |
| 39 | + switch ptr.Deref(input.COSI.Strategy, "") { |
| 40 | + case v1alpha1.AddonStrategyHelmAddon: |
| 41 | + WaitForHelmReleaseProxyReadyForCluster( |
| 42 | + ctx, |
| 43 | + WaitForHelmReleaseProxyReadyForClusterInput{ |
| 44 | + GetLister: input.ClusterProxy.GetClient(), |
| 45 | + Cluster: input.WorkloadCluster, |
| 46 | + HelmReleaseName: "cosi-controller", |
| 47 | + }, |
| 48 | + input.HelmReleaseIntervals..., |
| 49 | + ) |
| 50 | + case "": |
| 51 | + Fail("COSI strategy is not set") |
| 52 | + default: |
| 53 | + Fail( |
| 54 | + fmt.Sprintf( |
| 55 | + "Do not know how to wait for COSI using strategy %s to be ready", |
| 56 | + *input.COSI.Strategy, |
| 57 | + ), |
| 58 | + ) |
| 59 | + } |
| 60 | + |
| 61 | + workloadClusterClient := input.ClusterProxy.GetWorkloadCluster( |
| 62 | + ctx, input.WorkloadCluster.Namespace, input.WorkloadCluster.Name, |
| 63 | + ).GetClient() |
| 64 | + |
| 65 | + WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{ |
| 66 | + Getter: workloadClusterClient, |
| 67 | + Deployment: &appsv1.Deployment{ |
| 68 | + ObjectMeta: metav1.ObjectMeta{ |
| 69 | + Name: "container-object-storage-controller", |
| 70 | + Namespace: "container-object-storage-system", |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, input.DeploymentIntervals...) |
| 74 | +} |
0 commit comments