From 592c39550b51daa585ab7713a7df60b8cb0ac19a Mon Sep 17 00:00:00 2001 From: Zheng Xi Zhou Date: Wed, 23 Jun 2021 11:19:05 +0800 Subject: [PATCH] Fix rebase issues Signed-off-by: Zheng Xi Zhou --- pkg/clients/rds/rds_test.go | 11 ++++--- pkg/controller/oss/oss_controller.go | 39 +++++------------------- pkg/controller/sls/project_controller.go | 2 +- 3 files changed, 15 insertions(+), 37 deletions(-) diff --git a/pkg/clients/rds/rds_test.go b/pkg/clients/rds/rds_test.go index 305f85f..c58ad81 100644 --- a/pkg/clients/rds/rds_test.go +++ b/pkg/clients/rds/rds_test.go @@ -90,6 +90,7 @@ func TestNewClient(t *testing.T) { ctx context.Context accessKeyID string accessKeySecret string + securityToken string region string } type want struct { @@ -114,7 +115,7 @@ func TestNewClient(t *testing.T) { for name, tc := range cases { t.Run(name, func(t *testing.T) { - _, err := NewClient(tc.args.ctx, tc.args.accessKeyID, tc.args.accessKeySecret, tc.args.region) + _, err := NewClient(tc.args.ctx, tc.args.accessKeyID, tc.args.accessKeySecret, tc.args.securityToken, tc.args.region) if diff := cmp.Diff(tc.want.err, err, test.EquateErrors()); diff != "" { t.Errorf("\nNewClient(...) -want error, +got error:\n%s\n", diff) } @@ -123,7 +124,7 @@ func TestNewClient(t *testing.T) { } func TestDescribeDBInstance(t *testing.T) { - c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "cn-beijing") + c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "", "cn-beijing") type args struct { id string } @@ -167,7 +168,7 @@ func TestDescribeDBInstance(t *testing.T) { } func TestCreateDBInstance(t *testing.T) { - c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "cn-beijing") + c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "", "cn-beijing") type args struct { req CreateDBInstanceRequest } @@ -218,7 +219,7 @@ func TestCreateDBInstance(t *testing.T) { } func TestDeleteDBInstance(t *testing.T) { - c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "cn-beijing") + c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "", "cn-beijing") type args struct { id string } @@ -256,7 +257,7 @@ func TestDeleteDBInstance(t *testing.T) { } func TestCreateAccount(t *testing.T) { - c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "cn-beijing") + c, _ := NewClient(context.TODO(), "xwerwrfYfwq934tsfsFAKED", "fsdfwerfaUIIffaYYYYYFUUFHUDSDKSDFAKED", "", "cn-beijing") type args struct { id string username string diff --git a/pkg/controller/oss/oss_controller.go b/pkg/controller/oss/oss_controller.go index 4a931ae..3e20c54 100644 --- a/pkg/controller/oss/oss_controller.go +++ b/pkg/controller/oss/oss_controller.go @@ -26,8 +26,6 @@ import ( "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" "github.com/crossplane/crossplane-runtime/pkg/resource" "github.com/pkg/errors" - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -38,14 +36,8 @@ import ( ) const ( - errCreateClient = "cannot create OSS client" - errTrackUsage = "cannot track provider config usage" - errNoConnectionSecret = "no connection secret specified" - errGetConnectionSecret = "cannot get connection secret" - errFmtUnsupportedCredSource = "credentials source %q is not currently supported" -) - -const ( + errCreateClient = "cannot create OSS client" + errTrackUsage = "cannot track provider config usage" errFailedToCreateBucket = "failed to create OSS bucket" errFailedToUpdateBucket = "failed to update OSS bucket" errFailedToDeleteBucket = "failed to delete OSS bucket" @@ -84,33 +76,18 @@ func (c *Connector) Connect(ctx context.Context, mg resource.Managed) (managed.E return nil, errors.New(errNotBucket) } - var ( - secretKeySelector *xpv1.SecretKeySelector - region string - ) - if err := c.Usage.Track(ctx, mg); err != nil { return nil, errors.Wrap(err, errTrackUsage) } - providerConfig, err := util.GetProviderConfig(ctx, c.Client, cr.Spec.ProviderConfigReference.Name) + pcName := cr.Spec.ProviderConfigReference.Name + cred, err := util.GetCredentials(ctx, c.Client, pcName) if err != nil { return nil, err } - - if s := providerConfig.Spec.Credentials.Source; s != xpv1.CredentialsSourceSecret { - return nil, errors.Errorf(errFmtUnsupportedCredSource, s) - } - secretKeySelector = providerConfig.Spec.Credentials.SecretRef - region = providerConfig.Spec.Region - - if secretKeySelector == nil { - return nil, errors.New(errNoConnectionSecret) - } - s := &corev1.Secret{} - nn := types.NamespacedName{Namespace: secretKeySelector.Namespace, Name: secretKeySelector.Name} - if err := c.Client.Get(ctx, nn, s); err != nil { - return nil, errors.Wrap(err, errGetConnectionSecret) + region, err := util.GetRegion(ctx, c.Client, pcName) + if err != nil { + return nil, err } endpoint, err := util.GetEndpoint(cr.DeepCopyObject(), region) @@ -118,7 +95,7 @@ func (c *Connector) Connect(ctx context.Context, mg resource.Managed) (managed.E return nil, err } - ossClient, err := c.NewClientFn(ctx, endpoint, string(s.Data[util.AccessKeyID]), string(s.Data[util.AccessKeySecret]), string(s.Data[util.SecurityToken])) + ossClient, err := c.NewClientFn(ctx, endpoint, cred.AccessKeyID, cred.AccessKeySecret, cred.SecurityToken) return &External{ExternalClient: ossClient}, errors.Wrap(err, errCreateClient) } diff --git a/pkg/controller/sls/project_controller.go b/pkg/controller/sls/project_controller.go index 115b1f1..763b1f1 100644 --- a/pkg/controller/sls/project_controller.go +++ b/pkg/controller/sls/project_controller.go @@ -82,7 +82,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E if err != nil { return nil, err } - + slsClient := c.NewClientFn(cred.AccessKeyID, cred.AccessKeySecret, cred.SecurityToken, region) return &external{client: slsClient}, nil }