Skip to content

Commit

Permalink
Check for CRD using extensions API, fix Azure availabilitySetName issue
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Squizzato <[email protected]>
  • Loading branch information
squizzi committed Oct 1, 2024
1 parent 937b544 commit 84b64c9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
20 changes: 13 additions & 7 deletions test/e2e/managedcluster/clusteridentity/clusteridentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,24 @@ func validateSecretDataPopulated(secretData map[string]string) {
func (ci *ClusterIdentity) waitForResourceCRD(kc *kubeclient.KubeClient) {
GinkgoHelper()

By(fmt.Sprintf("waiting for %s CRD to be present", ci.GroupVersionResource.Resource))
By(fmt.Sprintf("waiting for %s CRD to be present", ci.Kind))

ctx := context.Background()
client := kc.GetDynamicClient(ci.GroupVersionResource)

Eventually(func() error {
if _, err := client.List(ctx, metav1.ListOptions{}); err != nil {
_, _ = fmt.Fprintf(GinkgoWriter, "failed to list %s resources: %v, retrying...\n", ci.GroupVersionResource.Resource, err)
return fmt.Errorf("failed to list %s resources: %w", ci.GroupVersionResource.String(), err)
crds, err := kc.ExtendedClient.ApiextensionsV1().CustomResourceDefinitions().List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to list CRDs: %w", err)
}
_, _ = fmt.Fprintf(GinkgoWriter, "CRD available\n")
return nil

for _, crd := range crds.Items {
if crd.Spec.Names.Kind == ci.Kind {
return nil
}
}

_, _ = fmt.Fprintf(GinkgoWriter, "Failed to find CRD, retrying...\n")
return fmt.Errorf("failed to find CRD for resource: %s: %w", ci.GroupVersionResource.String(), err)
}).WithTimeout(time.Minute).WithPolling(5 * time.Second).Should(Succeed())
}

Expand Down
30 changes: 22 additions & 8 deletions test/e2e/managedcluster/managedcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
_ "embed"
"fmt"
"os"
"strings"

"github.com/Mirantis/hmc/test/utils"
"github.com/a8m/envsubst"
Expand Down Expand Up @@ -82,19 +83,32 @@ func GetProviderLabel(provider ProviderType) string {
return fmt.Sprintf("%s=%s", providerLabel, provider)
}

func setClusterName(templateName Template) {
var generatedName string

mcName := os.Getenv(EnvVarManagedClusterName)
if mcName == "" {
mcName = "e2e-test-" + uuid.New().String()[:8]
}

providerName := strings.Split(string(templateName), "-")[0]

// Append the provider name to the cluster name to ensure uniqueness between
// different deployed ManagedClusters.
generatedName = fmt.Sprintf("%s-%s", mcName, providerName)
if strings.Contains(string(templateName), "hosted") {
generatedName = fmt.Sprintf("%s-%s", generatedName, "hosted")
}

GinkgoT().Setenv(EnvVarManagedClusterName, generatedName)
}

// GetUnstructured returns an unstructured ManagedCluster object based on the
// provider and template.
func GetUnstructured(templateName Template) *unstructured.Unstructured {
GinkgoHelper()

generatedName := os.Getenv(EnvVarManagedClusterName) + "-" + string(templateName)
if generatedName == "" {
generatedName = "e2e-test-" + uuid.New().String()[:8] + "-" + string(templateName)
_, _ = fmt.Fprintf(GinkgoWriter, "Generated cluster name: %q\n", generatedName)
} else {
_, _ = fmt.Fprintf(GinkgoWriter, "Using configured cluster name: %q\n", generatedName)
}
GinkgoT().Setenv(EnvVarManagedClusterName, generatedName)
setClusterName(templateName)

var managedClusterTemplateBytes []byte
switch templateName {
Expand Down

0 comments on commit 84b64c9

Please sign in to comment.