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-205482: Remove legacy deployment #1182

Merged
merged 8 commits into from
Nov 2, 2023
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
11 changes: 11 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ jobs:
platform=$(echo ${{ matrix.k8s }} | awk -F "-" '{print $2}')
echo "k8s_version=$version" >> $GITHUB_OUTPUT
echo "k8s_platform=$platform" >> $GITHUB_OUTPUT
- name: Generate configuration for the tests
uses: ./.github/actions/gen-install-scripts
with:
IMAGE_URL: ${{ env.DOCKER_REPO }}:${{ steps.prepare.outputs.tag }}
VERSION: ${{ steps.prepare.outputs.tag }}
ENV: dev

- name: Change path for the test
run: |
awk '{gsub(/cloud.mongodb.com/, "cloud-qa.mongodb.com", $0); print}' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml > tmp && mv tmp bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml
- name: Create k8s Kind Cluster
if: ${{ steps.properties.outputs.k8s_platform == 'kind' && !env.ACT }}
uses: helm/[email protected]
Expand Down
511 changes: 141 additions & 370 deletions config/crd/bases/atlas.mongodb.com_atlasdeployments.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/rbac/clusterwide/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ rules:
verbs:
- get
- patch
- update
- update
2 changes: 1 addition & 1 deletion config/rbac/namespaced/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ rules:
verbs:
- get
- patch
- update
- update
356 changes: 144 additions & 212 deletions pkg/api/v1/atlasdeployment_types.go

Large diffs are not rendered by default.

103 changes: 0 additions & 103 deletions pkg/api/v1/atlasdeployment_types_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package v1

import (
"reflect"
"sort"
"testing"

"github.com/fatih/structtag"

"github.com/stretchr/testify/assert"
"go.mongodb.org/atlas/mongodbatlas"

"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/provider"
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr"
)

Expand Down Expand Up @@ -57,104 +52,6 @@ func init() {
excludedClusterFieldsTheirs["serverlessBackupOptions"] = true
}

func TestCompatibility(t *testing.T) {
compareStruct(DeploymentSpec{}, mongodbatlas.Cluster{}, t)
}

// TestEnums verifies that replacing the strings with "enum" in Atlas Operator works correctly and is (de)serialized
// into the correct Atlas Cluster
func TestEnums(t *testing.T) {
atlasCluster := mongodbatlas.Cluster{
ProviderSettings: &mongodbatlas.ProviderSettings{
ProviderName: "AWS",
},
ClusterType: "GEOSHARDED",
}
operatorCluster := AtlasDeploymentSpec{
DeploymentSpec: &DeploymentSpec{
ProviderSettings: &ProviderSettingsSpec{
ProviderName: provider.ProviderAWS,
},
ClusterType: TypeGeoSharded,
},
}
transformedCluster, err := operatorCluster.LegacyDeployment()
assert.NoError(t, err)
assert.Equal(t, atlasCluster, *transformedCluster)
}

func compareStruct(ours interface{}, their interface{}, t *testing.T) {
ourFields := getAllFieldsSorted(ours, excludedClusterFieldsOurs)
theirFields := getAllFieldsSorted(their, excludedClusterFieldsTheirs)

// Comparing the fields in sorted order first
ourStructName := reflect.ValueOf(ours).Type().Name()
theirStructName := reflect.ValueOf(their).Type().Name()
assert.Equal(t, ourFields, theirFields, "The fields for structs [ours: %s, theirs: %s] don't match!", ourStructName, theirStructName)

// Then recurse into the fields of type struct
structFieldsTags := getAllStructFieldTags(ours, excludedClusterFieldsOurs)
for _, field := range structFieldsTags {
ourStructField := findFieldValueByTag(ours, field)
theirStructField := findFieldValueByTag(their, field)

compareStruct(ourStructField, theirStructField, t)
}
}

func findFieldValueByTag(theStruct interface{}, tag string) interface{} {
o := reflect.ValueOf(theStruct)
for i := 0; i < o.NumField(); i++ {
theTag := parseJSONName(o.Type().Field(i).Tag)
if theTag == tag {
v := reflect.New(o.Type().Field(i).Type.Elem()).Elem().Interface()
return v
}
}
panic("Field with tag not found")
}

func getAllStructFieldTags(theStruct interface{}, excludedFields map[string]bool) []string {
o := reflect.ValueOf(theStruct)
var res []string
for i := 0; i < o.NumField(); i++ {
theTag := parseJSONName(o.Type().Field(i).Tag)
ft := o.Field(i).Type()
if ft.Kind() == reflect.Ptr {
ft = ft.Elem()
}
if _, ok := excludedFields[theTag]; !ok && ft.Kind() == reflect.Struct {
res = append(res, theTag)
}
}
return res
}

