From 8ee3486d985bdbc9502a8ee499c11c6e29668723 Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 17 Feb 2021 17:13:23 +0000 Subject: [PATCH 1/4] Removed dependency on version manifest --- Makefile | 2 +- agent/Dockerfile | 2 +- config/manager/manager.yaml | 2 +- controllers/mongodb_tls_test.go | 8 +-- controllers/replica_set_controller.go | 57 ++++--------------- controllers/replicaset_controller_test.go | 48 +++++----------- pkg/automationconfig/automation_config.go | 17 ------ .../automation_config_builder.go | 27 +++++++++ .../automation_config_test.go | 26 --------- release.json | 8 ++- scripts/dev/templates/Dockerfile.operator | 5 -- 11 files changed, 61 insertions(+), 141 deletions(-) diff --git a/Makefile b/Makefile index 1bfc81123..09387eca1 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) BUNDLE_IMG ?= controller-bundle:$(VERSION) # Image URL to use all building/pushing image targets -IMG ?= quay.io/mongodb/mongodb-kubernetes-operator:0.5.0 # replace with localhost:5000/mongodb-kubernetes-operator locally +IMG ?= /mongodb-kubernetes-operator DOCKERFILE ?= operator # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=true,crdVersions=v1beta1" diff --git a/agent/Dockerfile b/agent/Dockerfile index 9bb918623..87ccb98c4 100644 --- a/agent/Dockerfile +++ b/agent/Dockerfile @@ -11,7 +11,7 @@ RUN apt-get -qq update \ && rm -rf /var/lib/apt/lists/* RUN mkdir -p agent \ - && curl --fail --retry 3 --silent https://s3.amazonaws.com/mciuploads/mms-automation/mongodb-mms-build-agent/builds/automation-agent/prod/mongodb-mms-automation-agent-${agent_version}.rhel7_x86_64.tar.gz -o agent/mongodb-agent.tar.gz \ + && curl --fail --retry 3 --silent https://mciuploads.s3.amazonaws.com/mms-automation/mongodb-mms-build-agent/builds/automation-agent/prod/mongodb-mms-automation-agent-${agent_version}.rhel7_x86_64.tar.gz -o agent/mongodb-agent.tar.gz \ && tar xfz agent/mongodb-agent.tar.gz \ && mv mongodb-mms-automation-agent-*/mongodb-mms-automation-agent agent/mongodb-agent \ && chmod +x agent/mongodb-agent \ diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index ff1e2468b..8a172fa09 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -32,7 +32,7 @@ spec: - name: OPERATOR_NAME value: "mongodb-kubernetes-operator" - name: AGENT_IMAGE # The MongoDB Agent the operator will deploy to manage MongoDB deployments - value: quay.io/mongodb/mongodb-agent:10.19.0.6562-1 + value: quay.io/mongodb/mongodb-agent:10.27.0.6772-1 - name: VERSION_UPGRADE_HOOK_IMAGE value: quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook:1.0.2 - name: MONGODB_IMAGE diff --git a/controllers/mongodb_tls_test.go b/controllers/mongodb_tls_test.go index 04a437ebc..990819f37 100644 --- a/controllers/mongodb_tls_test.go +++ b/controllers/mongodb_tls_test.go @@ -26,7 +26,7 @@ func TestStatefulSet_IsCorrectlyConfiguredWithTLS(t *testing.T) { err := createTLSSecretAndConfigMap(mgr.GetClient(), mdb) assert.NoError(t, err) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -85,14 +85,10 @@ func TestAutomationConfig_IsCorrectlyConfiguredWithTLS(t *testing.T) { err := createTLSSecretAndConfigMap(client, mdb) assert.NoError(t, err) - manifest, err := mockManifestProvider(mdb.Spec.Version)() - assert.NoError(t, err) - versionConfig := manifest.BuildsForVersion(mdb.Spec.Version) - tlsModification, err := getTLSConfigModification(client, mdb) assert.NoError(t, err) - ac, err := buildAutomationConfig(mdb, versionConfig, automationconfig.AutomationConfig{}, tlsModification) + ac, err := buildAutomationConfig(mdb, automationconfig.AutomationConfig{}, tlsModification) assert.NoError(t, err) return ac diff --git a/controllers/replica_set_controller.go b/controllers/replica_set_controller.go index 673974801..48509a412 100644 --- a/controllers/replica_set_controller.go +++ b/controllers/replica_set_controller.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "os" "strings" @@ -69,7 +68,6 @@ const ( mongodbName = "mongod" versionUpgradeHookName = "mongod-posthook" dataVolumeName = "data-volume" - versionManifestFilePath = "/usr/local/version_manifest.json" readinessProbePath = "/var/lib/mongodb-mms-automation/probes/readinessprobe" clusterFilePath = "/var/lib/automation/config/cluster-config.json" operatorServiceAccountName = "mongodb-kubernetes-operator" @@ -94,25 +92,15 @@ func init() { zap.ReplaceGlobals(logger) } -// ManifestProvider is a function which returns the VersionManifest which -// contains the list of all available MongoDB versions -type ManifestProvider func() (automationconfig.VersionManifest, error) - -func NewReconciler(mgr manager.Manager, manifestProvider ManifestProvider) *ReplicaSetReconciler { +func NewReconciler(mgr manager.Manager) *ReplicaSetReconciler { mgrClient := mgr.GetClient() secretWatcher := watch.New() - mp := manifestProvider - if mp == nil { - mp = readVersionManifestFromDisk - } - return &ReplicaSetReconciler{ - client: kubernetesClient.NewClient(mgrClient), - scheme: mgr.GetScheme(), - manifestProvider: mp, - log: zap.S(), - secretWatcher: &secretWatcher, + client: kubernetesClient.NewClient(mgrClient), + scheme: mgr.GetScheme(), + log: zap.S(), + secretWatcher: &secretWatcher, } } @@ -129,11 +117,10 @@ func (r *ReplicaSetReconciler) SetupWithManager(mgr ctrl.Manager) error { type ReplicaSetReconciler struct { // This client, initialized using mgr.Client() above, is a split client // that reads objects from the cache and writes to the apiserver - client kubernetesClient.Client - scheme *runtime.Scheme - manifestProvider func() (automationconfig.VersionManifest, error) - log *zap.SugaredLogger - secretWatcher *watch.ResourceWatcher + client kubernetesClient.Client + scheme *runtime.Scheme + log *zap.SugaredLogger + secretWatcher *watch.ResourceWatcher } // +kubebuilder:rbac:groups=mongodbcommunity.mongodb.com,resources=mongodbcommunity,verbs=get;list;watch;create;update;patch;delete @@ -446,7 +433,7 @@ func (r ReplicaSetReconciler) ensureAutomationConfig(mdb mdbv1.MongoDBCommunity) return secret.CreateOrUpdate(r.client, s) } -func buildAutomationConfig(mdb mdbv1.MongoDBCommunity, mdbVersionConfig automationconfig.MongoDbVersionConfig, currentAc automationconfig.AutomationConfig, modifications ...automationconfig.Modification) (automationconfig.AutomationConfig, error) { +func buildAutomationConfig(mdb mdbv1.MongoDBCommunity, currentAc automationconfig.AutomationConfig, modifications ...automationconfig.Modification) (automationconfig.AutomationConfig, error) { domain := getDomain(mdb.ServiceName(), mdb.Namespace, os.Getenv(clusterDNSName)) zap.S().Debugw("AutomationConfigMembersThisReconciliation", "mdb.AutomationConfigMembersThisReconciliation()", mdb.AutomationConfigMembersThisReconciliation()) @@ -459,7 +446,6 @@ func buildAutomationConfig(mdb mdbv1.MongoDBCommunity, mdbVersionConfig automati SetPreviousAutomationConfig(currentAc). SetMongoDBVersion(mdb.Spec.Version). SetFCV(mdb.GetFCV()). - AddVersion(mdbVersionConfig). AddModifications(getMongodConfigModification(mdb)). AddModifications(modifications...) newAc, err := builder.Build() @@ -470,22 +456,6 @@ func buildAutomationConfig(mdb mdbv1.MongoDBCommunity, mdbVersionConfig automati return newAc, nil } -func readVersionManifestFromDisk() (automationconfig.VersionManifest, error) { - versionManifestBytes, err := ioutil.ReadFile(versionManifestFilePath) - if err != nil { - return automationconfig.VersionManifest{}, err - } - return versionManifestFromBytes(versionManifestBytes) -} - -func versionManifestFromBytes(bytes []byte) (automationconfig.VersionManifest, error) { - versionManifest := automationconfig.VersionManifest{} - if err := json.Unmarshal(bytes, &versionManifest); err != nil { - return automationconfig.VersionManifest{}, err - } - return versionManifest, nil -} - // buildService creates a Service that will be used for the Replica Set StatefulSet // that allows all the members of the STS to see each other. // TODO: Make sure this Service is as minimal as possible, to not interfere with @@ -550,12 +520,6 @@ func getCustomRolesModification(mdb mdbv1.MongoDBCommunity) (automationconfig.Mo } func (r ReplicaSetReconciler) buildAutomationConfigSecret(mdb mdbv1.MongoDBCommunity) (corev1.Secret, error) { - - manifest, err := r.manifestProvider() - if err != nil { - return corev1.Secret{}, errors.Errorf("could not read version manifest from disk: %s", err) - } - authModification, err := scram.EnsureScram(r.client, mdb.ScramCredentialsNamespacedName(), mdb) if err != nil { return corev1.Secret{}, errors.Errorf("could not ensure scram credentials: %s", err) @@ -578,7 +542,6 @@ func (r ReplicaSetReconciler) buildAutomationConfigSecret(mdb mdbv1.MongoDBCommu ac, err := buildAutomationConfig( mdb, - manifest.BuildsForVersion(mdb.Spec.Version), currentAC, authModification, tlsModification, diff --git a/controllers/replicaset_controller_test.go b/controllers/replicaset_controller_test.go index cfc700aeb..b2e0a38bf 100644 --- a/controllers/replicaset_controller_test.go +++ b/controllers/replicaset_controller_test.go @@ -100,34 +100,12 @@ func newTestReplicaSetWithTLS() mdbv1.MongoDBCommunity { } } -func mockManifestProvider(version string) func() (automationconfig.VersionManifest, error) { - return func() (automationconfig.VersionManifest, error) { - return automationconfig.VersionManifest{ - Updated: 0, - Versions: []automationconfig.MongoDbVersionConfig{ - { - Name: version, - Builds: []automationconfig.BuildConfig{{ - Platform: "platform", - Url: "url", - GitVersion: "gitVersion", - Architecture: "arch", - Flavor: "flavor", - MinOsVersion: "0", - MaxOsVersion: "10", - Modules: []string{}, - }}, - }}, - }, nil - } -} - func TestKubernetesResources_AreCreated(t *testing.T) { // TODO: Create builder/yaml fixture of some type to construct MDB objects for unit tests mdb := newTestReplicaSet() mgr := client.NewManager(&mdb) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -147,7 +125,7 @@ func TestStatefulSet_IsCorrectlyConfigured(t *testing.T) { mdb := newTestReplicaSet() mgr := client.NewManager(&mdb) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -189,7 +167,7 @@ func TestChangingVersion_ResultsInRollingUpdateStrategyType(t *testing.T) { mdb := newTestReplicaSet() mgr := client.NewManager(&mdb) mgrClient := mgr.GetClient() - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: mdb.NamespacedName()}) assertReconciliationSuccessful(t, res, err) @@ -269,7 +247,7 @@ func TestService_isCorrectlyCreatedAndUpdated(t *testing.T) { mdb := newTestReplicaSet() mgr := client.NewManager(&mdb) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -289,7 +267,7 @@ func TestAutomationConfig_versionIsBumpedOnChange(t *testing.T) { mdb := newTestReplicaSet() mgr := client.NewManager(&mdb) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -313,7 +291,7 @@ func TestAutomationConfig_versionIsNotBumpedWithNoChanges(t *testing.T) { mdb := newTestReplicaSet() mgr := client.NewManager(&mdb) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -339,7 +317,7 @@ func TestAutomationConfig_CustomMongodConfig(t *testing.T) { mdb.Spec.AdditionalMongodConfig.Object = mongodConfig mgr := client.NewManager(&mdb) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -377,7 +355,7 @@ func TestExistingPasswordAndKeyfile_AreUsedWhenTheSecretExists(t *testing.T) { ) assert.NoError(t, err) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -405,7 +383,7 @@ func TestReplicaSet_IsScaledDown_OneMember_AtATime_WhenItAlreadyExists(t *testin mdb.Spec.Members = 5 mgr := client.NewManager(&mdb) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -449,7 +427,7 @@ func TestReplicaSet_IsScaledUp_OneMember_AtATime_WhenItAlreadyExists(t *testing. mdb := newTestReplicaSet() mgr := client.NewManager(&mdb) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -492,7 +470,7 @@ func TestReplicaSet_IsScaledUp_OneMember_AtATime_WhenItAlreadyExists(t *testing. func assertReplicaSetIsConfiguredWithScram(t *testing.T, mdb mdbv1.MongoDBCommunity) { mgr := client.NewManager(&mdb) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -517,7 +495,7 @@ func TestReplicaSet_IsScaledUpToDesiredMembers_WhenFirstCreated(t *testing.T) { mdb := newTestReplicaSet() mgr := client.NewManager(&mdb) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Namespace: mdb.Namespace, Name: mdb.Name}}) assertReconciliationSuccessful(t, res, err) @@ -595,7 +573,7 @@ func performReconciliationAndGetStatefulSet(t *testing.T, filePath string) appsv assert.NoError(t, err) mgr := client.NewManager(&mdb) assert.NoError(t, generatePasswordsForAllUsers(mdb, mgr.Client)) - r := NewReconciler(mgr, mockManifestProvider(mdb.Spec.Version)) + r := NewReconciler(mgr) res, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: mdb.NamespacedName()}) assertReconciliationSuccessful(t, res, err) diff --git a/pkg/automationconfig/automation_config.go b/pkg/automationconfig/automation_config.go index ff105aa7a..94b9f37a7 100644 --- a/pkg/automationconfig/automation_config.go +++ b/pkg/automationconfig/automation_config.go @@ -224,23 +224,6 @@ type VersionManifest struct { Versions []MongoDbVersionConfig `json:"versions"` } -// BuildsForVersion returns the MongoDbVersionConfig containing all of the version informatioon -// for the given mongodb version provided -func (v VersionManifest) BuildsForVersion(version string) MongoDbVersionConfig { - var builds []BuildConfig - for _, versionConfig := range v.Versions { - if versionConfig.Name != version { - continue - } - builds = versionConfig.Builds - break - } - return MongoDbVersionConfig{ - Name: version, - Builds: builds, - } -} - type BuildConfig struct { Platform string `json:"platform"` Url string `json:"url"` diff --git a/pkg/automationconfig/automation_config_builder.go b/pkg/automationconfig/automation_config_builder.go index e332adb5c..5e726e99c 100644 --- a/pkg/automationconfig/automation_config_builder.go +++ b/pkg/automationconfig/automation_config_builder.go @@ -137,6 +137,10 @@ func (b *Builder) Build() (AutomationConfig, error) { auth = b.enabler.EnableAuth(auth) } + if len(b.versions) == 0 { + b.versions = append(b.versions, buildDummyGenericMongoDbVersionConfig(b.mongodbVersion)) + } + currentAc := AutomationConfig{ Version: b.previousAC.Version, Processes: processes, @@ -191,3 +195,26 @@ func withFCV(fcv string) func(*Process) { process.FeatureCompatibilityVersion = fcv } } + +// buildDummyGenericMongoDbVersionConfig create a MongoDbVersionConfig which +// will be valid for any version of MongoDB. This is used as a default if no +// versions are manually specified. +func buildDummyGenericMongoDbVersionConfig(version string) MongoDbVersionConfig { + return MongoDbVersionConfig{ + Name: version, + Builds: []BuildConfig{ + { + Platform: "linux", + Architecture: "amd64", + Flavor: "rhel", + Modules: []string{}, + }, + { + Platform: "linux", + Architecture: "amd64", + Flavor: "ubuntu", + Modules: []string{}, + }, + }, + } +} diff --git a/pkg/automationconfig/automation_config_test.go b/pkg/automationconfig/automation_config_test.go index 2ca752f8c..f0a664223 100644 --- a/pkg/automationconfig/automation_config_test.go +++ b/pkg/automationconfig/automation_config_test.go @@ -171,32 +171,6 @@ func TestProcessHasPortSetToDefault(t *testing.T) { } } -func TestVersionManifest_BuildsForVersion(t *testing.T) { - vm := VersionManifest{ - Updated: 0, - Versions: []MongoDbVersionConfig{ - defaultMongoDbVersion("4.2.0"), - defaultMongoDbVersion("4.2.3"), - defaultMongoDbVersion("4.2.4"), - }, - } - - version := vm.BuildsForVersion("4.2.0") - assert.Len(t, version.Builds, 1) - assert.Equal(t, defaultMongoDbVersion("4.2.0"), version) - - version = vm.BuildsForVersion("4.2.3") - assert.Len(t, version.Builds, 1) - assert.Equal(t, defaultMongoDbVersion("4.2.3"), version) - - version = vm.BuildsForVersion("4.2.4") - assert.Len(t, version.Builds, 1) - assert.Equal(t, defaultMongoDbVersion("4.2.4"), version) - - version = vm.BuildsForVersion("4.2.1") - assert.Empty(t, version.Builds) -} - func TestModifications(t *testing.T) { incrementVersion := func(config *AutomationConfig) { config.Version += 1 diff --git a/release.json b/release.json index 7ff681f39..980e53daf 100644 --- a/release.json +++ b/release.json @@ -1,4 +1,8 @@ { - "mongodb-kubernetes-operator": "0.5.0", - "version-upgrade-hook": "1.0.2" + "mongodb-kubernetes-operator": "0.5.0", + "version-upgrade-hook": "1.0.2", + "agent": { + "version": "10.27.0.6772-1", + "tools_version": "100.2.0" + } } diff --git a/scripts/dev/templates/Dockerfile.operator b/scripts/dev/templates/Dockerfile.operator index d05e5b66f..b3b50fb9d 100644 --- a/scripts/dev/templates/Dockerfile.operator +++ b/scripts/dev/templates/Dockerfile.operator @@ -12,10 +12,6 @@ COPY build/bin/ build/bin/ # Build the operator RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager cmd/manager/main.go -ENV manifest_version=4.4 -RUN mkdir -p /content/ \ - && chmod -R +r /content/ \ - && curl --fail --retry 3 -o /content/version_manifest.json "https://opsmanager.mongodb.com/static/version_manifest/${manifest_version}.json" {% endblock -%} {% block build_second_stage -%} @@ -29,7 +25,6 @@ ENV OPERATOR=manager \ WORKDIR / COPY --from=builder /workspace/manager . COPY --from=builder /workspace/build/bin /usr/local/bin -COPY --from=builder /content/version_manifest.json /usr/local/version_manifest.json RUN /usr/local/bin/user_setup From c5243286c367d7dc12b57e085a51cf94a766fe10 Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 17 Feb 2021 17:22:54 +0000 Subject: [PATCH 2/4] added unit tests for mongodb version config --- .../automation_config_builder.go | 6 +-- .../automation_config_test.go | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/pkg/automationconfig/automation_config_builder.go b/pkg/automationconfig/automation_config_builder.go index 5e726e99c..9790a7a9e 100644 --- a/pkg/automationconfig/automation_config_builder.go +++ b/pkg/automationconfig/automation_config_builder.go @@ -138,7 +138,7 @@ func (b *Builder) Build() (AutomationConfig, error) { } if len(b.versions) == 0 { - b.versions = append(b.versions, buildDummyGenericMongoDbVersionConfig(b.mongodbVersion)) + b.versions = append(b.versions, buildDummyMongoDbVersionConfig(b.mongodbVersion)) } currentAc := AutomationConfig{ @@ -196,10 +196,10 @@ func withFCV(fcv string) func(*Process) { } } -// buildDummyGenericMongoDbVersionConfig create a MongoDbVersionConfig which +// buildDummyMongoDbVersionConfig create a MongoDbVersionConfig which // will be valid for any version of MongoDB. This is used as a default if no // versions are manually specified. -func buildDummyGenericMongoDbVersionConfig(version string) MongoDbVersionConfig { +func buildDummyMongoDbVersionConfig(version string) MongoDbVersionConfig { return MongoDbVersionConfig{ Name: version, Builds: []BuildConfig{ diff --git a/pkg/automationconfig/automation_config_test.go b/pkg/automationconfig/automation_config_test.go index f0a664223..859478047 100644 --- a/pkg/automationconfig/automation_config_test.go +++ b/pkg/automationconfig/automation_config_test.go @@ -184,3 +184,52 @@ func TestModifications(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 4, ac.Version) } + +func TestMongoDBVersionsConfig(t *testing.T) { + + t.Run("Dummy Config is used when no versions are set", func(t *testing.T) { + ac, err := NewBuilder().SetMongoDBVersion("4.4.2").Build() + assert.NoError(t, err) + + versions := ac.Versions + assert.Len(t, versions, 1) + v := versions[0] + dummyConfig := buildDummyMongoDbVersionConfig("4.4.2") + assert.Equal(t, v, dummyConfig) + }) + + t.Run("Dummy Config is not used when versions are set", func(t *testing.T) { + ac, err := NewBuilder().SetMongoDBVersion("4.4.2").AddVersion(MongoDbVersionConfig{ + Name: "4.4.2", + Builds: []BuildConfig{ + { + Platform: "linux", + Url: "url", + GitVersion: "gitVersion", + Architecture: "arch", + Flavor: "flavor", + MinOsVersion: "minOs", + MaxOsVersion: "maxOs", + }, + }, + }).Build() + + assert.NoError(t, err) + + versions := ac.Versions + assert.Len(t, versions, 1) + v := versions[0] + dummyConfig := buildDummyMongoDbVersionConfig("4.4.2") + assert.NotEqual(t, v, dummyConfig) + + b := versions[0].Builds[0] + assert.Equal(t, "linux", b.Platform) + assert.Equal(t, "url", b.Url) + assert.Equal(t, "gitVersion", b.GitVersion) + assert.Equal(t, "arch", b.Architecture) + assert.Equal(t, "minOs", b.MinOsVersion) + assert.Equal(t, "maxOs", b.MaxOsVersion) + + }) + +} From c51df753484cd01bb316845db33b11e80276ba9e Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 17 Feb 2021 17:34:45 +0000 Subject: [PATCH 3/4] fixed main.go --- cmd/manager/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/manager/main.go b/cmd/manager/main.go index fbbc375f7..63998f9f0 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -96,7 +96,7 @@ func main() { } // Setup Controller. - if err = controllers.NewReconciler(mgr, nil).SetupWithManager(mgr); err != nil { + if err = controllers.NewReconciler(mgr).SetupWithManager(mgr); err != nil { setupLog.Error(err, "Unable to create controller") os.Exit(1) } From 42fc255bf6e5fb7bce05c03c52633e33d8bf6b38 Mon Sep 17 00:00:00 2001 From: chatton Date: Wed, 17 Feb 2021 17:47:11 +0000 Subject: [PATCH 4/4] updated agent image in openshift sample --- deploy/openshift/operator_openshift.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/openshift/operator_openshift.yaml b/deploy/openshift/operator_openshift.yaml index 2b289acfa..f7765ae79 100644 --- a/deploy/openshift/operator_openshift.yaml +++ b/deploy/openshift/operator_openshift.yaml @@ -33,6 +33,6 @@ spec: - name: OPERATOR_NAME value: "mongodb-kubernetes-operator" - name: AGENT_IMAGE # The MongoDB Agent the operator will deploy to manage MongoDB deployments - value: quay.io/mongodb/mongodb-agent:10.19.0.6562-1 + value: quay.io/mongodb/mongodb-agent:10.27.0.6772-1 - name: VERSION_UPGRADE_HOOK_IMAGE value: quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook:1.0.2