Skip to content

Commit

Permalink
Make sure VERSION gets passed across jobs
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Squizzato <[email protected]>
  • Loading branch information
squizzi committed Sep 30, 2024
1 parent 49a8f70 commit 8b8fbaa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jobs:
GINKGO_LABEL_FILTER: 'controller'
MANAGED_CLUSTER_NAME: ${{ needs.build.outputs.clustername }}
IMG: 'ghcr.io/mirantis/hmc/controller-ci:${{ needs.build.outputs.version }}'
VERSION: ${{ needs.build.outputs.version }}
run: |
make test-e2e
- name: Archive test results
Expand All @@ -115,17 +116,17 @@ jobs:
concurrency:
group: cloud-e2e-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
outputs:
clustername: ${{ needs.build.outputs.clustername }}
version: ${{ needs.build.outputs.version }}
env:
GINKGO_LABEL_FILTER: 'provider:cloud'
AWS_REGION: us-west-2
AWS_ACCESS_KEY_ID: ${{ secrets.CI_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_AWS_SECRET_ACCESS_KEY }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.CI_AZURE_SUBSCRIPTION_ID }}
AZURE_TENANT_ID: ${{ secrets.CI_AZURE_TENANT_ID }}
AZURE_CLIENT_ID: ${{ secrets.CI_AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.CI_AZURE_CLIENT_SECRET }}
clustername: ${{ needs.build.outputs.clustername }}
version: ${{ needs.build.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -144,8 +145,10 @@ jobs:
detached: true
- name: Run E2E tests
env:
GINKGO_LABEL_FILTER: 'provider:cloud'
MANAGED_CLUSTER_NAME: ${{ needs.build.outputs.clustername }}
IMG: 'ghcr.io/mirantis/hmc/controller-ci:${{ needs.build.outputs.version }}'
VERSION: ${{ needs.build.outputs.version }}
run: |
make test-e2e
- name: Archive test results
Expand All @@ -168,7 +171,6 @@ jobs:
clustername: ${{ needs.build.outputs.clustername }}
version: ${{ needs.build.outputs.version }}
env:
GINKGO_LABEL_FILTER: 'provider:onprem'
VSPHERE_USER: ${{ secrets.CI_VSPHERE_USER }}
VSPHERE_PASSWORD: ${{ secrets.CI_VSPHERE_PASSWORD }}
VSPHERE_SERVER: ${{ secrets.CI_VSPHERE_SERVER }}
Expand All @@ -193,8 +195,10 @@ jobs:
uses: azure/setup-kubectl@v4
- name: Run E2E tests
env:
GINKGO_LABEL_FILTER: 'provider:onprem'
MANAGED_CLUSTER_NAME: ${{ needs.build.outputs.clustername }}
IMG: 'ghcr.io/mirantis/hmc/controller-ci:${{ needs.build.outputs.version }}'
VERSION: ${{ needs.build.outputs.version }}
run: |
make test-e2e
- name: Archive test results
Expand Down
49 changes: 23 additions & 26 deletions test/e2e/managedcluster/clusteridentity/clusteridentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import (
)

type ClusterIdentity struct {
Resource string
Kind string
SecretName string
IdentityName string
SecretData map[string]string
GroupVersionResource schema.GroupVersionResource
Kind string
SecretName string
IdentityName string
SecretData map[string]string
}

// New creates a ClusterIdentity resource and associated secret for the given
Expand All @@ -48,26 +48,30 @@ func New(kc *kubeclient.KubeClient, provider managedcluster.ProviderType) *Clust
var (
resource string
kind string
version string
secretStringData map[string]string
)

switch provider {
case managedcluster.ProviderAWS:
resource = "awsclusterstaticidentities"
kind = "AWSClusterStaticIdentity"
version = "v1beta2"
secretStringData = map[string]string{
"AccessKeyID": os.Getenv(managedcluster.EnvVarAWSAccessKeyID),
"SecretAccessKey": os.Getenv(managedcluster.EnvVarAWSSecretAccessKey),
}
case managedcluster.ProviderAzure:
resource = "azureclusterstaticidentities"
kind = "AzureClusterStaticIdentity"
version = "v1beta1"
secretStringData = map[string]string{
"clientSecret": os.Getenv(managedcluster.EnvVarAzureClientSecret),
}
case managedcluster.ProviderVSphere:
resource = "vsphereclusteridentities"
kind = "VSphereClusterIdentity"
version = "v1beta1"
secretStringData = map[string]string{
"username": os.Getenv(managedcluster.EnvVarVSphereUser),
"password": os.Getenv(managedcluster.EnvVarVSpherePassword),
Expand All @@ -76,17 +80,22 @@ func New(kc *kubeclient.KubeClient, provider managedcluster.ProviderType) *Clust
Fail(fmt.Sprintf("Unsupported provider: %s", provider))
}

waitForResourceCRD(kc, resource)
By(fmt.Sprintf("waiting for %s CRD to be present", resource))
validateSecretDataPopulated(secretStringData)

ci := ClusterIdentity{
Resource: resource,
GroupVersionResource: schema.GroupVersionResource{
Group: "infrastructure.cluster.x-k8s.io",
Version: version,
Resource: resource,
},
Kind: kind,
SecretName: fmt.Sprintf("%s-cluster-identity-secret", provider),
IdentityName: fmt.Sprintf("%s-cluster-identity", provider),
SecretData: secretStringData,
}

ci.waitForResourceCRD(kc)
ci.createSecret(kc)
ci.createClusterIdentity(kc)

Expand All @@ -101,23 +110,17 @@ func validateSecretDataPopulated(secretData map[string]string) {

// waitForResourceCRD ensures the CRD for the given resource is present by
// trying to list the resources of the given type until it succeeds.
func waitForResourceCRD(kc *kubeclient.KubeClient, resource string) {
func (ci *ClusterIdentity) waitForResourceCRD(kc *kubeclient.KubeClient) {
GinkgoHelper()

ctx := context.Background()
client, err := dynamic.NewForConfig(kc.Config)
Expect(err).NotTo(HaveOccurred())

gvr := schema.GroupVersionResource{
Group: "infrastructure.cluster.x-k8s.io",
Version: "v1beta2",
Resource: resource,
}

Eventually(func() bool {
_, err := client.Resource(gvr).List(ctx, metav1.ListOptions{})
_, err := client.Resource(ci.GroupVersionResource).List(ctx, metav1.ListOptions{})
return err == nil
}, "1m", "5s").Should(BeTrue(), "failed to list %s resources", resource)
}, "1m", "5s").Should(BeTrue(), "failed to list %s", ci.GroupVersionResource.String())
}

// createSecret creates a secret affiliated with a ClusterIdentity.
Expand Down Expand Up @@ -156,12 +159,6 @@ func (ci *ClusterIdentity) createClusterIdentity(kc *kubeclient.KubeClient) {
client, err := dynamic.NewForConfig(kc.Config)
Expect(err).NotTo(HaveOccurred(), "failed to create dynamic client")

gvr := schema.GroupVersionResource{
Group: "infrastructure.cluster.x-k8s.io",
Version: "v1beta2",
Resource: ci.Resource,
}

clusterIdentity := &unstructured.Unstructured{
Object: map[string]any{
"apiVersion": "infrastructure.cluster.x-k8s.io/v1beta2",
Expand All @@ -181,7 +178,7 @@ func (ci *ClusterIdentity) createClusterIdentity(kc *kubeclient.KubeClient) {
},
}

if ci.Resource == "azureclusterstaticidentities" {
if ci.GroupVersionResource.Resource == "azureclusterstaticidentities" {
err = unstructured.SetNestedField(clusterIdentity.Object, os.Getenv(managedcluster.EnvVarAzureTenantID), "spec", "tenantID")
Expect(err).NotTo(HaveOccurred())

Expand All @@ -202,13 +199,13 @@ func (ci *ClusterIdentity) createClusterIdentity(kc *kubeclient.KubeClient) {
}
}

_, err = client.Resource(gvr).Create(ctx, clusterIdentity, metav1.CreateOptions{})
_, err = client.Resource(ci.GroupVersionResource).Create(ctx, clusterIdentity, metav1.CreateOptions{})
if apierrors.IsAlreadyExists(err) {
resp, err := client.Resource(gvr).Get(ctx, ci.IdentityName, metav1.GetOptions{})
resp, err := client.Resource(ci.GroupVersionResource).Get(ctx, ci.IdentityName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

clusterIdentity.SetResourceVersion(resp.GetResourceVersion())
_, err = client.Resource(gvr).Update(ctx, clusterIdentity, metav1.UpdateOptions{})
_, err = client.Resource(ci.GroupVersionResource).Update(ctx, clusterIdentity, metav1.UpdateOptions{})
Expect(err).NotTo(HaveOccurred(), "failed to create cluster identity")
} else {
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit 8b8fbaa

Please sign in to comment.