Skip to content

Commit

Permalink
Update test/e2e/atlas/operator_helper_test.go
Browse files Browse the repository at this point in the history
Co-authored-by: Gustavo Bazan <[email protected]>
  • Loading branch information
s-urbaniak and gssbzn committed Nov 29, 2023
1 parent bc028ad commit f2f1e61
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
1 change: 1 addition & 0 deletions build/ci/library_owners.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"github.com/mongodb/mongodb-atlas-kubernetes/v2": "atlas_kubernetes_team",
"k8s.io/api": "atlas_kubernetes_team",
"k8s.io/apimachinery": "atlas_kubernetes_team",
"k8s.io/apiserver": "atlas_kubernetes_team",
"k8s.io/client-go": "atlas_kubernetes_team",
"k8s.io/apiextensions-apiserver": "atlas_kubernetes_team",
"sigs.k8s.io/yaml": "atlas_kubernetes_team",
Expand Down
2 changes: 1 addition & 1 deletion internal/kubernetes/operator/features/crds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func Test_CRDCompatibleVersion(t *testing.T) {
t.Run("should return operator major version when it is less than supported CRD version", func(t *testing.T) {
latestOperatorSemver, err := semver.NewVersion(LatestOperatorMajorVersion)
require.NoError(t, err)
operatorVersion := semver.New(latestOperatorSemver.Major(), latestOperatorSemver.Minor(), 2, "", "")
operatorVersion := semver.New(latestOperatorSemver.Major()-1, latestOperatorSemver.Minor(), 2, "", "")

expected := fmt.Sprintf("%d.%d.0", operatorVersion.Major(), operatorVersion.Minor())
compatibleVersion, err := CRDCompatibleVersion(operatorVersion.String())
Expand Down
50 changes: 19 additions & 31 deletions test/e2e/atlas/kubernetes_config_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,13 @@ func TestProjectWithMaintenanceWindow(t *testing.T) {
generator := s.generator
expectedProject := s.expectedProject
assertions := s.assertions
dictionary := resources.AtlasNameToKubernetesName()

newMaintenanceWindow := akov2project.MaintenanceWindow{
DayOfWeek: 1,
HourOfDay: 1,
}
expectedProject.Spec.MaintenanceWindow = newMaintenanceWindow
expectedProject.Spec.AlertConfigurations = defaultMaintenanceWindowAlertConfigs(expectedProject, dictionary)
expectedProject.Spec.AlertConfigurations = defaultMaintenanceWindowAlertConfigs()

t.Run("Add integration to the project", func(t *testing.T) {
cmd := exec.Command(cliPath,
Expand Down Expand Up @@ -1106,8 +1105,8 @@ func referenceSharedCluster(name, region, namespace, projectName string, labels
return cluster
}

func defaultMaintenanceWindowAlertConfigs(project *akov2.AtlasProject, dictionary map[string]string) []akov2.AlertConfiguration {
ownerNotifications := func(i int) []akov2.Notification {
func defaultMaintenanceWindowAlertConfigs() []akov2.AlertConfiguration {
ownerNotifications := func() []akov2.Notification {
return []akov2.Notification{
{
EmailEnabled: pointer.Get(true),
Expand All @@ -1116,57 +1115,46 @@ func defaultMaintenanceWindowAlertConfigs(project *akov2.AtlasProject, dictionar
SMSEnabled: pointer.Get(false),
TypeName: "GROUP",
Roles: []string{"GROUP_OWNER"},
APITokenRef: akov2common.ResourceRefNamespaced{
Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-api-token-%d", project.Name, i), dictionary),
Namespace: project.Namespace,
},
DatadogAPIKeyRef: akov2common.ResourceRefNamespaced{
Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-datadog-api-key-%d", project.Name, i), dictionary),
Namespace: project.Namespace,
},
OpsGenieAPIKeyRef: akov2common.ResourceRefNamespaced{
Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-ops-genie-api-key-%d", project.Name, i), dictionary),
Namespace: project.Namespace,
},
ServiceKeyRef: akov2common.ResourceRefNamespaced{
Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-service-key-%d", project.Name, i), dictionary),
Namespace: project.Namespace,
},
VictorOpsSecretRef: akov2common.ResourceRefNamespaced{
Name: resources.NormalizeAtlasName(fmt.Sprintf("%s-victor-ops-credentials-%d", project.Name, i), dictionary),
Namespace: project.Namespace,
},
},
}
}

return []akov2.AlertConfiguration{
{
Enabled: true,
EventTypeName: "MAINTENANCE_IN_ADVANCED",
Threshold: &akov2.Threshold{},
Notifications: ownerNotifications(0),
Enabled: true,
EventTypeName: "MAINTENANCE_IN_ADVANCED",
Threshold: &akov2.Threshold{},
Notifications: []akov2.Notification{
{
EmailEnabled: pointer.Get(true),
IntervalMin: 60,
DelayMin: pointer.Get(0),
SMSEnabled: pointer.Get(false),
TypeName: "GROUP",
Roles: []string{"GROUP_OWNER"},
},
},
MetricThreshold: &akov2.MetricThreshold{},
},
{
Enabled: true,
EventTypeName: "MAINTENANCE_STARTED",
Threshold: &akov2.Threshold{},
Notifications: ownerNotifications(1),
Notifications: ownerNotifications(),
MetricThreshold: &akov2.MetricThreshold{},
},
{
Enabled: true,
EventTypeName: "MAINTENANCE_NO_LONGER_NEEDED",
Threshold: &akov2.Threshold{},
Notifications: ownerNotifications(2),
Notifications: ownerNotifications(),
MetricThreshold: &akov2.MetricThreshold{},
},
{
Enabled: true,
EventTypeName: "MAINTENANCE_AUTO_DEFERRED",
Threshold: &akov2.Threshold{},
Notifications: ownerNotifications(3),
Notifications: ownerNotifications(),
MetricThreshold: &akov2.MetricThreshold{},
},
}
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/atlas/operator_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"
"time"

"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
akov2 "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/api/v1"
akov2toptr "github.com/mongodb/mongodb-atlas-kubernetes/v2/pkg/util/toptr"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -158,7 +159,7 @@ func (oh *operatorHelper) stopOperator() {
oh.t.Errorf("unable to retrieve operator deployment: %v", err)
}

deployment.Spec.Replicas = akov2toptr.MakePtr(int32(0))
deployment.Spec.Replicas = pointer.Get[int32](0)

err = oh.k8sClient.Update(context.Background(), &deployment, &client.UpdateOptions{})
if err != nil {
Expand Down

0 comments on commit f2f1e61

Please sign in to comment.