Skip to content

Commit e7c6368

Browse files
authored
CLOUDP-82159: Upgrade to operator-sdk v1.4.0 (#327)
* Import-only changes * Non-trivial code changes * Build, github, and evergreen changes * CRD changes * Address PR comments * Address PR comments II * Address PR comments III
1 parent e665f7e commit e7c6368

File tree

92 files changed

+913
-506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+913
-506
lines changed

.evergreen.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ functions:
1919
params:
2020
directory: mongodb-kubernetes-operator
2121

22-
setup_operator_sdk:
23-
- command: subprocess.exec
24-
type: setup
25-
params:
26-
working_dir: mongodb-kubernetes-operator/scripts/ci
27-
command: go run download.go
28-
env:
29-
URL: https://github.com/operator-framework/operator-sdk/releases/download/v0.19.4/operator-sdk-v0.19.4-s390x-linux-gnu
30-
FILENAME: operator-sdk
31-
DIR: ${workdir}/bin
32-
3322
# upload_e2e_logs has the responsibility of dumping as much information as
3423
# possible into the S3 bucket
3524
upload_e2e_logs:

.github/workflows/go.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ jobs:
1616
with:
1717
go-version: 1.14
1818

19+
- name: Test api
20+
run: go test -v ./api/...
21+
22+
- name: Test cmd
23+
run: go test -v ./cmd/...
24+
25+
- name: Test controllers
26+
run: go test -v ./controllers/...
27+
1928
- name: Test pkg
2029
run: go test -v ./pkg/...
2130

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ tags
7676
.history
7777
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
7878
*mypy_cache
79+
bin/
7980
venv/
8081
local-config.json
8182
.idea
@@ -84,5 +85,6 @@ __pycache__
8485
Dockerfile
8586
Dockerfile_python_formatting
8687
logs/*
88+
testbin/bin
8789
# OSX Trash
88-
.DS_Store
90+
.DS_Store

Makefile

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
SHELL := /bin/bash
2+
3+
# VERSION defines the project version for the bundle.
4+
# Update this value when you upgrade the version of your project.
5+
# To re-generate a bundle for another specific version without changing the standard setup, you can:
6+
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
7+
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
8+
VERSION ?= 0.0.1
9+
10+
# CHANNELS define the bundle channels used in the bundle.
11+
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
12+
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
13+
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=preview,fast,stable)
14+
# - use environment variables to overwrite this value (e.g export CHANNELS="preview,fast,stable")
15+
ifneq ($(origin CHANNELS), undefined)
16+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
17+
endif
18+
19+
# DEFAULT_CHANNEL defines the default channel used in the bundle.
20+
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
21+
# To re-generate a bundle for any other default channel without changing the default setup, you can:
22+
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
23+
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
24+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
25+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
26+
endif
27+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
28+
29+
# BUNDLE_IMG defines the image:tag used for the bundle.
30+
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
31+
BUNDLE_IMG ?= controller-bundle:$(VERSION)
32+
33+
# Image URL to use all building/pushing image targets
34+
IMG ?= quay.io/mongodb/mongodb-kubernetes-operator:0.5.0 # replace with localhost:5000/mongodb-kubernetes-operator locally
35+
DOCKERFILE ?= operator
36+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
37+
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=true,crdVersions=v1beta1"
38+
39+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
40+
ifeq (,$(shell go env GOBIN))
41+
GOBIN=$(shell go env GOPATH)/bin
42+
else
43+
GOBIN=$(shell go env GOBIN)
44+
endif
45+
46+
all: manager
47+
48+
# Run unit tests
49+
TEST ?= ./pkg/... ./api/... ./cmd/... ./controllers/... ./test/e2e/util/mongotester/...
50+
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
51+
test: generate fmt vet manifests
52+
mkdir -p ${ENVTEST_ASSETS_DIR}
53+
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
54+
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test $(TEST) -coverprofile cover.out
55+
56+
# Build manager binary
57+
manager: generate fmt vet
58+
go build -o bin/manager ./cmd/manager/main.go
59+
60+
# Run against the configured Kubernetes cluster in ~/.kube/config
61+
run: generate fmt vet manifests
62+
go run ./cmd/manager/main.go
63+
64+
# Install CRDs into a cluster
65+
install: manifests kustomize
66+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
67+
68+
# Uninstall CRDs from a cluster
69+
uninstall: manifests kustomize
70+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
71+
72+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
73+
deploy: manifests kustomize
74+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
75+
$(KUSTOMIZE) build config/default | kubectl apply -f -
76+
77+
# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
78+
undeploy:
79+
$(KUSTOMIZE) build config/default | kubectl delete -f -
80+
81+
# Generate manifests e.g. CRD, RBAC etc.
82+
manifests: controller-gen
83+
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=config/crd/bases
84+
85+
# Run go fmt against code
86+
fmt:
87+
go fmt ./...
88+
89+
# Run go vet against code
90+
vet:
91+
go vet ./...
92+
93+
# Generate code
94+
generate: controller-gen
95+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
96+
97+
# Build the docker image
98+
docker-build: dockerfile
99+
docker build -t ${IMG} .
100+
101+
# Push the docker image
102+
docker-push:
103+
docker push ${IMG}
104+
105+
# Download controller-gen locally if necessary
106+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
107+
controller-gen:
108+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
109+
110+
# Download kustomize locally if necessary
111+
KUSTOMIZE = $(shell pwd)/bin/kustomize
112+
kustomize:
113+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
114+
115+
# go-get-tool will 'go get' any package $2 and install it to $1.
116+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
117+
define go-get-tool
118+
@[ -f $(1) ] || { \
119+
set -e ;\
120+
TMP_DIR=$$(mktemp -d) ;\
121+
cd $$TMP_DIR ;\
122+
go mod init tmp ;\
123+
echo "Downloading $(2)" ;\
124+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
125+
rm -rf $$TMP_DIR ;\
126+
}
127+
endef
128+
129+
# Generate bundle manifests and metadata, then validate generated files.
130+
.PHONY: bundle
131+
bundle: manifests kustomize
132+
operator-sdk generate kustomize manifests -q
133+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
134+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
135+
operator-sdk bundle validate ./bundle
136+
137+
# Build the bundle image.
138+
.PHONY: bundle-build
139+
bundle-build:
140+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
141+
142+
# Generate Dockerfile
143+
.PHONY: dockerfile
144+
dockerfile:
145+
python scripts/dev/dockerfile_generator.py ${DOCKERFILE} > Dockerfile

PROJECT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
domain: mongodb.com
2+
layout: go.kubebuilder.io/v3
3+
projectName: mko-v1
4+
repo: github.com/mongodb/mongodb-kubernetes-operator
5+
resources:
6+
- crdVersion: v1beta1
7+
group: mongodbcommunity
8+
kind: MongoDBCommunity
9+
version: v1
10+
version: 3-alpha
11+
plugins:
12+
manifests.sdk.operatorframework.io/v2: {}
13+
scorecard.sdk.operatorframework.io/v2: {}

api/v1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2021.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1 contains API Schema definitions for the mongodbcommunity v1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=mongodbcommunity.mongodb.com
20+
package v1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "mongodbcommunity.mongodb.com", Version: "v1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

pkg/apis/mongodb/v1/mongodb_types.go renamed to api/v1/mongodbcommunity_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ type MongoDBCommunityStatus struct {
348348
Message string `json:"message,omitempty"`
349349
}
350350

351-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
351+
// +kubebuilder:object:root=true
352+
// +kubebuilder:subresource:status
352353

353354
// MongoDBCommunity is the Schema for the mongodbs API
354355
// +kubebuilder:subresource:status
@@ -462,7 +463,7 @@ func (a automationConfigReplicasScaler) CurrentReplicas() int {
462463
return a.current
463464
}
464465

465-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
466+
// +kubebuilder:object:root=true
466467

467468
// MongoDBCommunityList contains a list of MongoDB
468469
type MongoDBCommunityList struct {
File renamed without changes.

0 commit comments

Comments
 (0)