func getAllFieldsSorted(theStruct interface{}, excluded map[string]bool) []string {
var res []string
o := reflect.ValueOf(theStruct)
for i := 0; i < o.NumField(); i++ {
theTag := parseJSONName(o.Type().Field(i).Tag)
if _, ok := excluded[theTag]; !ok {
res = append(res, theTag)
}
}
sort.Strings(res)
return res
}

func parseJSONName(t reflect.StructTag) string {
tags, err := structtag.Parse(string(t))
if err != nil {
panic(err)
}
jsonTag, err := tags.Get("json")
if err != nil {
panic(err)
}
return jsonTag.Name
}

func TestIsEqual(t *testing.T) {
operatorArgs := ProcessArgs{
JavascriptEnabled: toptr.MakePtr(true),
Expand Down
157 changes: 0 additions & 157 deletions pkg/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions pkg/controller/atlasdeployment/advanced_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
const FreeTier = "M0"

func (r *AtlasDeploymentReconciler) ensureAdvancedDeploymentState(ctx *workflow.Context, project *mdbv1.AtlasProject, deployment *mdbv1.AtlasDeployment) (*mongodbatlas.AdvancedCluster, workflow.Result) {
advancedDeploymentSpec := deployment.Spec.AdvancedDeploymentSpec
advancedDeploymentSpec := deployment.Spec.DeploymentSpec

advancedDeployment, resp, err := ctx.Client.AdvancedClusters.Get(context.Background(), project.Status.ID, advancedDeploymentSpec.Name)

Expand All @@ -50,12 +50,12 @@ func (r *AtlasDeploymentReconciler) ensureAdvancedDeploymentState(ctx *workflow.
}
}

result := EnsureCustomZoneMapping(ctx, project.ID(), deployment.Spec.AdvancedDeploymentSpec.CustomZoneMapping, advancedDeployment.Name)
result := EnsureCustomZoneMapping(ctx, project.ID(), deployment.Spec.DeploymentSpec.CustomZoneMapping, advancedDeployment.Name)
if !result.IsOk() {
return advancedDeployment, result
}

result = EnsureManagedNamespaces(ctx, project.ID(), deployment.Spec.AdvancedDeploymentSpec.ClusterType, deployment.Spec.AdvancedDeploymentSpec.ManagedNamespaces, advancedDeployment.Name)
result = EnsureManagedNamespaces(ctx, project.ID(), deployment.Spec.DeploymentSpec.ClusterType, deployment.Spec.DeploymentSpec.ManagedNamespaces, advancedDeployment.Name)
if !result.IsOk() {
return advancedDeployment, result
}
Expand All @@ -78,7 +78,7 @@ func (r *AtlasDeploymentReconciler) ensureAdvancedDeploymentState(ctx *workflow.
}

func advancedDeploymentIdle(ctx *workflow.Context, project *mdbv1.AtlasProject, deployment *mdbv1.AtlasDeployment, atlasDeploymentAsAtlas *mongodbatlas.AdvancedCluster) (*mongodbatlas.AdvancedCluster, workflow.Result) {
specDeployment, atlasDeployment, err := MergedAdvancedDeployment(*atlasDeploymentAsAtlas, *deployment.Spec.AdvancedDeploymentSpec)
specDeployment, atlasDeployment, err := MergedAdvancedDeployment(*atlasDeploymentAsAtlas, *deployment.Spec.DeploymentSpec)
if err != nil {
return atlasDeploymentAsAtlas, workflow.Terminate(workflow.Internal, err.Error())
}
Expand All @@ -92,7 +92,7 @@ func advancedDeploymentIdle(ctx *workflow.Context, project *mdbv1.AtlasProject,
// paused is different from Atlas
// we need to first send a special (un)pause request before reconciling everything else
specDeployment = mdbv1.AdvancedDeploymentSpec{
Paused: deployment.Spec.AdvancedDeploymentSpec.Paused,
Paused: deployment.Spec.DeploymentSpec.Paused,
}
} else {
// otherwise, don't send the paused field
Expand All @@ -107,7 +107,9 @@ func advancedDeploymentIdle(ctx *workflow.Context, project *mdbv1.AtlasProject,
return atlasDeploymentAsAtlas, workflow.Terminate(workflow.Internal, err.Error())
}

atlasDeploymentAsAtlas, _, err = ctx.Client.AdvancedClusters.Update(context.Background(), project.Status.ID, deployment.Spec.AdvancedDeploymentSpec.Name, deploymentAsAtlas)
// TODO: Potential bug with disabling autoscaling if it was previously enabled

atlasDeploymentAsAtlas, _, err = ctx.Client.AdvancedClusters.Update(context.Background(), project.Status.ID, deployment.Spec.DeploymentSpec.Name, deploymentAsAtlas)
if err != nil {
return atlasDeploymentAsAtlas, workflow.Terminate(workflow.DeploymentNotUpdatedInAtlas, err.Error())
}
Expand Down
Loading
Loading