Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-293859: test/e2e/atlas/kube: fix tests #3553

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions internal/kubernetes/operator/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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),
},
})
Expand Down Expand Up @@ -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)
}
}

Expand Down
26 changes: 13 additions & 13 deletions test/e2e/atlas/kubernetes_operator_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func TestKubernetesOperatorInstall(t *testing.T) {
"install",
s-urbaniak marked this conversation as resolved.
Show resolved Hide resolved
"--operatorVersion", "1.1.0")
cmd.Env = os.Environ()
resp, inErr := e2e.RunAndGetStdOut(cmd)
require.Error(t, inErr, string(resp))
assert.Equal(t, "Error: version 1.1.0 is not supported\n", string(resp))
_, inErr := e2e.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) {
Expand All @@ -65,9 +65,9 @@ func TestKubernetesOperatorInstall(t *testing.T) {
"install",
"--operatorVersion", "100.0.0")
cmd.Env = os.Environ()
resp, inErr := e2e.RunAndGetStdOut(cmd)
require.Error(t, inErr, string(resp))
assert.Equal(t, "Error: version 100.0.0 is not supported\n", string(resp))
_, inErr := e2e.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) {
Expand All @@ -77,9 +77,9 @@ func TestKubernetesOperatorInstall(t *testing.T) {
"install",
"--kubeconfig", "/path/to/non/existing/config")
cmd.Env = os.Environ()
resp, inErr := e2e.RunAndGetStdOut(cmd)
require.Error(t, inErr, string(resp))
assert.Equal(t, "Error: unable to prepare client configuration: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable\n", string(resp))
_, inErr := e2e.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) {
Expand Down Expand Up @@ -179,8 +179,8 @@ func TestKubernetesOperatorInstall(t *testing.T) {
"--import",
"--kubeContext", context)
cmd.Env = os.Environ()
resp, inErr := e2e.RunAndGetStdOut(cmd)
require.NoError(t, inErr, string(resp))
resp, inErr := e2e.RunAndGetStdOutAndErr(cmd)
require.NoError(t, inErr)
assert.Equal(t, "Atlas Kubernetes Operator installed successfully\n", string(resp))

checkDeployment(t, operator, operatorNamespace)
Expand Down Expand Up @@ -296,8 +296,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, cliPath)
})
Expand Down
Loading