From bb5259dd1167bc9ddec61afa6d1bdc3a00d71433 Mon Sep 17 00:00:00 2001 From: Kartik Joshi Date: Tue, 19 Sep 2023 16:56:09 +0530 Subject: [PATCH] Azure: Add self managed provisioner for e2e test Add self managed provisioner class to handle e2e test request for already existing cluster Fixes: #1441 Signed-off-by: Kartik Joshi --- test/provisioner/provision_azure.go | 12 +++++- test/provisioner/provision_azure.properties | 1 + .../provision_azure_initializer.go | 7 ++++ test/provisioner/provision_azure_self_mgr.go | 40 +++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/provisioner/provision_azure_self_mgr.go diff --git a/test/provisioner/provision_azure.go b/test/provisioner/provision_azure.go index bb04258ff..dfd918fd6 100644 --- a/test/provisioner/provision_azure.go +++ b/test/provisioner/provision_azure.go @@ -159,6 +159,10 @@ func NewAzureCloudProvisioner(properties map[string]string) (CloudProvisioner, e return nil, err } + if AzureProps.IsSelfManaged { + return &AzureSelfManagedClusterProvisioner{}, nil + } + return &AzureCloudProvisioner{}, nil } @@ -176,6 +180,7 @@ func (p *AzureCloudProvisioner) DeleteVPC(ctx context.Context, cfg *envconf.Conf func createFederatedIdentityCredential(aksOIDCIssuer string) error { namespace := "confidential-containers-system" serviceAccountName := "cloud-api-adaptor" + log.Infof("Successfully created federated identity credential %q in resource group %q", AzureProps.federatedIdentityCredentialName, AzureProps.ResourceGroupName) if _, err := AzureProps.FederatedIdentityCredentialsClient.CreateOrUpdate( context.Background(), @@ -348,7 +353,7 @@ func (p *AzureCloudProvisioner) DeleteCluster(ctx context.Context, cfg *envconf. return nil } -func (p *AzureCloudProvisioner) GetProperties(ctx context.Context, cfg *envconf.Config) map[string]string { +func getPropertiesImpl() map[string]string { props := map[string]string{ "CLOUD_PROVIDER": "azure", "AZURE_SUBSCRIPTION_ID": AzureProps.SubscriptionID, @@ -366,6 +371,11 @@ func (p *AzureCloudProvisioner) GetProperties(ctx context.Context, cfg *envconf. return props } +func (p *AzureCloudProvisioner) GetProperties(ctx context.Context, cfg *envconf.Config) map[string]string { + log.Trace("GetProperties()") + return getPropertiesImpl() +} + func (p *AzureCloudProvisioner) UploadPodvm(imagePath string, ctx context.Context, cfg *envconf.Config) error { log.Trace("UploadPodvm()") log.Trace("Image is uploaded via packer in case of azure") diff --git a/test/provisioner/provision_azure.properties b/test/provisioner/provision_azure.properties index 3bf1afe17..6f6c3e6db 100644 --- a/test/provisioner/provision_azure.properties +++ b/test/provisioner/provision_azure.properties @@ -12,3 +12,4 @@ AZURE_IMAGE_ID="" SSH_USERNAME="" AZURE_CLI_AUTH="false" IS_CI_MANAGED_CLUSTER="false" +IS_SELF_MANAGED_CLUSTER="false" diff --git a/test/provisioner/provision_azure_initializer.go b/test/provisioner/provision_azure_initializer.go index b73e8f475..9c64c8246 100644 --- a/test/provisioner/provision_azure_initializer.go +++ b/test/provisioner/provision_azure_initializer.go @@ -32,6 +32,7 @@ type AzureProperties struct { ManagedIdentityName string IsCIManaged bool CaaImage string + IsSelfManaged bool InstanceSize string NodeName string @@ -71,6 +72,12 @@ func initAzureProperties(properties map[string]string) error { AzureProps.IsCIManaged = true } + selfManagedStr := properties["IS_SELF_MANAGED_CLUSTER"] + AzureProps.IsSelfManaged = false + if strings.EqualFold(selfManagedStr, "yes") || strings.EqualFold(selfManagedStr, "true") { + AzureProps.IsSelfManaged = true + } + if AzureProps.SubscriptionID == "" { return errors.New("AZURE_SUBSCRIPTION_ID was not set.") } diff --git a/test/provisioner/provision_azure_self_mgr.go b/test/provisioner/provision_azure_self_mgr.go new file mode 100644 index 000000000..cc7641bdd --- /dev/null +++ b/test/provisioner/provision_azure_self_mgr.go @@ -0,0 +1,40 @@ +//go:build azure + +// (C) Copyright Confidential Containers Contributors +// SPDX-License-Identifier: Apache-2.0 + +package provisioner + +import ( + "context" + + "sigs.k8s.io/e2e-framework/pkg/envconf" +) + +// AzureSelfManagedClusterProvisioner implements the CloudProvisioner interface for self-managed k8s cluster in azure cloud. +type AzureSelfManagedClusterProvisioner struct { +} + +func (p *AzureSelfManagedClusterProvisioner) CreateCluster(ctx context.Context, cfg *envconf.Config) error { + return nil +} + +func (p *AzureSelfManagedClusterProvisioner) CreateVPC(ctx context.Context, cfg *envconf.Config) error { + return createResourceImpl() +} + +func (p *AzureSelfManagedClusterProvisioner) DeleteCluster(ctx context.Context, cfg *envconf.Config) error { + return nil +} + +func (p *AzureSelfManagedClusterProvisioner) DeleteVPC(ctx context.Context, cfg *envconf.Config) error { + return deleteResourceImpl() +} + +func (p *AzureSelfManagedClusterProvisioner) UploadPodvm(imagePath string, ctx context.Context, cfg *envconf.Config) error { + return nil +} + +func (p *AzureSelfManagedClusterProvisioner) GetProperties(ctx context.Context, cfg *envconf.Config) map[string]string { + return getPropertiesImpl() +}