From 91b2598a8c58bc299bd58b468420c8146dbd64b5 Mon Sep 17 00:00:00 2001 From: Melanija Cvetic <119604954+cveticm@users.noreply.github.com> Date: Mon, 27 Jan 2025 15:06:41 +0000 Subject: [PATCH] chore: Ports atlascli changes (#24) * Ports AtlasCLI changes * Makes install e22e required and removes e2e generic --- build/ci/evergreen.yml | 10 +------ internal/kubernetes/operator/install.go | 15 ++++++++--- .../kubernetes/operator/project/project.go | 5 ++-- .../operator/project/project_test.go | 2 +- test/e2e/kubernetes_operator_install_test.go | 27 ++++++++++--------- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/build/ci/evergreen.yml b/build/ci/evergreen.yml index ae8b355..1e79e93 100644 --- a/build/ci/evergreen.yml +++ b/build/ci/evergreen.yml @@ -257,7 +257,7 @@ tasks: MCLI_SERVICE: cloud E2E_TAGS: apply - name: atlas_kubernetes_install_e2e - tags: [ "e2e","generic","kubernetes", "assigned_to_jira_team_cloudp_kubernetes_atlas" ] + tags: [ "e2e","required","kubernetes", "assigned_to_jira_team_cloudp_kubernetes_atlas" ] must_have_test_results: true commands: - func: "install gotestsum" @@ -279,14 +279,6 @@ buildvariants: <<: *go_linux_version tasks: - name: .code_health - - name: e2e_generic - display_name: "E2E Tests Generic" - run_on: - - rhel80-small - expansions: - <<: *go_linux_version - tasks: - - name: ".e2e .generic" - name: e2e_required display_name: "E2E Tests Required" run_on: diff --git a/internal/kubernetes/operator/install.go b/internal/kubernetes/operator/install.go index 9eeceb0..ad5a605 100644 --- a/internal/kubernetes/operator/install.go +++ b/internal/kubernetes/operator/install.go @@ -28,6 +28,7 @@ import ( akov2common "github.com/mongodb/mongodb-atlas-kubernetes/v2/api/v1/common" "go.mongodb.org/atlas-sdk/v20241113004/admin" corev1 "k8s.io/api/core/v1" + "k8s.io/client-go/util/retry" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -150,7 +151,6 @@ func (i *Install) ensureProject(orgID, projectName string) (*admin.Group, error) Group: &admin.Group{ Name: projectName, OrgId: orgID, - RegionUsageRestrictions: pointer.Get(""), WithDefaultAlertsSettings: pointer.Get(true), }, }) @@ -284,10 +284,17 @@ func (i *Install) ensureCredentialsAssignment(ctx context.Context) error { } } - project.Spec.ConnectionSecret = connectionSecret + err := retry.RetryOnConflict(retry.DefaultRetry, func() error { + if err := i.kubectl.Get(ctx, client.ObjectKeyFromObject(&project), &project); err != nil { + return err + } + + project.Spec.ConnectionSecret = connectionSecret - if err = i.kubectl.Update(ctx, &project); err != nil { - return fmt.Errorf("failed to update atlas project %s", i.projectName) + return i.kubectl.Update(ctx, &project) + }) + if err != nil { + return fmt.Errorf("failed to update atlas project %s: %w", i.projectName, err) } } diff --git a/internal/kubernetes/operator/project/project.go b/internal/kubernetes/operator/project/project.go index 428f4a0..eebab26 100644 --- a/internal/kubernetes/operator/project/project.go +++ b/internal/kubernetes/operator/project/project.go @@ -184,7 +184,7 @@ func BuildAtlasProject(br *AtlasProjectBuildRequest) (*AtlasProjectResult, error } if br.Validator.FeatureExist(features.ResourceAtlasProject, featureCustomRoles) && !br.Validator.IsResourceSupported(features.ResourceAtlasCustomRole) { - customRoles, ferr := buildCustomRoles(br.ProjectStore, br.ProjectID) + customRoles, ferr := projectBuildCustomRoles(br.ProjectStore, br.ProjectID) if ferr != nil { return nil, ferr } @@ -275,8 +275,7 @@ func BuildProjectNamedConnectionSecret(credsProvider store.CredentialsGetter, na return secret } -//nolint:revive -func buildCustomRoles(crProvider store.DatabaseRoleLister, projectID string) ([]akov2.CustomRole, error) { +func projectBuildCustomRoles(crProvider store.DatabaseRoleLister, projectID string) ([]akov2.CustomRole, error) { dbRoles, err := crProvider.DatabaseRoles(projectID) if err != nil { return nil, err diff --git a/internal/kubernetes/operator/project/project_test.go b/internal/kubernetes/operator/project/project_test.go index c136c64..44cc7c0 100644 --- a/internal/kubernetes/operator/project/project_test.go +++ b/internal/kubernetes/operator/project/project_test.go @@ -1510,7 +1510,7 @@ func Test_buildCustomRoles(t *testing.T) { }, } - got, err := buildCustomRoles(rolesProvider, projectID) + got, err := projectBuildCustomRoles(rolesProvider, projectID) if err != nil { t.Fatalf("%v", err) } diff --git a/test/e2e/kubernetes_operator_install_test.go b/test/e2e/kubernetes_operator_install_test.go index 7a344b8..96f6ac1 100644 --- a/test/e2e/kubernetes_operator_install_test.go +++ b/test/e2e/kubernetes_operator_install_test.go @@ -31,6 +31,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "github.com/mongodb/atlas-cli-plugin-kubernetes/internal/kubernetes/operator/features" + "github.com/mongodb/atlas-cli-plugin-kubernetes/test" ) const ( @@ -54,9 +55,9 @@ func TestKubernetesOperatorInstall(t *testing.T) { "install", "--operatorVersion", "1.1.0") cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.Error(t, err, string(resp)) - assert.Contains(t, string(resp), "Error: version 1.1.0 is not supported\n") + _, inErr := test.RunAndGetStdOutAndErr(cmd) + require.Error(t, inErr) + assert.Equal(t, "Error: version 1.1.0 is not supported\n (exit status 1)", inErr.Error()) }) t.Run("should failed to install a non-existing version of the operator", func(t *testing.T) { @@ -66,9 +67,9 @@ func TestKubernetesOperatorInstall(t *testing.T) { "install", "--operatorVersion", "100.0.0") cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.Error(t, err, string(resp)) - assert.Contains(t, string(resp), "Error: version 100.0.0 is not supported\n") + _, inErr := test.RunAndGetStdOutAndErr(cmd) + require.Error(t, inErr) + assert.Equal(t, "Error: version 100.0.0 is not supported\n (exit status 1)", inErr.Error()) }) t.Run("should failed when unable to setup connection to the cluster", func(t *testing.T) { @@ -78,9 +79,9 @@ func TestKubernetesOperatorInstall(t *testing.T) { "install", "--kubeconfig", "/path/to/non/existing/config") cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.Error(t, err, string(resp)) - assert.Contains(t, string(resp), "Error: unable to prepare client configuration: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable\n") + _, inErr := test.RunAndGetStdOutAndErr(cmd) + require.Error(t, inErr) + assert.Equal(t, "Error: unable to prepare client configuration: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable\n (exit status 1)", inErr.Error()) }) t.Run("should install operator with default options", func(t *testing.T) { @@ -94,8 +95,8 @@ func TestKubernetesOperatorInstall(t *testing.T) { "install", "--kubeContext", context) cmd.Env = os.Environ() - resp, err := cmd.CombinedOutput() - require.NoError(t, err, string(resp)) + resp, inErr := test.RunAndGetStdOutAndErr(cmd) + require.NoError(t, inErr) assert.Equal(t, "Atlas Kubernetes Operator installed successfully\n", string(resp)) checkDeployment(t, operator, "default") @@ -297,8 +298,8 @@ func TestKubernetesOperatorInstall(t *testing.T) { deployment, false, )) - assert.Contains(t, deployment.Spec.Template.Spec.Containers[0].Args, "--resourceDeletionProtection=false") - assert.Contains(t, deployment.Spec.Template.Spec.Containers[0].Args, "--subresourceDeletionProtection=false") + assert.Contains(t, deployment.Spec.Template.Spec.Containers[0].Args, "--object-deletion-protection=false") + assert.Contains(t, deployment.Spec.Template.Spec.Containers[0].Args, "--subobject-deletion-protection=false") cleanUpKeys(t, operator, operatorNamespace) })