Skip to content

Commit dd209c5

Browse files
authored
Moving to operator-sdk v0.17.0 to allow easy imports in enterprise co… (#37)
1 parent f964d09 commit dd209c5

File tree

11 files changed

+616
-65
lines changed

11 files changed

+616
-65
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ tags
8080
vendor
8181
zz_generated*.go
8282
__pycache__
83+
Dockerfile

cmd/testrunner/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func withTest(test string) func(obj runtime.Object) {
222222
"test",
223223
"local",
224224
fmt.Sprintf("./test/e2e/%s", test),
225-
"--namespace",
225+
"--operator-namespace",
226226
testPod.Namespace,
227227
"--verbose",
228228
"--kubeconfig",

go.mod

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ module github.com/mongodb/mongodb-kubernetes-operator
33
go 1.13
44

55
require (
6-
github.com/Azure/go-autorest/autorest v0.9.7 // indirect
7-
github.com/Azure/go-autorest/autorest/adal v0.8.3 // indirect
6+
github.com/Azure/go-autorest v14.0.1+incompatible // indirect
87
github.com/cespare/xxhash/v2 v2.1.1 // indirect
98
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
109
github.com/gobuffalo/envy v1.7.1 // indirect
@@ -15,47 +14,22 @@ require (
1514
github.com/json-iterator/go v1.1.9 // indirect
1615
github.com/klauspost/compress v1.9.8 // indirect
1716
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
18-
github.com/operator-framework/operator-sdk v0.16.0
17+
github.com/operator-framework/operator-sdk v0.17.0
1918
github.com/prometheus/procfs v0.0.11 // indirect
2019
github.com/rogpeppe/go-internal v1.5.2 // indirect
2120
github.com/spf13/cobra v0.0.7 // indirect
2221
github.com/stretchr/testify v1.4.0
2322
go.mongodb.org/mongo-driver v1.3.2
2423
go.uber.org/zap v1.14.1
2524
google.golang.org/appengine v1.6.6 // indirect
26-
k8s.io/api v0.0.0
27-
k8s.io/apiextensions-apiserver v0.0.0
28-
k8s.io/apimachinery v0.0.0
25+
k8s.io/api v0.17.5
26+
k8s.io/apiextensions-apiserver v0.17.5
27+
k8s.io/apimachinery v0.17.5
2928
k8s.io/client-go v12.0.0+incompatible
30-
k8s.io/kube-openapi v0.0.0-20200316234421-82d701f24f9d // indirect
31-
sigs.k8s.io/controller-runtime v0.4.0
29+
sigs.k8s.io/controller-runtime v0.5.2
3230
sigs.k8s.io/yaml v1.2.0
3331
)
3432

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

37-
// Required by operator-sdk 0.16.0
38-
// Pinned to kubernetes-1.16.2
39-
replace (
40-
k8s.io/api => k8s.io/api v0.0.0-20191016110408-35e52d86657a
41-
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20191016113550-5357c4baaf65
42-
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20191004115801-a2eda9f80ab8
43-
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20191016112112-5190913f932d
44-
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20191016114015-74ad18325ed5
45-
k8s.io/client-go => k8s.io/client-go v0.0.0-20191016111102-bec269661e48
46-
k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20191016115326-20453efc2458
47-
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.0.0-20191016115129-c07a134afb42
48-
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20191004115455-8e001e5d1894
49-
k8s.io/component-base => k8s.io/component-base v0.0.0-20191016111319-039242c015a9
50-
k8s.io/cri-api => k8s.io/cri-api v0.0.0-20190828162817-608eb1dad4ac
51-
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.0.0-20191016115521-756ffa5af0bd
52-
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.0.0-20191016112429-9587704a8ad4
53-
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.0.0-20191016114939-2b2b218dc1df
54-
k8s.io/kube-proxy => k8s.io/kube-proxy v0.0.0-20191016114407-2e83b6f20229
55-
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.0.0-20191016114748-65049c67a58b
56-
k8s.io/kubectl => k8s.io/kubectl v0.0.0-20191016120415-2ed914427d51
57-
k8s.io/kubelet => k8s.io/kubelet v0.0.0-20191016114556-7841ed97f1b2
58-
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.0.0-20191016115753-cf0698c3a16b
59-
k8s.io/metrics => k8s.io/metrics v0.0.0-20191016113814-3b1a734dba6e
60-
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20191016112829-06bb3c9d77c9
61-
)
35+
replace k8s.io/client-go => k8s.io/client-go v0.17.5 // Required by controller-runtime

go.sum

Lines changed: 561 additions & 0 deletions
Large diffs are not rendered by default.

pkg/automationconfig/automation_config_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (b *Builder) SetFCV(fcv string) *Builder {
6060
}
6161

6262
func (b *Builder) AddVersion(version MongoDbVersionConfig) *Builder {
63-
for idx, _ := range version.Builds {
63+
for idx := range version.Builds {
6464
if version.Builds[idx].Modules == nil {
6565
version.Builds[idx].Modules = make([]string, 0)
6666
}

pkg/kube/client/client_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package client
22

33
import (
44
"context"
5+
"testing"
6+
57
"github.com/mongodb/mongodb-kubernetes-operator/pkg/kube/configmap"
68
"github.com/stretchr/testify/assert"
79
corev1 "k8s.io/api/core/v1"
810
k8sClient "sigs.k8s.io/controller-runtime/pkg/client"
9-
"testing"
1011
)
1112

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

3233
newCm.Name = "new-name"
3334

34-
objectKey, err = k8sClient.ObjectKeyFromObject(&newCm)
35-
err = client.CreateOrUpdate(&newCm)
35+
objectKey, _ = k8sClient.ObjectKeyFromObject(&newCm)
36+
_ = client.CreateOrUpdate(&newCm)
3637

37-
err = client.Get(context.TODO(), objectKey, &newCm)
38+
_ = client.Get(context.TODO(), objectKey, &newCm)
3839

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

5354
cm.Data["new-field"] = "value"
54-
err = client.CreateOrUpdate(&cm)
55+
_ = client.CreateOrUpdate(&cm)
5556

5657
newCm := corev1.ConfigMap{}
5758
objectKey, err := k8sClient.ObjectKeyFromObject(&newCm)
5859
assert.NoError(t, err)
59-
err = client.Get(context.TODO(), objectKey, &newCm)
60+
_ = client.Get(context.TODO(), objectKey, &newCm)
6061

6162
assert.Contains(t, cm.Data, "new-field")
6263
assert.Equal(t, cm.Data["new-field"], "value")

pkg/kube/pod/pod_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,33 @@ func (m mockPoller) Poll(interval, timeout time.Duration, condition wait.Conditi
3232
return nil
3333
}
3434
}
35-
return fmt.Errorf("timed out!")
35+
return fmt.Errorf("timed out")
3636
}
3737

3838
func TestWaitForPhase(t *testing.T) {
3939
mockedClient := client.NewClient(client.NewMockedClient())
4040
testPod := newPod(corev1.PodRunning)
4141
err := mockedClient.Update(context.TODO(), &testPod)
4242
assert.NoError(t, err)
43-
_, err = waitForPhase(mockedClient, types.NamespacedName{Name: testPod.Name, Namespace: testPod.Namespace}, time.Second*5, time.Minute*5, corev1.PodRunning, mockPoller{})
43+
_, err = waitForPhase(
44+
mockedClient,
45+
types.NamespacedName{Name: testPod.Name, Namespace: testPod.Namespace},
46+
time.Second*5,
47+
time.Minute*5,
48+
corev1.PodRunning,
49+
mockPoller{},
50+
)
4451
assert.NoError(t, err)
4552

4653
testPod = newPod(corev1.PodFailed)
47-
err = mockedClient.Update(context.TODO(), &testPod)
48-
_, err = waitForPhase(mockedClient, types.NamespacedName{Name: testPod.Name, Namespace: testPod.Namespace}, time.Second*5, time.Minute*5, corev1.PodRunning, mockPoller{})
54+
_ = mockedClient.Update(context.TODO(), &testPod)
55+
_, err = waitForPhase(mockedClient,
56+
types.NamespacedName{Name: testPod.Name, Namespace: testPod.Namespace},
57+
time.Second*5,
58+
time.Minute*5,
59+
corev1.PodRunning,
60+
mockPoller{},
61+
)
4962
assert.Error(t, err)
5063
}
5164

scripts/dev/build_and_deploy_operator.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
from dockerutil import build_and_push_image
2-
from dockerfile_generator import render
3-
from kubernetes import client, config
4-
from kubernetes.client.rest import ApiException
5-
from dev_config import DevConfig, load_config
6-
from typing import Dict, Optional
7-
import yaml
81
import io
92
import os
103
import time
4+
from typing import Dict, Optional
5+
6+
import yaml
7+
from kubernetes import client, config
8+
from kubernetes.client.rest import ApiException
9+
10+
from dev_config import DevConfig, load_config
11+
from dockerfile_generator import render
12+
from dockerutil import build_and_push_image
1113

1214

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

2830

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

3234

3335
def load_yaml_from_file(path: str) -> Optional[Dict]:

scripts/dev/templates/Dockerfile.operator

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

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

3030
{% block command -%}
3131
ENTRYPOINT ["/usr/local/bin/entrypoint"]
32-
{% endblock -%}
32+
{% endblock -%}

scripts/dev/templates/Dockerfile.template

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ FROM {{base_image}}
88
{% block packages -%}
99
{% endblock -%}
1010

11-
ENV OPERATOR_SDK_VERSION v0.15.2
11+
ENV OPERATOR_SDK_VERSION v0.17.0
1212
ENV GO111MODULE=on
13-
ENV GOFLAGS="-mod=vendor"
1413
ENV GOPATH ""
1514

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

2322
ADD . .
2423

25-
RUN go mod vendor && /bin/operator-sdk generate k8s
24+
RUN /bin/operator-sdk generate k8s
2625

2726
# build the binary
2827
{% block build_binary -%}

0 commit comments

Comments
 (0)