Skip to content

Commit

Permalink
Operator Makefile Changes
Browse files Browse the repository at this point in the history
This replicates the same build behaviour for the Operator as done by `tridentctl`, that includes:

1. Override default trident installation image to the build image.
2. Override default trident-operator image in the operator.yaml and bundle.yaml to the operator build image in trident-installer.tar.gz.
3. The operator would only support only one dot version of the Trident.
  • Loading branch information
rohit-arora-dev committed May 23, 2020
1 parent bb71f41 commit da0a654
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 40 deletions.
14 changes: 13 additions & 1 deletion Makefile
Expand Up @@ -9,6 +9,7 @@ TRIDENT_VOLUME = trident_build
TRIDENT_VOLUME_PATH = /go/src/github.com/netapp/trident
TRIDENT_CONFIG_PKG = github.com/netapp/trident/config
TRIDENT_KUBERNETES_PKG = github.com/netapp/trident/persistent_store/crd
VERSION_FILE = github.com/netapp/trident/hack/VERSION
K8S_CODE_GENERATOR = code-generator-kubernetes-1.18.2

## build flags variables
Expand All @@ -29,6 +30,7 @@ CLI_BIN ?= tridentctl
CLI_PKG ?= github.com/netapp/trident/cli
K8S ?= ""
BUILD = build
VERSION ?= $(shell cat ${ROOT}/hack/VERSION)

DR_LINUX = docker run --rm \
--net=host \
Expand Down Expand Up @@ -61,7 +63,7 @@ GO_MACOS = ${DR_MACOS} go
default: dist

## version variables
TRIDENT_VERSION ?= 20.07.0
TRIDENT_VERSION ?= ${VERSION}
TRIDENT_IMAGE ?= trident
ifeq ($(BUILD_TYPE),custom)
TRIDENT_VERSION := ${TRIDENT_VERSION}-custom
Expand All @@ -79,6 +81,13 @@ endif
DIST_REGISTRY ?= netapp
TRIDENT_DIST_TAG := ${DIST_REGISTRY}/${TRIDENT_IMAGE}:${TRIDENT_VERSION}

## trident operator variable
OPERATOR_IMAGE ?= trident-operator
DEFAULT_TRIDENT_OPERATOR_REPO ?= netapp/${OPERATOR_IMAGE}
DEFAULT_TRIDENT_OPERATOR_VERSION ?= ${VERSION}
DEFAULT_TRIDENT_OPERATOR_IMAGE := ${DEFAULT_TRIDENT_OPERATOR_REPO}:${DEFAULT_TRIDENT_OPERATOR_VERSION}
OPERATOR_DIST_TAG := ${DIST_REGISTRY}/${OPERATOR_IMAGE}:${TRIDENT_VERSION}

