Skip to content

Commit 7c0d2e8

Browse files
CLOUDP-148830: Added CRD versions logic (#812)
Added CRD versions logic
1 parent ea08695 commit 7c0d2e8

File tree

22 files changed

+431
-35
lines changed

22 files changed

+431
-35
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ COPY config/ config/
1919
COPY hack/ hack/
2020

2121
ARG VERSION
22-
ENV PRODUCT_VERSION=${VERSION}
22+
ENV VERSION=${VERSION}
2323
ENV TARGET_ARCH=amd64
2424
ENV TARGET_OS=linux
2525

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ CONTAINER_ENGINE?=docker
1010
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
1111
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
1212
VERSION ?= $(shell git describe --tags --dirty --broken | cut -c 2-)
13-
PRODUCT_VERSION ?= $(shell git describe --tags --dirty --broken | cut -c 2-)
1413

1514
# CHANNELS define the bundle channels used in the bundle.
1615
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
@@ -107,7 +106,8 @@ e2e-openshift-upgrade:
107106

108107
.PHONY: manager
109108
manager: generate fmt vet ## Build manager binary
110-
GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) go build -o bin/manager -ldflags="-X main.version=$(PRODUCT_VERSION)" cmd/manager/main.go
109+
@echo "Building operator with version $(VERSION)"
110+
GOOS=$(TARGET_OS) GOARCH=$(TARGET_ARCH) go build -o bin/manager -ldflags="-X github.com/mongodb/mongodb-atlas-kubernetes/pkg/version.Version=$(VERSION)" cmd/manager/main.go
111111

112112
.PHONY: run
113113
run: generate fmt vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
@@ -184,8 +184,8 @@ bundle: manifests kustomize ## Generate bundle manifests and metadata, then vali
184184
operator-sdk bundle validate ./bundle
185185

186186
.PHONY: image
187-
image: manager ## Build the operator image
188-
$(CONTAINER_ENGINE) build -t $(OPERATOR_IMAGE) .
187+
image: ## Build the operator image
188+
$(CONTAINER_ENGINE) build --build-arg VERSION=$(VERSION) -t $(OPERATOR_IMAGE) .
189189
$(CONTAINER_ENGINE) push $(OPERATOR_IMAGE)
190190

191191
.PHONY: bundle-build

cmd/manager/main.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"strings"
2626
"time"
2727

28+
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/version"
29+
2830
"go.uber.org/zap/zapcore"
2931
ctrzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
3032

