diff --git a/pkg/providers/aws.go b/pkg/providers/aws.go index fd0a50328..f61526c5f 100644 --- a/pkg/providers/aws.go +++ b/pkg/providers/aws.go @@ -2,16 +2,11 @@ package providers import ( "context" - "encoding/base64" "encoding/json" "fmt" "k8s.io/client-go/kubernetes" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/credentials" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/ec2" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -22,48 +17,12 @@ import ( "github.com/openshift/cluster-api-actuator-pkg/pkg/framework" "github.com/openshift/cluster-api-actuator-pkg/pkg/framework/gatherer" - "github.com/tidwall/gjson" ) const ( amiIDMetadataEndpoint = "http://169.254.169.254/latest/meta-data/ami-id" ) -// createAWSClient create AWS client. -func createAWSClient(oc *gatherer.CLI) *framework.AwsClient { - awscreds, err := oc.WithoutNamespace().Run("get").Args("secret/aws-creds", "-n", "kube-system", "-o", "json").Output() - if err != nil { - Skip("Unable to get AWS credentials secret, skipping the testing.") - } - - accessKeyIDBase64, secureKeyBase64 := gjson.Get(awscreds, `data.aws_access_key_id`).String(), gjson.Get(awscreds, `data.aws_secret_access_key`).String() - - accessKeyID, err := base64.StdEncoding.DecodeString(accessKeyIDBase64) - Expect(err).NotTo(HaveOccurred()) - secureKey, err := base64.StdEncoding.DecodeString(secureKeyBase64) - Expect(err).NotTo(HaveOccurred()) - clusterRegion, err := oc.WithoutNamespace().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.status.platformStatus.aws.region}").Output() - Expect(err).NotTo(HaveOccurred()) - - awsConfig := &aws.Config{ - Region: aws.String(clusterRegion), - Credentials: credentials.NewStaticCredentials( - string(accessKeyID), - string(secureKey), - "", - ), - } - - sess, err := session.NewSession(awsConfig) - Expect(err).ToNot(HaveOccurred()) - - aClient := &framework.AwsClient{ - Svc: ec2.New(sess), - } - - return aClient -} - var _ = Describe("MetadataServiceOptions", framework.LabelCloudProviderSpecific, framework.LabelProviderAWS, func() { var client runtimeclient.Client var clientset *kubernetes.Clientset @@ -278,9 +237,11 @@ var _ = Describe("CapacityReservationID", framework.LabelCloudProviderSpecific, By("Access AWS to create CapacityReservation") oc, _ := framework.NewCLI() - awsClient := createAWSClient(oc) + awsClient := framework.CreateAWSClient(oc) capacityReservationID, err := awsClient.CreateCapacityReservation(awsProviderConfig.InstanceType, "Linux/UNIX", awsProviderConfig.Placement.AvailabilityZone, 1) - Expect(err).ToNot(HaveOccurred()) + if err != nil { + Skip(fmt.Sprintf("Skip because CreateCapacityReservation failed %v", err)) + } Expect(capacityReservationID).ToNot(Equal("")) defer func() {