Skip to content

Commit

Permalink
Removed legacy deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-karpukhin committed Oct 27, 2023
1 parent 06198be commit fb2b806
Show file tree
Hide file tree
Showing 49 changed files with 1,272 additions and 2,138 deletions.
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.

4 changes: 2 additions & 2 deletions config/rbac/clusterwide/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ rules:
- apiGroups:
- atlas.mongodb.com
resources:
- atlasfederatedauths
- atlasfederatedauths
verbs:
- create
- delete
Expand All @@ -183,4 +183,4 @@ rules:
verbs:
- get
- patch
- update
- update
4 changes: 2 additions & 2 deletions config/rbac/namespaced/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ rules:
- apiGroups:
- atlas.mongodb.com
resources:
- atlasfederatedauths
- atlasfederatedauths
verbs:
- create
- delete
Expand All @@ -184,4 +184,4 @@ rules:
verbs:
- get
- patch
- update
- update
511 changes: 141 additions & 370 deletions deploy/crds/atlas.mongodb.com_atlasdeployments.yaml

Large diffs are not rendered by default.

356 changes: 144 additions & 212 deletions pkg/api/v1/atlasdeployment_types.go

Large diffs are not rendered by default.

177 changes: 75 additions & 102 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,103 +52,81 @@ 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 TestCompatibility(t *testing.T) {
// compareStruct(AdvancedDeploymentSpec{}, mongodbatlas.Cluster{}, t)
// }

// 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{
Expand Down
Loading

0 comments on commit fb2b806

Please sign in to comment.