@@ -43,7 +45,6 @@ import (
4345
"sigs.k8s.io/controller-runtime/pkg/predicate"
4446

4547
mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1"
46-
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlas"
4748
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasdatabaseuser"
4849
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasdeployment"
4950
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasproject"
@@ -56,18 +57,13 @@ import (
5657
var (
5758
scheme = runtime.NewScheme()
5859
setupLog = ctrl.Log.WithName("setup")
59-
60-
// Set by the linker during link time.
61-
version = "unknown"
6260
)
6361

6462
func init() {
6563
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
6664

6765
utilruntime.Must(mdbv1.AddToScheme(scheme))
6866
// +kubebuilder:scaffold:scheme
69-
70-
atlas.ProductVersion = version
7167
}
7268

7369
func main() {
@@ -83,12 +79,10 @@ func main() {
8379
os.Exit(1)
8480
}
8581

86-
logger.Info("starting with configuration", zap.Any("config", config), zap.Any("version", atlas.ProductVersion))
82+
logger.Info("starting with configuration", zap.Any("config", config), zap.Any("version", version.Version))
8783

8884
ctrl.SetLogger(zapr.NewLogger(logger))
8985

90-
logger.Info("MongoDB Atlas Operator version ", zap.String("version", version))
91-
9286
syncPeriod := time.Hour * 3
9387

9488
var cacheFunc cache.NewCacheFunc
@@ -223,7 +217,7 @@ func parseConfiguration() Config {
223217
flag.Parse()
224218

225219
if *appVersion {
226-
fmt.Println(version)
220+
fmt.Println(version.Version)
227221
os.Exit(0)
228222
}
229223

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/Azure/go-autorest/autorest v0.11.28
88
github.com/Azure/go-autorest/autorest/azure/auth v0.5.11
99
github.com/Azure/go-autorest/autorest/to v0.4.0
10+
github.com/Masterminds/semver v1.5.0
1011
github.com/aws/aws-sdk-go v1.44.151
1112
github.com/fatih/structtag v1.2.0
1213
github.com/go-logr/zapr v1.2.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUM
6666
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
6767
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
6868
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
69+
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
70+
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
6971
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
7072
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
7173
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=

pkg/api/v1/atlasbackuppolicy_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ package v1
1010

1111
import (
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
14+
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status"
1315
)
1416

1517
// AtlasBackupPolicySpec defines the desired state of AtlasBackupPolicy
@@ -47,6 +49,13 @@ type AtlasBackupPolicy struct {
4749
Status AtlasBackupPolicyStatus `json:"status,omitempty"`
4850
}
4951

52+
func (in *AtlasBackupPolicy) GetStatus() status.Status {
53+
return nil
54+
}
55+
56+
func (in *AtlasBackupPolicy) UpdateStatus(_ []status.Condition, _ ...status.Option) {
57+
}
58+
5059
type AtlasBackupPolicyStatus struct {
5160
}
5261

pkg/api/v1/atlasbackupschedule_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ package v1
1111
import (
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313

14+
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status"
15+
1416
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/common"
1517
)
1618

@@ -74,6 +76,13 @@ type AtlasBackupSchedule struct {
7476
Status AtlasBackupScheduleStatus `json:"status,omitempty"`
7577
}
7678

79+
func (in *AtlasBackupSchedule) GetStatus() status.Status {
80+
return nil
81+
}
82+
83+
func (in *AtlasBackupSchedule) UpdateStatus(_ []status.Condition, _ ...status.Option) {
84+
}
85+
7786
type AtlasBackupScheduleStatus struct {
7887
}
7988

pkg/api/v1/atlasproject_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ func NewProject(namespace, name, nameInAtlas string) *AtlasProject {
181181
}
182182
}
183183

184+
func (p *AtlasProject) WithLabels(labels map[string]string) *AtlasProject {
185+
p.Labels = labels
186+
return p
187+
}
188+
189+
func (p *AtlasProject) WithAnnotations(labels map[string]string) *AtlasProject {
190+
p.Labels = labels
191+
return p
192+
}
193+
184194
func (p *AtlasProject) WithName(name string) *AtlasProject {
185195
p.Name = name
186196
return p

pkg/api/v1/status/condition.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ const (
6161
DatabaseUserReadyType ConditionType = "DatabaseUserReady"
6262
)
6363

64+
// Generic condition type
65+
const (
66+
ResourceVersionStatus ConditionType = "ResourceVersionIsValid"
67+
)
68+
6469
// Condition describes the state of an Atlas Custom Resource at a certain point.
6570
type Condition struct {
6671
// Type of Atlas Custom Resource condition.

pkg/controller/atlas/client.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import (
55
"net/http"
66
"runtime"
77

8+
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/version"
9+
810
"go.mongodb.org/atlas/mongodbatlas"
911
"go.uber.org/zap"
1012

1113
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/httputil"
1214
)
1315

14-
// ProductVersion is used for sending the current Operator version in the User-Agent string
15-
var ProductVersion = "unknown"
16-
1716
// Client is the central place to create a client for Atlas using specified API keys and a server URL.
1817
// Note, that the default HTTP transport is reused globally by Go so all caching, keep-alive etc will be in action.
1918
func Client(atlasDomain string, connection Connection, log *zap.SugaredLogger) (mongodbatlas.Client, error) {
@@ -28,7 +27,7 @@ func Client(atlasDomain string, connection Connection, log *zap.SugaredLogger) (
2827
if err != nil {
2928
return mongodbatlas.Client{}, err
3029
}
31-
client.UserAgent = fmt.Sprintf("%s/%s (%s;%s)", "MongoDBAtlasKubernetesOperator", ProductVersion, runtime.GOOS, runtime.GOARCH)
30+
client.UserAgent = fmt.Sprintf("%s/%s (%s;%s)", "MongoDBAtlasKubernetesOperator", version.Version, runtime.GOOS, runtime.GOARCH)
3231

3332
return *client, nil
3433
}

0 commit comments

Comments
 (0)