Skip to content
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the official registry as default to prevent any accidental pushes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳🥳🥳

IMG ?= <operator-registry>/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"
Expand Down
2 changes: 1 addition & 1 deletion agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

@chatton chatton Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this version of the agent allows us to provide the dummy configuration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

- name: VERSION_UPGRADE_HOOK_IMAGE
value: quay.io/mongodb/mongodb-kubernetes-operator-version-upgrade-post-start-hook:1.0.2
- name: MONGODB_IMAGE
Expand Down
8 changes: 2 additions & 6 deletions controllers/mongodb_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
57 changes: 10 additions & 47 deletions controllers/replica_set_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"

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

Expand All @@ -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
Expand Down Expand Up @@ -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())

Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -578,7 +542,6 @@ func (r ReplicaSetReconciler) buildAutomationConfigSecret(mdb mdbv1.MongoDBCommu

ac, err := buildAutomationConfig(
mdb,
manifest.BuildsForVersion(mdb.Spec.Version),
currentAC,
authModification,
tlsModification,
Expand Down
48 changes: 13 additions & 35 deletions controllers/replicaset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

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

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

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

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

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

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

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

Expand All @@ -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)

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

Expand Down
2 changes: 1 addition & 1 deletion deploy/openshift/operator_openshift.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 0 additions & 17 deletions pkg/automationconfig/automation_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
27 changes: 27 additions & 0 deletions pkg/automationconfig/automation_config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, buildDummyMongoDbVersionConfig(b.mongodbVersion))
}

currentAc := AutomationConfig{
Version: b.previousAC.Version,
Processes: processes,
Expand Down Expand Up @@ -191,3 +195,26 @@ func withFCV(fcv string) func(*Process) {
process.FeatureCompatibilityVersion = fcv
}
}

// 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 buildDummyMongoDbVersionConfig(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{},
},
},
}
}
Loading