From 5e2b473b54bf1b1389992e87969190eb23ddcba4 Mon Sep 17 00:00:00 2001 From: gniranjan Date: Wed, 6 Sep 2023 14:29:46 -0500 Subject: [PATCH] e2e test for api 2023-09-04 --- .../redhatopenshift/openshiftclusters.go | 54 ++++++++++++++ .../openshiftclusters_addons.go | 72 +++++++++++++++++++ .../2023-09-04/redhatopenshift/operations.go | 48 +++++++++++++ .../redhatopenshift/operations_addons.go | 33 +++++++++ test/e2e/setup.go | 10 +-- 5 files changed, 212 insertions(+), 5 deletions(-) create mode 100644 pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/openshiftclusters.go create mode 100644 pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/openshiftclusters_addons.go create mode 100644 pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/operations.go create mode 100644 pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/operations_addons.go diff --git a/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/openshiftclusters.go b/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/openshiftclusters.go new file mode 100644 index 00000000000..09bc10dbf10 --- /dev/null +++ b/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/openshiftclusters.go @@ -0,0 +1,54 @@ +package redhatopenshift + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +import ( + "context" + "crypto/tls" + "net/http" + "time" + + "github.com/Azure/go-autorest/autorest" + + mgmtredhatopenshift20230904 "github.com/Azure/ARO-RP/pkg/client/services/redhatopenshift/mgmt/2023-09-04/redhatopenshift" + "github.com/Azure/ARO-RP/pkg/env" + "github.com/Azure/ARO-RP/pkg/util/azureclient" +) + +// OpenShiftClustersClient is a minimal interface for azure OpenshiftClustersClient +type OpenShiftClustersClient interface { + ListCredentials(ctx context.Context, resourceGroupName string, resourceName string) (result mgmtredhatopenshift20230904.OpenShiftClusterCredentials, err error) + Get(ctx context.Context, resourceGroupName string, resourceName string) (result mgmtredhatopenshift20230904.OpenShiftCluster, err error) + OpenShiftClustersClientAddons +} + +type openShiftClustersClient struct { + mgmtredhatopenshift20230904.OpenShiftClustersClient +} + +var _ OpenShiftClustersClient = &openShiftClustersClient{} + +// NewOpenShiftClustersClient creates a new OpenShiftClustersClient +func NewOpenShiftClustersClient(environment *azureclient.AROEnvironment, subscriptionID string, authorizer autorest.Authorizer) OpenShiftClustersClient { + var client mgmtredhatopenshift20230904.OpenShiftClustersClient + if env.IsLocalDevelopmentMode() { + client = mgmtredhatopenshift20230904.NewOpenShiftClustersClientWithBaseURI("https://localhost:8443", subscriptionID) + client.Sender = &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, // #nosec G402 + }, + }, + } + } else { + client = mgmtredhatopenshift20230904.NewOpenShiftClustersClientWithBaseURI(environment.ResourceManagerEndpoint, subscriptionID) + client.Authorizer = authorizer + } + client.PollingDelay = 10 * time.Second + client.PollingDuration = 2 * time.Hour + + return &openShiftClustersClient{ + OpenShiftClustersClient: client, + } +} diff --git a/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/openshiftclusters_addons.go b/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/openshiftclusters_addons.go new file mode 100644 index 00000000000..e1dc0603761 --- /dev/null +++ b/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/openshiftclusters_addons.go @@ -0,0 +1,72 @@ +package redhatopenshift + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +import ( + "context" + + mgmtredhatopenshift20230904 "github.com/Azure/ARO-RP/pkg/client/services/redhatopenshift/mgmt/2023-09-04/redhatopenshift" +) + +// OpenShiftClustersClientAddons contains addons for OpenShiftClustersClient +type OpenShiftClustersClientAddons interface { + CreateOrUpdateAndWait(ctx context.Context, resourceGroupName string, resourceName string, parameters mgmtredhatopenshift20230904.OpenShiftCluster) error + DeleteAndWait(ctx context.Context, resourceGroupName string, resourceName string) error + List(ctx context.Context) (clusters []mgmtredhatopenshift20230904.OpenShiftCluster, err error) + ListByResourceGroup(ctx context.Context, resourceGroupName string) (clusters []mgmtredhatopenshift20230904.OpenShiftCluster, err error) +} + +func (c *openShiftClustersClient) CreateOrUpdateAndWait(ctx context.Context, resourceGroupName string, resourceName string, parameters mgmtredhatopenshift20230904.OpenShiftCluster) error { + future, err := c.CreateOrUpdate(ctx, resourceGroupName, resourceName, parameters) + if err != nil { + return err + } + + return future.WaitForCompletionRef(ctx, c.Client) +} + +func (c *openShiftClustersClient) DeleteAndWait(ctx context.Context, resourceGroupName string, resourceName string) error { + future, err := c.Delete(ctx, resourceGroupName, resourceName) + if err != nil { + return err + } + + return future.WaitForCompletionRef(ctx, c.Client) +} + +func (c *openShiftClustersClient) List(ctx context.Context) (clusters []mgmtredhatopenshift20230904.OpenShiftCluster, err error) { + page, err := c.OpenShiftClustersClient.List(ctx) + if err != nil { + return nil, err + } + + for page.NotDone() { + clusters = append(clusters, page.Values()...) + + err = page.NextWithContext(ctx) + if err != nil { + return nil, err + } + } + + return clusters, nil +} + +func (c *openShiftClustersClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (clusters []mgmtredhatopenshift20230904.OpenShiftCluster, err error) { + page, err := c.OpenShiftClustersClient.ListByResourceGroup(ctx, resourceGroupName) + if err != nil { + return nil, err + } + + for page.NotDone() { + clusters = append(clusters, page.Values()...) + + err = page.NextWithContext(ctx) + if err != nil { + return nil, err + } + } + + return clusters, nil +} diff --git a/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/operations.go b/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/operations.go new file mode 100644 index 00000000000..0b4ee641485 --- /dev/null +++ b/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/operations.go @@ -0,0 +1,48 @@ +package redhatopenshift + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +import ( + "crypto/tls" + "net/http" + + "github.com/Azure/go-autorest/autorest" + + mgmtredhatopenshift20230904 "github.com/Azure/ARO-RP/pkg/client/services/redhatopenshift/mgmt/2023-09-04/redhatopenshift" + "github.com/Azure/ARO-RP/pkg/env" + "github.com/Azure/ARO-RP/pkg/util/azureclient" +) + +// OperationsClient is a minimal interface for azure OperationsClient +type OperationsClient interface { + OperationsClientAddons +} + +type operationsClient struct { + mgmtredhatopenshift20230904.OperationsClient +} + +var _ OperationsClient = &operationsClient{} + +// NewOperationsClient creates a new OperationsClient +func NewOperationsClient(environment *azureclient.AROEnvironment, subscriptionID string, authorizer autorest.Authorizer) OperationsClient { + var client mgmtredhatopenshift20230904.OperationsClient + if env.IsLocalDevelopmentMode() { + client = mgmtredhatopenshift20230904.NewOperationsClientWithBaseURI("https://localhost:8443", subscriptionID) + client.Sender = &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, // #nosec G402 + }, + }, + } + } else { + client = mgmtredhatopenshift20230904.NewOperationsClientWithBaseURI(environment.ResourceManagerEndpoint, subscriptionID) + client.Authorizer = authorizer + } + + return &operationsClient{ + OperationsClient: client, + } +} diff --git a/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/operations_addons.go b/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/operations_addons.go new file mode 100644 index 00000000000..d375141cf07 --- /dev/null +++ b/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift/operations_addons.go @@ -0,0 +1,33 @@ +package redhatopenshift + +// Copyright (c) Microsoft Corporation. +// Licensed under the Apache License 2.0. + +import ( + "context" + + mgmtredhatopenshift20230904 "github.com/Azure/ARO-RP/pkg/client/services/redhatopenshift/mgmt/2023-09-04/redhatopenshift" +) + +// OperationsClientAddons contains addons for OperationsClient +type OperationsClientAddons interface { + List(ctx context.Context) (operations []mgmtredhatopenshift20230904.Operation, err error) +} + +func (c *operationsClient) List(ctx context.Context) (operations []mgmtredhatopenshift20230904.Operation, err error) { + page, err := c.OperationsClient.List(ctx) + if err != nil { + return nil, err + } + + for page.NotDone() { + operations = append(operations, page.Values()...) + + err = page.NextWithContext(ctx) + if err != nil { + return nil, err + } + } + + return operations, nil +} diff --git a/test/e2e/setup.go b/test/e2e/setup.go index 159bac5bdab..c34ffb84942 100644 --- a/test/e2e/setup.go +++ b/test/e2e/setup.go @@ -40,7 +40,7 @@ import ( "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/compute" "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/features" "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/network" - redhatopenshift20220904 "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/redhatopenshift/2022-09-04/redhatopenshift" + redhatopenshift20230904 "github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/redhatopenshift/2023-09-04/redhatopenshift" "github.com/Azure/ARO-RP/pkg/util/cluster" utillog "github.com/Azure/ARO-RP/pkg/util/log" "github.com/Azure/ARO-RP/pkg/util/uuid" @@ -50,8 +50,8 @@ import ( var disallowedInFilenameRegex = regexp.MustCompile(`[<>:"/\\|?*\x00-\x1F]`) type clientSet struct { - Operations redhatopenshift20220904.OperationsClient - OpenshiftClusters redhatopenshift20220904.OpenShiftClustersClient + Operations redhatopenshift20230904.OperationsClient + OpenshiftClusters redhatopenshift20230904.OpenShiftClustersClient VirtualMachines compute.VirtualMachinesClient Resources features.ResourcesClient @@ -333,8 +333,8 @@ func newClientSet(ctx context.Context) (*clientSet, error) { } return &clientSet{ - Operations: redhatopenshift20220904.NewOperationsClient(_env.Environment(), _env.SubscriptionID(), authorizer), - OpenshiftClusters: redhatopenshift20220904.NewOpenShiftClustersClient(_env.Environment(), _env.SubscriptionID(), authorizer), + Operations: redhatopenshift20230904.NewOperationsClient(_env.Environment(), _env.SubscriptionID(), authorizer), + OpenshiftClusters: redhatopenshift20230904.NewOpenShiftClustersClient(_env.Environment(), _env.SubscriptionID(), authorizer), VirtualMachines: compute.NewVirtualMachinesClient(_env.Environment(), _env.SubscriptionID(), authorizer), Resources: features.NewResourcesClient(_env.Environment(), _env.SubscriptionID(), authorizer),