## etcd variables
ifeq ($(ETCD_VERSION),)
ETCD_VERSION := v3.3.13
Expand Down Expand Up @@ -148,6 +157,9 @@ dist_tar: build
@cp -a trident-installer /tmp/
@cp -a deploy /tmp/trident-installer/
@cp ${BIN_DIR}/${CLI_BIN} /tmp/trident-installer/
@sed -Ei.bak "s|${DEFAULT_TRIDENT_OPERATOR_IMAGE}|${OPERATOR_DIST_TAG}|g" /tmp/trident-installer/deploy/operator.yaml
@sed -Ei.bak "s|${DEFAULT_TRIDENT_OPERATOR_IMAGE}|${OPERATOR_DIST_TAG}|g" /tmp/trident-installer/deploy/bundle.yaml
@rm /tmp/trident-installer/deploy/*.bak
@mkdir -p /tmp/trident-installer/extras/bin
@cp ${BIN_DIR}/${BIN} /tmp/trident-installer/extras/bin/${TARBALL_BIN}
@mkdir -p /tmp/trident-installer/extras/macos/bin
Expand Down
10 changes: 5 additions & 5 deletions config/config.go
Expand Up @@ -33,8 +33,8 @@ const (
/* Misc. orchestrator constants */
OrchestratorName = "trident"
OrchestratorClientName = OrchestratorName + "ctl"
orchestratorVersion = "20.07.0"
OrchestratorAPIVersion = "1"
DefaultOrchestratorVersion = "20.07.0"
PersistentStoreBootstrapAttempts = 30
PersistentStoreBootstrapTimeout = PersistentStoreBootstrapAttempts * time.Second
PersistentStoreTimeout = 10 * time.Second
Expand Down Expand Up @@ -151,7 +151,7 @@ var (
BuildTime = "unknown"

// BuildImage is the Trident image that was built
BuildImage = "netapp/trident:" + orchestratorVersion + "-custom.0"
BuildImage = "netapp/trident:" + DefaultOrchestratorVersion + "-custom.0"

// BuildEtcdVersion is the etcd version that Trident should be deployed with
BuildEtcdVersion = "v3.3.18"
Expand Down Expand Up @@ -215,12 +215,12 @@ func version() string {

if BuildType != "stable" {
if BuildType == "custom" {
version = fmt.Sprintf("%v-%v+%v", orchestratorVersion, BuildType, BuildHash)
version = fmt.Sprintf("%v-%v+%v", DefaultOrchestratorVersion, BuildType, BuildHash)
} else {
version = fmt.Sprintf("%v-%v.%v+%v", orchestratorVersion, BuildType, BuildTypeRev, BuildHash)
version = fmt.Sprintf("%v-%v.%v+%v", DefaultOrchestratorVersion, BuildType, BuildTypeRev, BuildHash)
}
} else {
version = orchestratorVersion
version = DefaultOrchestratorVersion
}

return version
Expand Down
2 changes: 1 addition & 1 deletion deploy/bundle.yaml
Expand Up @@ -168,7 +168,7 @@ spec:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: trident-operator
image: netapp/trident-operator:20.04.0
image: netapp/trident-operator:20.07.0
imagePullPolicy: IfNotPresent
name: trident-operator
serviceAccountName: trident-operator
Expand Down
2 changes: 1 addition & 1 deletion deploy/operator.yaml
Expand Up @@ -20,7 +20,7 @@ spec:
serviceAccountName: trident-operator
containers:
- name: trident-operator
image: netapp/trident-operator:20.04.0
image: netapp/trident-operator:20.07.0
command:
- "/usr/local/bin/trident-operator"
- "--debug"
Expand Down
1 change: 1 addition & 0 deletions hack/VERSION
@@ -0,0 +1 @@
20.07.0
9 changes: 7 additions & 2 deletions operator/Makefile
Expand Up @@ -8,7 +8,9 @@ OPERATOR_VOLUME = operator_build
TRIDENT_VOLUME_PATH = /go/src/github.com/netapp/trident
OPERATOR_VOLUME_PATH = /go/src/github.com/netapp/trident/operator
OPERATOR_CONFIG_PKG = github.com/netapp/trident/operator/config
OPERATOR_INSTALLER_CONFIG_PKG = github.com/netapp/trident/operator/controllers/provisioner/installer
TRIDENT_PROVISIONER_PKG = github.com/netapp/trident/operator/controllers/provisioner
VERSION_FILE = github.com/netapp/trident/hack/VERSION
K8S_CODE_GENERATOR = ./../code-generator-kubernetes-1.18.2

## build flags variables
Expand All @@ -25,6 +27,7 @@ BIN ?= trident-operator
TARBALL_BIN ?= trident-operator
K8S ?= ""
BUILD = build
VERSION ?= $(shell cat ${ROOT}/hack/VERSION)

DR_LINUX = docker run --rm \
--net=host \
Expand All @@ -42,7 +45,8 @@ GO_LINUX = ${DR_LINUX} go
.PHONY = default build retag dist dist_tar dist_tag clean vet

## version variables
OPERATOR_VERSION ?= 20.07.0
OPERATOR_VERSION ?= ${VERSION}
TRIDENT_IMAGE ?= trident
OPERATOR_IMAGE ?= trident-operator
ifeq ($(BUILD_TYPE),custom)
OPERATOR_VERSION := ${OPERATOR_VERSION}-custom
Expand All @@ -59,6 +63,7 @@ OPERATOR_TAG_OLD := ${REGISTRY_ADDR}/${OPERATOR_TAG_OLD}
endif
DIST_REGISTRY ?= netapp
OPERATOR_DIST_TAG := ${DIST_REGISTRY}/${OPERATOR_IMAGE}:${OPERATOR_VERSION}
TRIDENT_IMAGE_REPO := ${DIST_REGISTRY}/${TRIDENT_IMAGE}:

## etcd variables
ifeq ($(ETCD_VERSION),)
Expand All @@ -69,7 +74,7 @@ ETCD_SERVER ?= http://localhost:${ETCD_PORT}
ETCD_TAG := quay.io/coreos/etcd:${ETCD_VERSION}

# Go compiler flags need to be properly encapsulated with double quotes to handle spaces in values
BUILD_FLAGS = "-X \"${OPERATOR_CONFIG_PKG}.BuildHash=$(GITHASH)\" -X \"${OPERATOR_CONFIG_PKG}.BuildType=$(BUILD_TYPE)\" -X \"${OPERATOR_CONFIG_PKG}.BuildTypeRev=$(BUILD_TYPE_REV)\" -X \"${OPERATOR_CONFIG_PKG}.BuildTime=$(BUILD_TIME)\" -X \"${OPERATOR_CONFIG_PKG}.BuildImage=$(OPERATOR_DIST_TAG)\" -X \"${OPERATOR_CONFIG_PKG}.BuildEtcdVersion=$(ETCD_VERSION)\" -X \"${OPERATOR_CONFIG_PKG}.BuildEtcdImage=$(ETCD_TAG)\""
BUILD_FLAGS = "-X \"${OPERATOR_CONFIG_PKG}.BuildHash=$(GITHASH)\" -X \"${OPERATOR_CONFIG_PKG}.BuildType=$(BUILD_TYPE)\" -X \"${OPERATOR_CONFIG_PKG}.BuildTypeRev=$(BUILD_TYPE_REV)\" -X \"${OPERATOR_CONFIG_PKG}.BuildTime=$(BUILD_TIME)\" -X \"${OPERATOR_CONFIG_PKG}.BuildImage=$(OPERATOR_DIST_TAG)\" -X \"${OPERATOR_CONFIG_PKG}.BuildEtcdVersion=$(ETCD_VERSION)\" -X \"${OPERATOR_CONFIG_PKG}.BuildEtcdImage=$(ETCD_TAG)\" -X \"${OPERATOR_INSTALLER_CONFIG_PKG}.DefaultTridentVersion=$(OPERATOR_VERSION)\" -X \"${OPERATOR_INSTALLER_CONFIG_PKG}.DefaultTridentRepo=$(TRIDENT_IMAGE_REPO)\""

## Operator build targets

Expand Down
3 changes: 2 additions & 1 deletion operator/config/config.go
Expand Up @@ -4,6 +4,7 @@ package config

import (
"fmt"
"github.com/netapp/trident/config"

log "github.com/sirupsen/logrus"

Expand All @@ -21,7 +22,7 @@ type Telemetry struct {
const (
/* Misc. orchestrator constants */
OperatorName = "trident-operator"
operatorVersion = "20.07.0"
operatorVersion = config.DefaultOrchestratorVersion
)

var (
Expand Down
29 changes: 18 additions & 11 deletions operator/controllers/provisioner/installer/config.go
Expand Up @@ -2,10 +2,25 @@

package installer

import (
"github.com/netapp/trident/config"
)

var (
DefaultTridentVersion = config.DefaultOrchestratorVersion

DefaultTridentRepo = "netapp/trident:" // Default repo from where to pull Trident Image

// TridentImage is the image that the operator installs by default
TridentImage = DefaultTridentRepo + DefaultTridentVersion

// This gets stored in the objects created by the CR
TridentVersionLabelKey = "trident_version"
TridentVersionLabelValue = "v" + DefaultTridentVersion // need to append 'v', otherwise label freaks out
TridentVersionLabel = TridentVersionLabelKey + "=" + TridentVersionLabelValue
)

const (
MinSupportedTridentVersion = "20.04.0" // ParseDate needs this format but should be used with ToMajorMinorVersion
MaxSupportedTridentVersion = "20.07.0" // ParseDate needs this format but should be used with ToMajorMinorVersion
DefaultTridentVersion = "20.07" // This will ensure we get the latest dot release

TridentAppLabelKey = "app"

Expand All @@ -28,20 +43,12 @@ const (
// This is used to Watch and List for deployment matching Trident CSI and Legacy labels
LabelSelector = TridentAppLabelKey + " in (" + TridentCSILabelValue + ", " + TridentLegacyLabelValue + ")"

// This gets stored in the objects created by the CR
TridentVersionLabelKey = "trident_version"
TridentVersionLabelValue = "v" + DefaultTridentVersion // need to append 'v', otherwise label freaks out
TridentVersionLabel = TridentVersionLabelKey + "=" + TridentVersionLabelValue

// This is the key that stored in the objects created by the CR, value is decided based on the K8s version
K8sVersionLabelKey = "k8s_version"

ControllerServer = "127.0.0.1:8000"
TridentContainer = "trident-main"

// TridentImage is the image that the operator installs by default
TridentImage = "netapp/trident:" + DefaultTridentVersion

// DefaultImageRegistry is the address/port of an internal image registry.
DefaultImageRegistry = "quay.io"

Expand Down
25 changes: 7 additions & 18 deletions operator/controllers/provisioner/installer/installer.go
Expand Up @@ -226,30 +226,19 @@ func (i *Installer) imagePrechecks(labels, controllingCRDetails map[string]strin
return "", fmt.Errorf(errMessage)
}

minSupportedTridentVersion, err := utils.ParseDate(MinSupportedTridentVersion)
supportedTridentVersion, err := utils.ParseDate(DefaultTridentVersion)
if err != nil {
errMessage := fmt.Sprintf("unexpected parse error during minimum supported Trident version; err: %v", err)
errMessage := fmt.Sprintf("unexpected parse error during supported Trident version; err: %v", err)
log.Errorf(errMessage)
return "", fmt.Errorf(errMessage)
}

maxSupportedTridentVersion, err := utils.ParseDate(MaxSupportedTridentVersion)
if err != nil {
errMessage := fmt.Sprintf("unexpected parse error during maximum supported Trident version; err: %v", err)
log.Errorf(errMessage)
return "", fmt.Errorf(errMessage)
}

tridentImageVersionMM := tridentImageVersion.ToMajorMinorVersion()
minSupportedTridentVersionMM := minSupportedTridentVersion.ToMajorMinorVersion()
maxSupportedTridentVersionMM := maxSupportedTridentVersion.ToMajorMinorVersion()
tridentImageShortVersion := tridentImageVersion.ShortString()
supportedTridentShortVersion := supportedTridentVersion.ShortString()

if tridentImageVersionMM.LessThan(minSupportedTridentVersionMM) || tridentImageVersionMM.
GreaterThan(maxSupportedTridentVersionMM) {
errMessage := fmt.Sprintf("unsupported Trident image version '%s', "+
"minimum supported Trident version is '%s', maximum supported Trident version is '%s'",
tridentImageVersion.ShortStringWithRelease(),
minSupportedTridentVersion.ShortStringWithRelease(), maxSupportedTridentVersion.ShortStringWithRelease())
if tridentImageShortVersion != supportedTridentShortVersion {
errMessage := fmt.Sprintf("unsupported Trident image version '%s', supported Trident version is '%s'",
tridentImageVersion.ShortStringWithRelease(), supportedTridentVersion.ShortStringWithRelease())
log.Errorf(errMessage)
return "", fmt.Errorf(errMessage)
}
Expand Down

0 comments on commit da0a654

Please sign in to comment.