From 025ef96812bbab5642ecdeb8b91ff61cc66ca924 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Mon, 15 Jan 2024 17:01:52 +0100 Subject: [PATCH] improvements suggestions --- pkg/api/v1/atlasdatabaseuser_types.go | 6 +++++- pkg/controller/atlas/provider.go | 13 ++++++++----- test/int/integration_suite_test.go | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/api/v1/atlasdatabaseuser_types.go b/pkg/api/v1/atlasdatabaseuser_types.go index caeb25fcc2..015c2473eb 100644 --- a/pkg/api/v1/atlasdatabaseuser_types.go +++ b/pkg/api/v1/atlasdatabaseuser_types.go @@ -230,9 +230,13 @@ func (p AtlasDatabaseUser) ToAtlasSDK(ctx context.Context, kubeClient client.Cli result := admin.NewCloudDatabaseUserWithDefaults() err = compat.JSONCopy(result, p.Spec) + if err != nil { + return nil, err + } + result.Password = &password - return result, err + return result, nil } func (p AtlasDatabaseUser) GetScopes(scopeType ScopeType) []string { diff --git a/pkg/controller/atlas/provider.go b/pkg/controller/atlas/provider.go index 41ee7b74d7..ccb190b098 100644 --- a/pkg/controller/atlas/provider.go +++ b/pkg/controller/atlas/provider.go @@ -120,18 +120,21 @@ func (p *ProductionProvider) SdkClient(ctx context.Context, secretRef *client.Ob //} c, err := NewClient(p.domain, secretData.PublicKey, secretData.PrivateKey) + if err != nil { + return nil, "", err + } - return c, secretData.OrgID, err + return c, secretData.OrgID, nil } -func getSecrets(ctx context.Context, k8sClient client.Client, secretRef, fallbackRef *client.ObjectKey) (credentialsSecret, error) { +func getSecrets(ctx context.Context, k8sClient client.Client, secretRef, fallbackRef *client.ObjectKey) (*credentialsSecret, error) { if secretRef == nil { secretRef = fallbackRef } secret := &corev1.Secret{} if err := k8sClient.Get(ctx, *secretRef, secret); err != nil { - return credentialsSecret{}, fmt.Errorf("failed to read Atlas API credentials from the secret %s: %w", secretRef.String(), err) + return nil, fmt.Errorf("failed to read Atlas API credentials from the secret %s: %w", secretRef.String(), err) } secretData := credentialsSecret{ @@ -141,10 +144,10 @@ func getSecrets(ctx context.Context, k8sClient client.Client, secretRef, fallbac } if missingFields, valid := validateSecretData(&secretData); !valid { - return credentialsSecret{}, fmt.Errorf("the following fields are missing in the secret %v: %v", secretRef, missingFields) + return nil, fmt.Errorf("the following fields are missing in the secret %v: %v", secretRef, missingFields) } - return secretData, nil + return &secretData, nil } func validateSecretData(secretData *credentialsSecret) ([]string, bool) { diff --git a/test/int/integration_suite_test.go b/test/int/integration_suite_test.go index db0c1c204f..077f01d0a3 100644 --- a/test/int/integration_suite_test.go +++ b/test/int/integration_suite_test.go @@ -124,7 +124,7 @@ var _ = SynchronizedBeforeSuite(func() []byte { err = e.Encode(*cfg) Expect(err).ToNot(HaveOccurred()) - fmt.Printf("Api Server is listening on %s\n", cfg.Host) + GinkgoWriter.Printf("Api Server is listening on %s\n", cfg.Host) }) return b.Bytes()