Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ tags
vendor
zz_generated*.go
__pycache__
Dockerfile
2 changes: 1 addition & 1 deletion cmd/testrunner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func withTest(test string) func(obj runtime.Object) {
"test",
"local",
fmt.Sprintf("./test/e2e/%s", test),
"--namespace",
"--operator-namespace",
testPod.Namespace,
"--verbose",
"--kubeconfig",
Expand Down
40 changes: 7 additions & 33 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ module github.com/mongodb/mongodb-kubernetes-operator
go 1.13

require (
github.com/Azure/go-autorest/autorest v0.9.7 // indirect
github.com/Azure/go-autorest/autorest/adal v0.8.3 // indirect
github.com/Azure/go-autorest v14.0.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gobuffalo/envy v1.7.1 // indirect
Expand All @@ -15,47 +14,22 @@ require (
github.com/json-iterator/go v1.1.9 // indirect
github.com/klauspost/compress v1.9.8 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/operator-framework/operator-sdk v0.16.0
github.com/operator-framework/operator-sdk v0.17.0
github.com/prometheus/procfs v0.0.11 // indirect
github.com/rogpeppe/go-internal v1.5.2 // indirect
github.com/spf13/cobra v0.0.7 // indirect
github.com/stretchr/testify v1.4.0
go.mongodb.org/mongo-driver v1.3.2
go.uber.org/zap v1.14.1
google.golang.org/appengine v1.6.6 // indirect
k8s.io/api v0.0.0
k8s.io/apiextensions-apiserver v0.0.0
k8s.io/apimachinery v0.0.0
k8s.io/api v0.17.5
k8s.io/apiextensions-apiserver v0.17.5
k8s.io/apimachinery v0.17.5
k8s.io/client-go v12.0.0+incompatible
k8s.io/kube-openapi v0.0.0-20200316234421-82d701f24f9d // indirect
sigs.k8s.io/controller-runtime v0.4.0
sigs.k8s.io/controller-runtime v0.5.2
sigs.k8s.io/yaml v1.2.0
)

replace github.com/docker/docker => github.com/moby/moby v17.12.0-ce-rc1.0.20200309214505-aa6a9891b09c+incompatible // Required by Helm

// Required by operator-sdk 0.16.0
// Pinned to kubernetes-1.16.2
replace (
k8s.io/api => k8s.io/api v0.0.0-20191016110408-35e52d86657a
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20191016113550-5357c4baaf65
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191004115801-a2eda9f80ab8
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20191016112112-5190913f932d
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20191016114015-74ad18325ed5
k8s.io/client-go => k8s.io/client-go v0.0.0-20191016111102-bec269661e48
k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20191016115326-20453efc2458
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.0.0-20191016115129-c07a134afb42
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20191004115455-8e001e5d1894
k8s.io/component-base => k8s.io/component-base v0.0.0-20191016111319-039242c015a9
k8s.io/cri-api => k8s.io/cri-api v0.0.0-20190828162817-608eb1dad4ac
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.0.0-20191016115521-756ffa5af0bd
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.0.0-20191016112429-9587704a8ad4
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.0.0-20191016114939-2b2b218dc1df
k8s.io/kube-proxy => k8s.io/kube-proxy v0.0.0-20191016114407-2e83b6f20229
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.0.0-20191016114748-65049c67a58b
k8s.io/kubectl => k8s.io/kubectl v0.0.0-20191016120415-2ed914427d51
k8s.io/kubelet => k8s.io/kubelet v0.0.0-20191016114556-7841ed97f1b2
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.0.0-20191016115753-cf0698c3a16b
k8s.io/metrics => k8s.io/metrics v0.0.0-20191016113814-3b1a734dba6e
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20191016112829-06bb3c9d77c9
)
replace k8s.io/client-go => k8s.io/client-go v0.17.5 // Required by controller-runtime
561 changes: 561 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/automationconfig/automation_config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (b *Builder) SetFCV(fcv string) *Builder {
}

func (b *Builder) AddVersion(version MongoDbVersionConfig) *Builder {
for idx, _ := range version.Builds {
for idx := range version.Builds {
if version.Builds[idx].Modules == nil {
version.Builds[idx].Modules = make([]string, 0)
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/kube/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package client

import (
"context"
"testing"

"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/configmap"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
k8sClient "sigs.k8s.io/controller-runtime/pkg/client"
"testing"
)

func TestChangingName_CreatesNewObject(t *testing.T) {
Expand All @@ -31,10 +32,10 @@ func TestChangingName_CreatesNewObject(t *testing.T) {

newCm.Name = "new-name"

objectKey, err = k8sClient.ObjectKeyFromObject(&newCm)
err = client.CreateOrUpdate(&newCm)
objectKey, _ = k8sClient.ObjectKeyFromObject(&newCm)
_ = client.CreateOrUpdate(&newCm)

err = client.Get(context.TODO(), objectKey, &newCm)
_ = client.Get(context.TODO(), objectKey, &newCm)

assert.Equal(t, newCm.Name, "new-name")
assert.Equal(t, newCm.Namespace, "some-namespace")
Expand All @@ -51,12 +52,12 @@ func TestAddingDataField_ModifiesExistingObject(t *testing.T) {
assert.NoError(t, err)

cm.Data["new-field"] = "value"
err = client.CreateOrUpdate(&cm)
_ = client.CreateOrUpdate(&cm)

newCm := corev1.ConfigMap{}
objectKey, err := k8sClient.ObjectKeyFromObject(&newCm)
assert.NoError(t, err)
err = client.Get(context.TODO(), objectKey, &newCm)
_ = client.Get(context.TODO(), objectKey, &newCm)

assert.Contains(t, cm.Data, "new-field")
assert.Equal(t, cm.Data["new-field"], "value")
Expand Down
21 changes: 17 additions & 4 deletions pkg/kube/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,33 @@ func (m mockPoller) Poll(interval, timeout time.Duration, condition wait.Conditi
return nil
}
}
return fmt.Errorf("timed out!")
return fmt.Errorf("timed out")
}

func TestWaitForPhase(t *testing.T) {
mockedClient := client.NewClient(client.NewMockedClient())
testPod := newPod(corev1.PodRunning)
err := mockedClient.Update(context.TODO(), &testPod)
assert.NoError(t, err)
_, err = waitForPhase(mockedClient, types.NamespacedName{Name: testPod.Name, Namespace: testPod.Namespace}, time.Second*5, time.Minute*5, corev1.PodRunning, mockPoller{})
_, err = waitForPhase(
mockedClient,
types.NamespacedName{Name: testPod.Name, Namespace: testPod.Namespace},
time.Second*5,
time.Minute*5,
corev1.PodRunning,
mockPoller{},
)
assert.NoError(t, err)

testPod = newPod(corev1.PodFailed)
err = mockedClient.Update(context.TODO(), &testPod)
_, err = waitForPhase(mockedClient, types.NamespacedName{Name: testPod.Name, Namespace: testPod.Namespace}, time.Second*5, time.Minute*5, corev1.PodRunning, mockPoller{})
_ = mockedClient.Update(context.TODO(), &testPod)
_, err = waitForPhase(mockedClient,
types.NamespacedName{Name: testPod.Name, Namespace: testPod.Namespace},
time.Second*5,
time.Minute*5,
corev1.PodRunning,
mockPoller{},
)
assert.Error(t, err)
}

Expand Down
18 changes: 10 additions & 8 deletions scripts/dev/build_and_deploy_operator.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from dockerutil import build_and_push_image
from dockerfile_generator import render
from kubernetes import client, config
from kubernetes.client.rest import ApiException
from dev_config import DevConfig, load_config
from typing import Dict, Optional
import yaml
import io
import os
import time
from typing import Dict, Optional

import yaml
from kubernetes import client, config
from kubernetes.client.rest import ApiException

from dev_config import DevConfig, load_config
from dockerfile_generator import render
from dockerutil import build_and_push_image


def _load_operator_service_account() -> Optional[Dict]:
Expand All @@ -27,7 +29,7 @@ def _load_operator_deployment() -> Optional[Dict]:


def _load_mongodb_crd() -> Optional[Dict]:
return load_yaml_from_file("deploy/crds/mongodb.com_mongodbs_crd.yaml")
return load_yaml_from_file("deploy/crds/mongodb.com_mongodb_crd.yaml")


def load_yaml_from_file(path: str) -> Optional[Dict]:
Expand Down
4 changes: 2 additions & 2 deletions scripts/dev/templates/Dockerfile.operator
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block build_binary -%}
# TODO: This build takes longer than it needs to and can still be optimized
RUN go build -o build/_output/bin/mongodb-kubernetes-operator -mod=vendor github.com/mongodb/mongodb-kubernetes-operator/cmd/manager
RUN go build -o build/_output/bin/mongodb-kubernetes-operator github.com/mongodb/mongodb-kubernetes-operator/cmd/manager

ENV manifest_version=4.2
RUN mkdir -p /content/ \
Expand All @@ -29,4 +29,4 @@ USER ${USER_UID}

{% block command -%}
ENTRYPOINT ["/usr/local/bin/entrypoint"]
{% endblock -%}
{% endblock -%}
5 changes: 2 additions & 3 deletions scripts/dev/templates/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ FROM {{base_image}}
{% block packages -%}
{% endblock -%}

ENV OPERATOR_SDK_VERSION v0.15.2
ENV OPERATOR_SDK_VERSION v0.17.0
ENV GO111MODULE=on
ENV GOFLAGS="-mod=vendor"
ENV GOPATH ""

RUN curl -LO https://github.com/operator-framework/operator-sdk/releases/download/${OPERATOR_SDK_VERSION}/operator-sdk-${OPERATOR_SDK_VERSION}-x86_64-linux-gnu \
Expand All @@ -22,7 +21,7 @@ RUN go mod download

ADD . .

RUN go mod vendor && /bin/operator-sdk generate k8s
RUN /bin/operator-sdk generate k8s

# build the binary
{% block build_binary -%}
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/e2eutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func UpdateMongoDBResource(original *mdbv1.MongoDB, updateFunc func(*mdbv1.Mongo
return f.Global.Client.Update(context.TODO(), original)
}

// waitForConfigMapToExist waits until a ConfigMap of the given name exists
// WaitForConfigMapToExist waits until a ConfigMap of the given name exists
// using the provided retryInterval and timeout
func WaitForConfigMapToExist(cmName string, retryInterval, timeout time.Duration) (corev1.ConfigMap, error) {
cm := corev1.ConfigMap{}
Expand All @@ -59,7 +59,7 @@ func WaitForMongoDBToReachPhase(t *testing.T, mdb *mdbv1.MongoDB, phase mdbv1.Ph
func waitForMongoDBCondition(mdb *mdbv1.MongoDB, retryInterval, timeout time.Duration, condition func(mdbv1.MongoDB) bool) error {
mdbNew := mdbv1.MongoDB{}
return wait.Poll(retryInterval, timeout, func() (done bool, err error) {
err = f.Global.Client.Get(context.TODO(), types.NamespacedName{Name: mdb.Name, Namespace: f.Global.Namespace}, &mdbNew)
err = f.Global.Client.Get(context.TODO(), types.NamespacedName{Name: mdb.Name, Namespace: f.Global.OperatorNamespace}, &mdbNew)
if err != nil {
return false, err
}
Expand All @@ -68,14 +68,14 @@ func waitForMongoDBCondition(mdb *mdbv1.MongoDB, retryInterval, timeout time.Dur
})
}

// waitForStatefulSetToExist waits until a StatefulSet of the given name exists
// WaitForStatefulSetToExist waits until a StatefulSet of the given name exists
// using the provided retryInterval and timeout
func WaitForStatefulSetToExist(stsName string, retryInterval, timeout time.Duration) (appsv1.StatefulSet, error) {
sts := appsv1.StatefulSet{}
return sts, waitForRuntimeObjectToExist(stsName, retryInterval, timeout, &sts)
}

// waitForStatefulSetToBeReady waits until all replicas of the StatefulSet with the given name
// WaitForStatefulSetToBeReady waits until all replicas of the StatefulSet with the given name
// have reached the ready status
func WaitForStatefulSetToBeReady(t *testing.T, mdb *mdbv1.MongoDB, retryInterval, timeout time.Duration) error {
return waitForStatefulSetCondition(t, mdb, retryInterval, timeout, func(sts appsv1.StatefulSet) bool {
Expand All @@ -91,7 +91,7 @@ func waitForStatefulSetCondition(t *testing.T, mdb *mdbv1.MongoDB, retryInterval

sts := appsv1.StatefulSet{}
return wait.Poll(retryInterval, timeout, func() (done bool, err error) {
err = f.Global.Client.Get(context.TODO(), types.NamespacedName{Name: mdb.Name, Namespace: f.Global.Namespace}, &sts)
err = f.Global.Client.Get(context.TODO(), types.NamespacedName{Name: mdb.Name, Namespace: f.Global.OperatorNamespace}, &sts)
if err != nil {
return false, err
}
Expand All @@ -105,7 +105,7 @@ func waitForStatefulSetCondition(t *testing.T, mdb *mdbv1.MongoDB, retryInterval
// using the provided retryInterval and timeout provided.
func waitForRuntimeObjectToExist(name string, retryInterval, timeout time.Duration, obj runtime.Object) error {
return wait.Poll(retryInterval, timeout, func() (done bool, err error) {
err = f.Global.Client.Get(context.TODO(), types.NamespacedName{Name: name, Namespace: f.Global.Namespace}, obj)
err = f.Global.Client.Get(context.TODO(), types.NamespacedName{Name: name, Namespace: f.Global.OperatorNamespace}, obj)
if err != nil {
return false, client.IgnoreNotFound(err)
}
Expand All @@ -117,7 +117,7 @@ func NewTestMongoDB() mdbv1.MongoDB {
return mdbv1.MongoDB{
ObjectMeta: metav1.ObjectMeta{
Name: "example-mongodb",
Namespace: f.Global.Namespace,
Namespace: f.Global.OperatorNamespace,
},
Spec: mdbv1.MongoDBSpec{
Members: 3,
Expand Down