From 64006e41e7de1a9cdb62a45924435a8557702912 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 21 May 2020 15:18:59 -0400 Subject: [PATCH 01/30] baby steps --- operator/Dockerfile | 6 +++++- operator/cmd/manager/main.go | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/operator/Dockerfile b/operator/Dockerfile index ec6d3ac3a..a1fe9cc08 100644 --- a/operator/Dockerfile +++ b/operator/Dockerfile @@ -4,6 +4,7 @@ ########## # "builder" compiles and tests the code # This stage name is important to the Cloud Platform CI/CD infrastructure, and should be preserved +ARG BASE_OS=alpine:3.9 FROM golang:1.13-stretch as builder # Disable cgo - this makes static binaries that will work on an Alpine image @@ -45,9 +46,12 @@ RUN MO_VERSION=${VERSION_STAMP} mage operator:buildGo # Second stage # Produce a smaller image than the one used to build the code -FROM alpine:3.9 +FROM ${BASE_OS} ENV GOPATH=/go + +ARG BASE_OS="" +ENV BASE_OS=${BASE_OS} WORKDIR /go # All we need from the builder image is operator executable diff --git a/operator/cmd/manager/main.go b/operator/cmd/manager/main.go index bda0014c7..6eeb18123 100644 --- a/operator/cmd/manager/main.go +++ b/operator/cmd/manager/main.go @@ -33,6 +33,7 @@ import ( sdkVersion "github.com/operator-framework/operator-sdk/version" "github.com/spf13/pflag" v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/intstr" @@ -127,6 +128,7 @@ func main() { ctx := context.Background() // Become the leader before proceeding err = leader.Become(ctx, "cass-operator-lock") + if err != nil { log.Error(err, "could not become leader") os.Exit(1) @@ -139,6 +141,10 @@ func main() { log.Error(err, "Failed to ensure webhook CA configuration") } + if err = ensureBaseOsConfigMap(cfg, namespace); err != nil { + log.Error(err, "Failed to ensure base os configmap") + } + // Set default manager options options := manager.Options{ Namespace: namespace, @@ -207,6 +213,38 @@ func main() { } } +func ensureBaseOsConfigMap(cfg *rest.Config, ns string) error { + name := "base-os-config" + + client, err := crclient.New(cfg, crclient.Options{}) + if err != nil { + return err + } + + var existing *v1.ConfigMap + key := crclient.ObjectKey{Namespace: ns, Name: name} + err = client.Get(context.Background(), key, existing) + if err == nil && existing != nil { + // config map already exists + return nil + } + + baseOs := os.Getenv("BASE_OS") + cm := &v1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: ns, + }, + Data: map[string]string{"BASE_OS": baseOs}, + } + err = client.Create(context.Background(), cm) + if err != nil { + return err + } + + return nil +} + // addMetrics will create the Services and Service Monitors to allow the operator export the metrics by using // the Prometheus operator func addMetrics(ctx context.Context, cfg *rest.Config) { From 153c8f31dc5257e19e048084221fa94bbb33293e Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 21 May 2020 16:52:25 -0400 Subject: [PATCH 02/30] build out some more steps --- .../templates/deployment.yaml | 5 ++ operator/cmd/manager/main.go | 2 +- .../v1beta1/cassandradatacenter_types.go | 49 ++++++++++++++----- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/charts/cass-operator-chart/templates/deployment.yaml b/charts/cass-operator-chart/templates/deployment.yaml index 904422aed..28ef004b2 100644 --- a/charts/cass-operator-chart/templates/deployment.yaml +++ b/charts/cass-operator-chart/templates/deployment.yaml @@ -67,3 +67,8 @@ spec: value: "cass-operator" - name: SKIP_VALIDATING_WEBHOOK value: "FALSE" + - name: BASE_IMAGE_OS + valueFrom: + configMapKeyRef: + name: base-image-os + key: BASE_OS diff --git a/operator/cmd/manager/main.go b/operator/cmd/manager/main.go index 6eeb18123..9e5cba787 100644 --- a/operator/cmd/manager/main.go +++ b/operator/cmd/manager/main.go @@ -214,7 +214,7 @@ func main() { } func ensureBaseOsConfigMap(cfg *rest.Config, ns string) error { - name := "base-os-config" + name := "base-image-os-config" client, err := crclient.New(cfg, crclient.Options{}) if err != nil { diff --git a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go index e9bf31bc7..15229416e 100644 --- a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -6,6 +6,7 @@ package v1beta1 import ( "encoding/json" "fmt" + "os" "github.com/Jeffail/gabs" "github.com/pkg/errors" @@ -46,25 +47,51 @@ const ( // This type exists so there's no chance of pushing random strings to our progress status type ProgressState string +const ( + cassandra_3_11_6 = "datastax/cassandra-mgmtapi-3_11_6:v0.1.2" + cassandra_4_0_0 = "datastax/cassandra-mgmtapi-4_0_0:v0.1.2" + dse_6_8_0 = "datastax/dse-server:6.8.0" + envBaseImageOs = "BASE_IMAGE_OS" +) + // getImageForServerVersion tries to look up a known image for a server type and version number. // In the event that no image is found, an error is returned func getImageForServerVersion(server, version string) (string, error) { - const ( - cassandra_3_11_6 = "datastax/cassandra-mgmtapi-3_11_6:v0.1.2" - cassandra_4_0_0 = "datastax/cassandra-mgmtapi-4_0_0:v0.1.2" - dse_6_8_0 = "datastax/dse-server:6.8.0" - ) - sv := server + "-" + version + baseImageOs := os.Getenv(envBaseImageOs) + + var imageCalc func(string) (string, bool) + var img string + var success bool + + switch baseImageOs { + case "": + imageCalc = getImageForDefaultBaseOs + case "universal-base-image": + imageCalc = getImageForUniversalBaseOs + } + + img, success = imageCalc(server + "-" + version) + if !success { + return "", fmt.Errorf("server '%s' and version '%s' do not work together", server, version) + } + + return img, nil +} + +func getImageForDefaultBaseOs(sv string) (string, bool) { switch sv { case "dse-6.8.0": - return dse_6_8_0, nil + return dse_6_8_0, true case "cassandra-3.11.6": - return cassandra_3_11_6, nil + return cassandra_3_11_6, true case "cassandra-4.0.0": - return cassandra_4_0_0, nil + return cassandra_4_0_0, true } - err := fmt.Errorf("server '%s' and version '%s' do not work together", server, version) - return "", err + return "", false +} + +func getImageForUniversalBaseOs(sv string) (string, bool) { + panic("TODO: Need universal basic image coords") } // CassandraDatacenterSpec defines the desired state of a CassandraDatacenter From 34922cbe13eeed5d1c8507b7dba9263512c152c9 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Tue, 26 May 2020 12:02:37 -0400 Subject: [PATCH 03/30] write file with base os --- .../templates/deployment.yaml | 5 --- mage/operator/lib.go | 41 ++++++++++++++----- operator/Dockerfile | 3 +- operator/cmd/manager/main.go | 41 +++++++++---------- .../v1beta1/cassandradatacenter_types.go | 6 +-- 5 files changed, 55 insertions(+), 41 deletions(-) diff --git a/charts/cass-operator-chart/templates/deployment.yaml b/charts/cass-operator-chart/templates/deployment.yaml index 28ef004b2..904422aed 100644 --- a/charts/cass-operator-chart/templates/deployment.yaml +++ b/charts/cass-operator-chart/templates/deployment.yaml @@ -67,8 +67,3 @@ spec: value: "cass-operator" - name: SKIP_VALIDATING_WEBHOOK value: "FALSE" - - name: BASE_IMAGE_OS - valueFrom: - configMapKeyRef: - name: base-image-os - key: BASE_OS diff --git a/mage/operator/lib.go b/mage/operator/lib.go index 7b60e2af8..49ba77450 100644 --- a/mage/operator/lib.go +++ b/mage/operator/lib.go @@ -36,6 +36,7 @@ const ( envGitBranch = "MO_BRANCH" envVersionString = "MO_VERSION" envGitHash = "MO_HASH" + envBaseOs = "MO_BASE_OS" errorUnstagedPreGenerate = ` Unstaged changes detected. @@ -345,17 +346,35 @@ func calcFullVersion(settings cfgutil.BuildSettings, git GitData) FullVersion { } } -func runDockerBuild(version FullVersion) []string { +func calcVersionAndTags(version FullVersion) (string, []string) { repoPath := "datastax/cass-operator" - versionedTag := fmt.Sprintf("%s:%v", repoPath, version) - tagsToPush := []string{ - versionedTag, - fmt.Sprintf("%s:%s", repoPath, version.Hash), + var versionedTag string + var tagsToPush []string + + if baseOs := os.Getenv(envBaseOs); baseOs != "" { + versionedTag := fmt.Sprintf("%s:%v-ubi", repoPath, version) + tagsToPush = []string{ + versionedTag, + fmt.Sprintf("%s:%s-ubi", repoPath, version.Hash), + fmt.Sprintf("%s:latest-ubi", repoPath), + } + } else { + versionedTag := fmt.Sprintf("%s:%v", repoPath, version) + tagsToPush = []string{ + versionedTag, + fmt.Sprintf("%s:%s", repoPath, version.Hash), + fmt.Sprintf("%s:latest", repoPath), + } } - tags := append(tagsToPush, fmt.Sprintf("%s:latest", repoPath)) + return versionedTag, tagsToPush +} + +func runDockerBuild(versionedTag string, dockerTags []string) { buildArgs := []string{fmt.Sprintf("VERSION_STAMP=%s", versionedTag)} - dockerutil.Build(".", "", "./operator/Dockerfile", tags, buildArgs).ExecVPanic() - return tagsToPush + if baseOs := os.Getenv(envBaseOs); baseOs != "" { + buildArgs = append(buildArgs, fmt.Sprintf("BASE_OS=%s", baseOs)) + } + dockerutil.Build(".", "", "./operator/Dockerfile", dockerTags, buildArgs).ExecVPanic() } func runGoBuild(version string) { @@ -419,12 +438,14 @@ func BuildDocker() { settings := cfgutil.ReadBuildSettings() git := getGitData() version := calcFullVersion(settings, git) - operatorTags := runDockerBuild(version) + + versionedTag, dockerTags := calcVersionAndTags(version) + runDockerBuild(versionedTag, dockerTags) // Write the versioned image tags to a file in our build // directory so that other targets in the build process can identify // what was built. This is particularly important to know // for targets that retag and deploy to external docker repositories - outputText := strings.Join(operatorTags, "|") + outputText := strings.Join(dockerTags, "|") writeBuildFile("tagsToPush.txt", outputText) } diff --git a/operator/Dockerfile b/operator/Dockerfile index a1fe9cc08..a32c94438 100644 --- a/operator/Dockerfile +++ b/operator/Dockerfile @@ -51,7 +51,8 @@ FROM ${BASE_OS} ENV GOPATH=/go ARG BASE_OS="" -ENV BASE_OS=${BASE_OS} +RUN mkdir -p /var/lib/cass-operator/ +RUN echo ${BASE_OS} > /var/lib/cass-operator/base_os WORKDIR /go # All we need from the builder image is operator executable diff --git a/operator/cmd/manager/main.go b/operator/cmd/manager/main.go index 9e5cba787..dc15d9cac 100644 --- a/operator/cmd/manager/main.go +++ b/operator/cmd/manager/main.go @@ -33,7 +33,6 @@ import ( sdkVersion "github.com/operator-framework/operator-sdk/version" "github.com/spf13/pflag" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/intstr" @@ -141,8 +140,8 @@ func main() { log.Error(err, "Failed to ensure webhook CA configuration") } - if err = ensureBaseOsConfigMap(cfg, namespace); err != nil { - log.Error(err, "Failed to ensure base os configmap") + if err = readBaseOsIntoEnv(); err != nil { + log.Error(err, "Failed to read base OS into env") } // Set default manager options @@ -213,35 +212,33 @@ func main() { } } -func ensureBaseOsConfigMap(cfg *rest.Config, ns string) error { - name := "base-image-os-config" +func readBaseOsIntoEnv() error { + baseOsArgFilePath := "/var/lib/cass-operator/base_os" - client, err := crclient.New(cfg, crclient.Options{}) - if err != nil { + info, err := os.Stat(baseOsArgFilePath) + if os.IsNotExist(err) { + msg := fmt.Sprintf("Could not locate base OS arg file at %s", baseOsArgFilePath) + err = fmt.Errorf("%s. %v", msg, err) return err } - var existing *v1.ConfigMap - key := crclient.ObjectKey{Namespace: ns, Name: name} - err = client.Get(context.Background(), key, existing) - if err == nil && existing != nil { - // config map already exists - return nil + if info.IsDir() { + msg := fmt.Sprintf("Base OS arg path is a directory not a file: %s", baseOsArgFilePath) + err = fmt.Errorf("%s. %v", msg, err) + return err } - baseOs := os.Getenv("BASE_OS") - cm := &v1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: ns, - }, - Data: map[string]string{"BASE_OS": baseOs}, - } - err = client.Create(context.Background(), cm) + rawVal, err := ioutil.ReadFile(baseOsArgFilePath) if err != nil { + msg := fmt.Sprintf("Failed to read base OS arg file at %s", baseOsArgFilePath) + err = fmt.Errorf("%s. %v", msg, err) return err } + baseOs := strings.TrimSpace(string(rawVal)) + os.Setenv("BASE_IMAGE_OS", baseOs) + log.Info(fmt.Sprintf("BASE_IMAGE_OS set to '%s'", baseOs)) + return nil } diff --git a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go index 15229416e..47cd0904c 100644 --- a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -63,10 +63,10 @@ func getImageForServerVersion(server, version string) (string, error) { var img string var success bool - switch baseImageOs { - case "": + if baseImageOs == "" { imageCalc = getImageForDefaultBaseOs - case "universal-base-image": + } else { + imageCalc = getImageForUniversalBaseOs } From d56217488cedd7b1c10ed4c4b36a5248d37ab045 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Tue, 26 May 2020 14:29:47 -0400 Subject: [PATCH 04/30] add logic to select ubi image in mage targets --- mage/k8s/lib.go | 16 ++++++++++++++-- mage/operator/lib.go | 10 +++++----- operator/Dockerfile | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/mage/k8s/lib.go b/mage/k8s/lib.go index e2d5e6ea5..90b84d70b 100644 --- a/mage/k8s/lib.go +++ b/mage/k8s/lib.go @@ -25,6 +25,7 @@ import ( const ( OperatorImage = "datastax/cass-operator:latest" + OperatorImageUBI = "datastax/cass-operator:latest-ubi" envLoadDevImages = "M_LOAD_DEV_IMAGES" envK8sFlavor = "M_K8S_FLAVOR" ) @@ -38,6 +39,16 @@ var supportedFlavors = map[string]ClusterActions{ "gke": gcp.ClusterActions, } +func getOperatorImage() string { + var img string + if baseOs := os.Getenv(operator.EnvBaseOs); baseOs != "" { + img = "datastax/cass-operator:latest-ubi" + } else { + img = "datastax/cass-operator:latest" + } + return img +} + func loadImagesFromBuildSettings(cfg ClusterActions, settings BuildSettings) { for _, image := range settings.Dev.Images { shutil.RunVPanic("docker", "pull", image) @@ -96,7 +107,8 @@ func SetupEmptyCluster() { clusterActions.ApplyDefaultStorage() //TODO make this part optional operator.BuildDocker() - clusterActions.LoadImage(OperatorImage) + operatorImg := getOperatorImage() + clusterActions.LoadImage(operatorImg) } // Bootstrap a cluster, then run Ginkgo integration tests. @@ -131,8 +143,8 @@ func SetupExampleCluster() { mg.Deps(SetupEmptyCluster) kubectl.CreateSecretLiteral("cassandra-superuser-secret", "devuser", "devpass").ExecVPanic() + overrides := map[string]string{"image": getOperatorImage()} var namespace = "default" - var overrides = map[string]string{"image": "datastax/cass-operator:latest"} err := helm_util.Install("./charts/cass-operator-chart", "cass-operator", namespace, overrides) mageutil.PanicOnError(err) diff --git a/mage/operator/lib.go b/mage/operator/lib.go index 49ba77450..c36444ed5 100644 --- a/mage/operator/lib.go +++ b/mage/operator/lib.go @@ -36,7 +36,7 @@ const ( envGitBranch = "MO_BRANCH" envVersionString = "MO_VERSION" envGitHash = "MO_HASH" - envBaseOs = "MO_BASE_OS" + EnvBaseOs = "MO_BASE_OS" errorUnstagedPreGenerate = ` Unstaged changes detected. @@ -351,15 +351,15 @@ func calcVersionAndTags(version FullVersion) (string, []string) { var versionedTag string var tagsToPush []string - if baseOs := os.Getenv(envBaseOs); baseOs != "" { - versionedTag := fmt.Sprintf("%s:%v-ubi", repoPath, version) + if baseOs := os.Getenv(EnvBaseOs); baseOs != "" { + versionedTag = fmt.Sprintf("%s:%v-ubi", repoPath, version) tagsToPush = []string{ versionedTag, fmt.Sprintf("%s:%s-ubi", repoPath, version.Hash), fmt.Sprintf("%s:latest-ubi", repoPath), } } else { - versionedTag := fmt.Sprintf("%s:%v", repoPath, version) + versionedTag = fmt.Sprintf("%s:%v", repoPath, version) tagsToPush = []string{ versionedTag, fmt.Sprintf("%s:%s", repoPath, version.Hash), @@ -371,7 +371,7 @@ func calcVersionAndTags(version FullVersion) (string, []string) { func runDockerBuild(versionedTag string, dockerTags []string) { buildArgs := []string{fmt.Sprintf("VERSION_STAMP=%s", versionedTag)} - if baseOs := os.Getenv(envBaseOs); baseOs != "" { + if baseOs := os.Getenv(EnvBaseOs); baseOs != "" { buildArgs = append(buildArgs, fmt.Sprintf("BASE_OS=%s", baseOs)) } dockerutil.Build(".", "", "./operator/Dockerfile", dockerTags, buildArgs).ExecVPanic() diff --git a/operator/Dockerfile b/operator/Dockerfile index a32c94438..ffdceef0c 100644 --- a/operator/Dockerfile +++ b/operator/Dockerfile @@ -52,7 +52,7 @@ ENV GOPATH=/go ARG BASE_OS="" RUN mkdir -p /var/lib/cass-operator/ -RUN echo ${BASE_OS} > /var/lib/cass-operator/base_os +RUN echo "${BASE_OS}" > /var/lib/cass-operator/base_os WORKDIR /go # All we need from the builder image is operator executable From c7a975786e23b309b73f1e9f387d358fb911c3b1 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Wed, 27 May 2020 10:50:47 -0400 Subject: [PATCH 05/30] use ubi instead of busybox when necessary for logging container; build/publish ubi images from gh workflow --- .../workflows/operatorPRBuildAndDeploy.yml | 33 ++++++++++++++-- .../operatorStableBuildAndDeploy.yml | 39 +++++++++++++++++-- .../v1beta1/cassandradatacenter_types.go | 4 +- operator/pkg/reconciliation/constructor.go | 11 ++++-- 4 files changed, 75 insertions(+), 12 deletions(-) diff --git a/.github/workflows/operatorPRBuildAndDeploy.yml b/.github/workflows/operatorPRBuildAndDeploy.yml index ef840991b..b7d0b2ee0 100644 --- a/.github/workflows/operatorPRBuildAndDeploy.yml +++ b/.github/workflows/operatorPRBuildAndDeploy.yml @@ -31,13 +31,13 @@ jobs: run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testGenerateClient - - name: Build docker + - name: Build docker - standard image env: MO_BRANCH: ${{ github.event.pull_request.head.ref }} run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - - name: Deploy to ECR + - name: Deploy to ECR - standard image if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' env: MO_ECR_ID: ${{ secrets.ECR_ID }} @@ -47,7 +47,34 @@ jobs: export PATH=$GOROOT/bin:$GOPATH/bin:$PATH export MO_TAGS=$(cat ./build/tagsToPush.txt) mage operator:deployToECR - - name: Deploy to GH Packages + - name: Deploy to GH Packages - standard image + if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' + env: + MO_GH_USR: 'datastax/cass-operator' + MO_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MO_GH_PKG_REPO: 'datastax/cass-operator/operator' + run: | + export PATH=$GOROOT/bin:$GOPATH/bin:$PATH + export MO_TAGS=$(cat ./build/tagsToPush.txt) + mage operator:deployToGHPackages + - name: Build docker - ubi image + env: + MO_BRANCH: ${{ github.event.pull_request.head.ref }} + MO_BASE_OS: 'registry.access.redhat.com/ubi7/ubi-minimal:7.8' + run: | + export PATH=$GOROOT/bin:$GOPATH/bin:$PATH + mage operator:testAndBuild + - name: Deploy to ECR - ubi image + if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' + env: + MO_ECR_ID: ${{ secrets.ECR_ID }} + MO_ECR_SECRET: ${{ secrets.ECR_SECRET }} + MO_ECR_REPO: ${{ secrets.ECR_REPO }} + run: | + export PATH=$GOROOT/bin:$GOPATH/bin:$PATH + export MO_TAGS=$(cat ./build/tagsToPush.txt) + mage operator:deployToECR + - name: Deploy to GH Packages - ubi image if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' env: MO_GH_USR: 'datastax/cass-operator' diff --git a/.github/workflows/operatorStableBuildAndDeploy.yml b/.github/workflows/operatorStableBuildAndDeploy.yml index ad14229f4..4c53e9fb1 100644 --- a/.github/workflows/operatorStableBuildAndDeploy.yml +++ b/.github/workflows/operatorStableBuildAndDeploy.yml @@ -32,12 +32,42 @@ jobs: run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testGenerateClient - - name: Build docker + - name: Build docker - standard image + env: + MO_BRANCH: ${{ github.event.pull_request.head.ref }} + run: | + export PATH=$GOROOT/bin:$GOPATH/bin:$PATH + mage operator:testAndBuild + - name: Deploy to ECR - standard image + if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' + env: + MO_ECR_ID: ${{ secrets.ECR_ID }} + MO_ECR_SECRET: ${{ secrets.ECR_SECRET }} + MO_ECR_REPO: ${{ secrets.ECR_REPO }} + run: | + export PATH=$GOROOT/bin:$GOPATH/bin:$PATH + export MO_TAGS=$(cat ./build/tagsToPush.txt) + mage operator:deployToECR + - name: Deploy to GH Packages - standard image + if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' + env: + MO_GH_USR: 'datastax/cass-operator' + MO_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MO_GH_PKG_REPO: 'datastax/cass-operator/operator' + run: | + export PATH=$GOROOT/bin:$GOPATH/bin:$PATH + export MO_TAGS=$(cat ./build/tagsToPush.txt) + mage operator:deployToGHPackages + - name: Build docker - ubi image + env: + MO_BRANCH: ${{ github.event.pull_request.head.ref }} + MO_BASE_OS: 'registry.access.redhat.com/ubi7/ubi-minimal:7.8' run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - - name: Deploy to ECR - env: + - name: Deploy to ECR - ubi image + if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' + env: MO_ECR_ID: ${{ secrets.ECR_ID }} MO_ECR_SECRET: ${{ secrets.ECR_SECRET }} MO_ECR_REPO: ${{ secrets.ECR_REPO }} @@ -45,7 +75,8 @@ jobs: export PATH=$GOROOT/bin:$GOPATH/bin:$PATH export MO_TAGS=$(cat ./build/tagsToPush.txt) mage operator:deployToECR - - name: Deploy to GH Packages + - name: Deploy to GH Packages - ubi image + if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' env: MO_GH_USR: 'datastax/cass-operator' MO_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go index 47cd0904c..9dc9ca622 100644 --- a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -51,13 +51,13 @@ const ( cassandra_3_11_6 = "datastax/cassandra-mgmtapi-3_11_6:v0.1.2" cassandra_4_0_0 = "datastax/cassandra-mgmtapi-4_0_0:v0.1.2" dse_6_8_0 = "datastax/dse-server:6.8.0" - envBaseImageOs = "BASE_IMAGE_OS" + EnvBaseImageOs = "BASE_IMAGE_OS" ) // getImageForServerVersion tries to look up a known image for a server type and version number. // In the event that no image is found, an error is returned func getImageForServerVersion(server, version string) (string, error) { - baseImageOs := os.Getenv(envBaseImageOs) + baseImageOs := os.Getenv(EnvBaseImageOs) var imageCalc func(string) (string, bool) var img string diff --git a/operator/pkg/reconciliation/constructor.go b/operator/pkg/reconciliation/constructor.go index 3c91e9e1a..6f99388f6 100644 --- a/operator/pkg/reconciliation/constructor.go +++ b/operator/pkg/reconciliation/constructor.go @@ -7,6 +7,7 @@ package reconciliation import ( "fmt" + "os" api "github.com/datastax/cass-operator/operator/pkg/apis/cassandra/v1beta1" "github.com/datastax/cass-operator/operator/pkg/httphelper" @@ -121,7 +122,7 @@ func newStatefulSetForCassandraDatacenterWithDefunctPvcManagedBy( rackName string, dc *api.CassandraDatacenter, replicaCount int) (*appsv1.StatefulSet, error) { - + return newStatefulSetForCassandraDatacenterHelper(rackName, dc, replicaCount, true) } @@ -132,7 +133,7 @@ func usesDefunctPvcManagedByLabel(sts *appsv1.StatefulSet) bool { if ok && value == oplabels.ManagedByLabelDefunctValue { usesDefunct = true break - } + } } return usesDefunct @@ -404,7 +405,11 @@ func buildContainers(dc *api.CassandraDatacenter, serverVolumeMounts []corev1.Vo // server logger container loggerContainer := corev1.Container{} loggerContainer.Name = "server-system-logger" - loggerContainer.Image = "busybox" + if baseImageOs := os.Getenv(api.EnvBaseImageOs); baseImageOs != "" { + loggerContainer.Image = baseImageOs + } else { + loggerContainer.Image = "busybox" + } loggerContainer.Args = []string{ "/bin/sh", "-c", "tail -n+1 -F /var/log/cassandra/system.log", } From 6db60cf07c59d39321936042d5323e68c2d84a1b Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Wed, 27 May 2020 13:00:52 -0400 Subject: [PATCH 06/30] unify gh workflows and simplify steps --- ...dDeploy.yml => operatorBuildAndDeploy.yml} | 42 +++------ .../operatorStableBuildAndDeploy.yml | 87 ------------------- mage/operator/lib.go | 2 +- 3 files changed, 15 insertions(+), 116 deletions(-) rename .github/workflows/{operatorPRBuildAndDeploy.yml => operatorBuildAndDeploy.yml} (61%) delete mode 100644 .github/workflows/operatorStableBuildAndDeploy.yml diff --git a/.github/workflows/operatorPRBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml similarity index 61% rename from .github/workflows/operatorPRBuildAndDeploy.yml rename to .github/workflows/operatorBuildAndDeploy.yml index b7d0b2ee0..99255af2b 100644 --- a/.github/workflows/operatorPRBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -1,5 +1,9 @@ name: Cass Operator Build & Deploy -on: pull_request +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] jobs: build_operator_docker: name: Build Cass Operator Docker Image @@ -9,8 +13,6 @@ jobs: GOROOT: /usr/local/go1.13 steps: - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - name: Set up Go 1.13 uses: actions/setup-go@v1 with: @@ -37,26 +39,8 @@ jobs: run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - - name: Deploy to ECR - standard image - if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' - env: - MO_ECR_ID: ${{ secrets.ECR_ID }} - MO_ECR_SECRET: ${{ secrets.ECR_SECRET }} - MO_ECR_REPO: ${{ secrets.ECR_REPO }} - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - export MO_TAGS=$(cat ./build/tagsToPush.txt) - mage operator:deployToECR - - name: Deploy to GH Packages - standard image - if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' - env: - MO_GH_USR: 'datastax/cass-operator' - MO_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MO_GH_PKG_REPO: 'datastax/cass-operator/operator' - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - export MO_TAGS=$(cat ./build/tagsToPush.txt) - mage operator:deployToGHPackages + cat ./build/tagsToPush.txt > ./build/fullTagsToPush.txt + echo "|" >> ./build/tagsToPush.txt - name: Build docker - ubi image env: MO_BRANCH: ${{ github.event.pull_request.head.ref }} @@ -64,8 +48,9 @@ jobs: run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - - name: Deploy to ECR - ubi image - if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' + cat ./build/tagsToPush.txt >> ./build/fullTagsToPush.txt + - name: Deploy to ECR + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' env: MO_ECR_ID: ${{ secrets.ECR_ID }} MO_ECR_SECRET: ${{ secrets.ECR_SECRET }} @@ -74,13 +59,14 @@ jobs: export PATH=$GOROOT/bin:$GOPATH/bin:$PATH export MO_TAGS=$(cat ./build/tagsToPush.txt) mage operator:deployToECR - - name: Deploy to GH Packages - ubi image - if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' + - name: Deploy to GH Packages + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' + env: env: MO_GH_USR: 'datastax/cass-operator' MO_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} MO_GH_PKG_REPO: 'datastax/cass-operator/operator' run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - export MO_TAGS=$(cat ./build/tagsToPush.txt) + export MO_TAGS=$(cat ./build/fullTagsToPush.txt) mage operator:deployToGHPackages diff --git a/.github/workflows/operatorStableBuildAndDeploy.yml b/.github/workflows/operatorStableBuildAndDeploy.yml deleted file mode 100644 index 4c53e9fb1..000000000 --- a/.github/workflows/operatorStableBuildAndDeploy.yml +++ /dev/null @@ -1,87 +0,0 @@ -name: Cass Operator Stable Build & Deploy -on: - push: - branches: - - master -jobs: - build_operator_docker: - name: Build Cass Operator Docker Image - runs-on: ubuntu-latest - env: - GOPATH: /home/runner/go - GOROOT: /usr/local/go1.13 - steps: - - uses: actions/checkout@v2 - - name: Set up Go 1.13 - uses: actions/setup-go@v1 - with: - go-version: 1.13 - - name: Install Mage - run: | - cd /tmp - wget https://github.com/magefile/mage/releases/download/v1.9.0/mage_1.9.0_Linux-64bit.tar.gz - tar -xvf mage_1.9.0_Linux-64bit.tar.gz - mkdir -p $GOPATH/bin - mv mage $GOPATH/bin/mage - sudo chmod +x $GOPATH/bin/mage - - name: Test Sdk Generate - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - mage operator:testSdkGenerate - - name: Test Client Generate - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - mage operator:testGenerateClient - - name: Build docker - standard image - env: - MO_BRANCH: ${{ github.event.pull_request.head.ref }} - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - mage operator:testAndBuild - - name: Deploy to ECR - standard image - if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' - env: - MO_ECR_ID: ${{ secrets.ECR_ID }} - MO_ECR_SECRET: ${{ secrets.ECR_SECRET }} - MO_ECR_REPO: ${{ secrets.ECR_REPO }} - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - export MO_TAGS=$(cat ./build/tagsToPush.txt) - mage operator:deployToECR - - name: Deploy to GH Packages - standard image - if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' - env: - MO_GH_USR: 'datastax/cass-operator' - MO_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MO_GH_PKG_REPO: 'datastax/cass-operator/operator' - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - export MO_TAGS=$(cat ./build/tagsToPush.txt) - mage operator:deployToGHPackages - - name: Build docker - ubi image - env: - MO_BRANCH: ${{ github.event.pull_request.head.ref }} - MO_BASE_OS: 'registry.access.redhat.com/ubi7/ubi-minimal:7.8' - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - mage operator:testAndBuild - - name: Deploy to ECR - ubi image - if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' - env: - MO_ECR_ID: ${{ secrets.ECR_ID }} - MO_ECR_SECRET: ${{ secrets.ECR_SECRET }} - MO_ECR_REPO: ${{ secrets.ECR_REPO }} - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - export MO_TAGS=$(cat ./build/tagsToPush.txt) - mage operator:deployToECR - - name: Deploy to GH Packages - ubi image - if: github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' - env: - MO_GH_USR: 'datastax/cass-operator' - MO_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MO_GH_PKG_REPO: 'datastax/cass-operator/operator' - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - export MO_TAGS=$(cat ./build/tagsToPush.txt) - mage operator:deployToGHPackages diff --git a/mage/operator/lib.go b/mage/operator/lib.go index c36444ed5..8ef9229af 100644 --- a/mage/operator/lib.go +++ b/mage/operator/lib.go @@ -74,7 +74,7 @@ func checkForUnstagedChanges(message string) { func writeBuildFile(fileName string, contents string) { mageutil.EnsureDir(rootBuildDir) outputPath := filepath.Join(rootBuildDir, fileName) - err := ioutil.WriteFile(outputPath, []byte(contents+"\n"), 0666) + err := ioutil.WriteFile(outputPath, []byte(contents), 0666) if err != nil { fmt.Printf("Failed to write file at %s\n", outputPath) panic(err) From a7da497419edd97b3ebf2cf652da1394af433aaf Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Wed, 27 May 2020 13:01:27 -0400 Subject: [PATCH 07/30] fixup! unify gh workflows and simplify steps --- .github/workflows/operatorBuildAndDeploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 99255af2b..18e56e0f0 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -57,7 +57,7 @@ jobs: MO_ECR_REPO: ${{ secrets.ECR_REPO }} run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - export MO_TAGS=$(cat ./build/tagsToPush.txt) + export MO_TAGS=$(cat ./build/fullTagsToPush.txt) mage operator:deployToECR - name: Deploy to GH Packages if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' From 8aac13d44e048b97171c32d6fcf538eb2961df6b Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Wed, 27 May 2020 13:04:07 -0400 Subject: [PATCH 08/30] fixup! fixup! unify gh workflows and simplify steps --- .github/workflows/operatorBuildAndDeploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 18e56e0f0..322fee8ac 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -61,7 +61,6 @@ jobs: mage operator:deployToECR - name: Deploy to GH Packages if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' - env: env: MO_GH_USR: 'datastax/cass-operator' MO_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From bb6dc8a8ca017a8569ae33855dc6a4f77db97cec Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Wed, 27 May 2020 13:21:26 -0400 Subject: [PATCH 09/30] add debug print --- .github/workflows/operatorBuildAndDeploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 322fee8ac..6bfb41d52 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -58,6 +58,8 @@ jobs: run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH export MO_TAGS=$(cat ./build/fullTagsToPush.txt) + echo "Full tags:" + cat ./build/fullTagsToPush.txt mage operator:deployToECR - name: Deploy to GH Packages if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' From c7f6fd4de010f1e4df4f08cbb65857830f3f9fae Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Wed, 27 May 2020 13:38:01 -0400 Subject: [PATCH 10/30] fixup workflow tags to push --- .github/workflows/operatorBuildAndDeploy.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 6bfb41d52..528ba1428 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -40,7 +40,7 @@ jobs: export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild cat ./build/tagsToPush.txt > ./build/fullTagsToPush.txt - echo "|" >> ./build/tagsToPush.txt + echo "|" >> ./build/fullTagsToPush.txt - name: Build docker - ubi image env: MO_BRANCH: ${{ github.event.pull_request.head.ref }} @@ -58,8 +58,6 @@ jobs: run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH export MO_TAGS=$(cat ./build/fullTagsToPush.txt) - echo "Full tags:" - cat ./build/fullTagsToPush.txt mage operator:deployToECR - name: Deploy to GH Packages if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' From 55e0cff449071a9762219776cf496d62e9a4f7de Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Wed, 27 May 2020 13:58:27 -0400 Subject: [PATCH 11/30] trimspace on gh package tags --- mage/operator/deploy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mage/operator/deploy.go b/mage/operator/deploy.go index d7c2ba003..3a809a360 100644 --- a/mage/operator/deploy.go +++ b/mage/operator/deploy.go @@ -59,7 +59,7 @@ func retagAndPushForGH(tags []string) { pkgRepo := mageutil.RequireEnv(envGHPackageRepo) reg := regexp.MustCompile(`.*\:`) for _, tag := range tags { - updatedTag := reg.ReplaceAllString(tag, fmt.Sprintf("%s:", pkgRepo)) + updatedTag := reg.ReplaceAllString(strings.TrimSpace(tag), fmt.Sprintf("%s:", pkgRepo)) fullGHTag := fmt.Sprintf("%s/%s", ghPackagesRegistry, updatedTag) dockerTag(tag, fullGHTag) fmt.Printf("- Pushing image %s\n", fullGHTag) From 6236cd7c0c9b40249649b365f392c902168e5ba9 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Wed, 27 May 2020 14:35:37 -0400 Subject: [PATCH 12/30] fixup! trimspace on gh package tags --- mage/operator/deploy.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mage/operator/deploy.go b/mage/operator/deploy.go index 3a809a360..bafc565f9 100644 --- a/mage/operator/deploy.go +++ b/mage/operator/deploy.go @@ -59,8 +59,8 @@ func retagAndPushForGH(tags []string) { pkgRepo := mageutil.RequireEnv(envGHPackageRepo) reg := regexp.MustCompile(`.*\:`) for _, tag := range tags { - updatedTag := reg.ReplaceAllString(strings.TrimSpace(tag), fmt.Sprintf("%s:", pkgRepo)) - fullGHTag := fmt.Sprintf("%s/%s", ghPackagesRegistry, updatedTag) + updatedTag := reg.ReplaceAllString(tag, fmt.Sprintf("%s:", pkgRepo)) + fullGHTag := fmt.Sprintf("%s/%s", ghPackagesRegistry, strings.TrimSpace(updatedTag)) dockerTag(tag, fullGHTag) fmt.Printf("- Pushing image %s\n", fullGHTag) dockerutil.Push(fullGHTag).WithCfg(rootBuildDir).ExecVPanic() From c4e62952d15022be9a521adad55e2fde2a87302d Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Wed, 27 May 2020 14:50:25 -0400 Subject: [PATCH 13/30] more trimspace --- mage/operator/deploy.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mage/operator/deploy.go b/mage/operator/deploy.go index bafc565f9..c57a850b3 100644 --- a/mage/operator/deploy.go +++ b/mage/operator/deploy.go @@ -58,7 +58,8 @@ func retagAndPush(tags []string, remoteUrl string) { func retagAndPushForGH(tags []string) { pkgRepo := mageutil.RequireEnv(envGHPackageRepo) reg := regexp.MustCompile(`.*\:`) - for _, tag := range tags { + for _, t := range tags { + tag := strings.TrimSpace(t) updatedTag := reg.ReplaceAllString(tag, fmt.Sprintf("%s:", pkgRepo)) fullGHTag := fmt.Sprintf("%s/%s", ghPackagesRegistry, strings.TrimSpace(updatedTag)) dockerTag(tag, fullGHTag) From b75fb4610aa6c7dacede0bd46a7bc397c16cef23 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Fri, 29 May 2020 10:37:20 -0400 Subject: [PATCH 14/30] add in logic for choosing ubi based config builder image --- mage/k8s/lib.go | 4 ++- .../v1beta1/cassandradatacenter_types.go | 31 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/mage/k8s/lib.go b/mage/k8s/lib.go index 90b84d70b..8bb44e525 100644 --- a/mage/k8s/lib.go +++ b/mage/k8s/lib.go @@ -51,7 +51,9 @@ func getOperatorImage() string { func loadImagesFromBuildSettings(cfg ClusterActions, settings BuildSettings) { for _, image := range settings.Dev.Images { - shutil.RunVPanic("docker", "pull", image) + // we likely don't always care if we fail to pull + // because we could be testing local images + _ = shutil.RunV("docker", "pull", image) cfg.LoadImage(image) } } diff --git a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go index 9dc9ca622..e48fb7ec1 100644 --- a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -62,17 +62,19 @@ func getImageForServerVersion(server, version string) (string, error) { var imageCalc func(string) (string, bool) var img string var success bool + var errMsg string if baseImageOs == "" { imageCalc = getImageForDefaultBaseOs + errMsg = fmt.Sprintf("server '%s' and version '%s' do not work together", server, version) } else { - + errMsg = fmt.Sprintf("server '%s' and version '%s', along with the specified base OS '%s', do not work together", server, version, baseImageOs) imageCalc = getImageForUniversalBaseOs } img, success = imageCalc(server + "-" + version) if !success { - return "", fmt.Errorf("server '%s' and version '%s' do not work together", server, version) + return "", fmt.Errorf(errMsg) } return img, nil @@ -91,7 +93,18 @@ func getImageForDefaultBaseOs(sv string) (string, bool) { } func getImageForUniversalBaseOs(sv string) (string, bool) { - panic("TODO: Need universal basic image coords") + switch sv { + case "dse-6.8.0": + //TODO need ubi coords + return "", false + case "cassandra-3.11.6": + //TODO need ubi coords + return "", false + case "cassandra-4.0.0": + //TODO need ubi coords + return "", false + } + return "", false } // CassandraDatacenterSpec defines the desired state of a CassandraDatacenter @@ -320,10 +333,16 @@ func init() { } func (dc *CassandraDatacenter) GetConfigBuilderImage() string { - if dc.Spec.ConfigBuilderImage == "" { - return defaultConfigBuilderImage + var image string + if dc.Spec.ConfigBuilderImage != "" { + image = dc.Spec.ConfigBuilderImage + } else if baseImageOs := os.Getenv(EnvBaseImageOs); baseImageOs != "" { + //TODO actual config builder ubi image + image = "config-builder-ubi:test1" + } else { + image = defaultConfigBuilderImage } - return dc.Spec.ConfigBuilderImage + return image } // GetServerImage produces a fully qualified container image to pull From 97e30c254243493aa0edd3d41e59d5d8e5bcaecc Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Fri, 5 Jun 2020 15:04:09 -0400 Subject: [PATCH 15/30] add in dse and config builder ubi coords --- .../v1beta1/cassandradatacenter_types.go | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go index e48fb7ec1..28243ff06 100644 --- a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -19,8 +19,6 @@ import ( ) const ( - defaultConfigBuilderImage = "datastax/cass-config-builder:1.0.0" - // ClusterLabel is the operator's label for the cluster name ClusterLabel = "cassandra.datastax.com/cluster" @@ -48,10 +46,15 @@ const ( type ProgressState string const ( - cassandra_3_11_6 = "datastax/cassandra-mgmtapi-3_11_6:v0.1.2" - cassandra_4_0_0 = "datastax/cassandra-mgmtapi-4_0_0:v0.1.2" - dse_6_8_0 = "datastax/dse-server:6.8.0" - EnvBaseImageOs = "BASE_IMAGE_OS" + defaultConfigBuilderImage = "datastax/cass-config-builder:1.0.0" + cassandra_3_11_6 = "datastax/cassandra-mgmtapi-3_11_6:v0.1.2" + cassandra_4_0_0 = "datastax/cassandra-mgmtapi-4_0_0:v0.1.2" + dse_6_8_0 = "datastax/dse-server:6.8.0" + ubi_cassandra_3_11_6 = "TODO" + ubi_cassandra_4_0_0 = "TODO" + ubi_dse_6_8_0 = "registry.connect.redhat.com/datastax/dse-server:6.8.0" + ubi_defaultConfigBuilderImage = "registry.connect.redhat.com/datastax/cass-config-builder:1.0.0" + EnvBaseImageOs = "BASE_IMAGE_OS" ) // getImageForServerVersion tries to look up a known image for a server type and version number. @@ -68,6 +71,10 @@ func getImageForServerVersion(server, version string) (string, error) { imageCalc = getImageForDefaultBaseOs errMsg = fmt.Sprintf("server '%s' and version '%s' do not work together", server, version) } else { + // if this operator was compiled using a UBI base image + // such as registry.access.redhat.com/ubi7/ubi-minimal:7.8 + // then we use specific cassandra and init container coordinates + // that are built accordingly errMsg = fmt.Sprintf("server '%s' and version '%s', along with the specified base OS '%s', do not work together", server, version, baseImageOs) imageCalc = getImageForUniversalBaseOs } @@ -95,14 +102,11 @@ func getImageForDefaultBaseOs(sv string) (string, bool) { func getImageForUniversalBaseOs(sv string) (string, bool) { switch sv { case "dse-6.8.0": - //TODO need ubi coords - return "", false + return ubi_dse_6_8_0, true case "cassandra-3.11.6": - //TODO need ubi coords - return "", false + return ubi_cassandra_3_11_6, true case "cassandra-4.0.0": - //TODO need ubi coords - return "", false + return ubi_cassandra_4_0_0, true } return "", false } @@ -337,8 +341,7 @@ func (dc *CassandraDatacenter) GetConfigBuilderImage() string { if dc.Spec.ConfigBuilderImage != "" { image = dc.Spec.ConfigBuilderImage } else if baseImageOs := os.Getenv(EnvBaseImageOs); baseImageOs != "" { - //TODO actual config builder ubi image - image = "config-builder-ubi:test1" + image = ubi_defaultConfigBuilderImage } else { image = defaultConfigBuilderImage } From 89540fd97e90fbbf77218a0130246afedc08dcad Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Tue, 16 Jun 2020 11:34:33 -0400 Subject: [PATCH 16/30] add oss c* 3.11.6 image --- .../pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go index 28243ff06..9ac71b35d 100644 --- a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -50,7 +50,7 @@ const ( cassandra_3_11_6 = "datastax/cassandra-mgmtapi-3_11_6:v0.1.2" cassandra_4_0_0 = "datastax/cassandra-mgmtapi-4_0_0:v0.1.2" dse_6_8_0 = "datastax/dse-server:6.8.0" - ubi_cassandra_3_11_6 = "TODO" + ubi_cassandra_3_11_6 = "registry.connect.redhat.com/datastax/cassandra:3.11.6" ubi_cassandra_4_0_0 = "TODO" ubi_dse_6_8_0 = "registry.connect.redhat.com/datastax/dse-server:6.8.0" ubi_defaultConfigBuilderImage = "registry.connect.redhat.com/datastax/cass-config-builder:1.0.0" @@ -106,7 +106,8 @@ func getImageForUniversalBaseOs(sv string) (string, bool) { case "cassandra-3.11.6": return ubi_cassandra_3_11_6, true case "cassandra-4.0.0": - return ubi_cassandra_4_0_0, true + //TODO no image available yet + return ubi_cassandra_4_0_0, false } return "", false } From 14d4c91d16a009360de0d0496e5aab604042c742 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Tue, 16 Jun 2020 14:08:20 -0400 Subject: [PATCH 17/30] prefix ioutil import --- operator/cmd/manager/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator/cmd/manager/main.go b/operator/cmd/manager/main.go index dc15d9cac..e65ae76a2 100644 --- a/operator/cmd/manager/main.go +++ b/operator/cmd/manager/main.go @@ -11,7 +11,7 @@ import ( "errors" "flag" "fmt" - "io/ioutil" + ioutil "io/ioutil" "os" "path/filepath" "runtime" From 288402cd2ba4ef2708d2c2b0e7b964f76d22e55e Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Tue, 16 Jun 2020 14:43:25 -0400 Subject: [PATCH 18/30] Add debug cat cmd to gh action --- .github/workflows/operatorBuildAndDeploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 528ba1428..7709cf6c0 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -38,6 +38,7 @@ jobs: MO_BRANCH: ${{ github.event.pull_request.head.ref }} run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH + cat ./operator/cmd/manager/main.go mage operator:testAndBuild cat ./build/tagsToPush.txt > ./build/fullTagsToPush.txt echo "|" >> ./build/fullTagsToPush.txt From ce01958a927d4ce6a79de89c421c67e8973397a8 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Tue, 16 Jun 2020 15:03:57 -0400 Subject: [PATCH 19/30] add conditions around checkout rules in gh workflow to avoid merging --- .github/workflows/operatorBuildAndDeploy.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 7709cf6c0..69a0a8cbd 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -13,6 +13,11 @@ jobs: GOROOT: /usr/local/go1.13 steps: - uses: actions/checkout@v2 + if: github.event_name == 'pull_request' + with: + ref: ${{ github.event.pull_request.head.sha }} + - uses: actions/checkout@v2 + if: github.event_name != 'pull_request' - name: Set up Go 1.13 uses: actions/setup-go@v1 with: From 0710032d82c4687df3d045302975e72473cd5be9 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Tue, 16 Jun 2020 15:08:56 -0400 Subject: [PATCH 20/30] Remove debug print in gh workflow --- .github/workflows/operatorBuildAndDeploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 69a0a8cbd..fa9ed1baf 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -43,7 +43,6 @@ jobs: MO_BRANCH: ${{ github.event.pull_request.head.ref }} run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - cat ./operator/cmd/manager/main.go mage operator:testAndBuild cat ./build/tagsToPush.txt > ./build/fullTagsToPush.txt echo "|" >> ./build/fullTagsToPush.txt From 3c6c780de6b2f24d2caf7ebfa8fd4475ae0ca7d1 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 25 Jun 2020 10:40:48 -0400 Subject: [PATCH 21/30] use separate dockerfile for ubi images --- mage/operator/lib.go | 29 ++- operator/{ => docker/base}/Dockerfile | 6 +- operator/docker/ubi/Dockerfile | 49 +++++ operator/docker/ubi/LICENSE | 201 ++++++++++++++++++ .../v1beta1/cassandradatacenter_types.go | 17 +- 5 files changed, 280 insertions(+), 22 deletions(-) rename operator/{ => docker/base}/Dockerfile (94%) create mode 100644 operator/docker/ubi/Dockerfile create mode 100644 operator/docker/ubi/LICENSE diff --git a/mage/operator/lib.go b/mage/operator/lib.go index d9ccdc895..af4804ecd 100644 --- a/mage/operator/lib.go +++ b/mage/operator/lib.go @@ -23,6 +23,8 @@ import ( ) const ( + dockerBase = "./operator/docker/base/Dockerfile" + dockerUbi = "./operator/docker/ubi/Dockerfile" rootBuildDir = "./build" sdkBuildDir = "operator/build" diagramsDir = "./docs/developer/diagrams" @@ -350,12 +352,12 @@ func calcFullVersion(settings cfgutil.BuildSettings, git GitData) FullVersion { } } -func calcVersionAndTags(version FullVersion) (string, []string) { +func calcVersionAndTags(version FullVersion, ubiBase bool) (string, []string) { repoPath := "datastax/cass-operator" var versionedTag string var tagsToPush []string - if baseOs := os.Getenv(EnvBaseOs); baseOs != "" { + if ubiBase { versionedTag = fmt.Sprintf("%s:%v-ubi", repoPath, version) tagsToPush = []string{ versionedTag, @@ -370,15 +372,14 @@ func calcVersionAndTags(version FullVersion) (string, []string) { fmt.Sprintf("%s:latest", repoPath), } } + return versionedTag, tagsToPush } -func runDockerBuild(versionedTag string, dockerTags []string) { +func runDockerBuild(versionedTag string, dockerTags []string, extraBuildArgs []string, dockerfile string) { buildArgs := []string{fmt.Sprintf("VERSION_STAMP=%s", versionedTag)} - if baseOs := os.Getenv(EnvBaseOs); baseOs != "" { - buildArgs = append(buildArgs, fmt.Sprintf("BASE_OS=%s", baseOs)) - } - dockerutil.Build(".", "", "./operator/Dockerfile", dockerTags, buildArgs).ExecVPanic() + buildArgs = append(buildArgs, extraBuildArgs...) + dockerutil.Build(".", "", dockerfile, dockerTags, buildArgs).ExecVPanic() } func runGoBuild(version string) { @@ -443,8 +444,18 @@ func BuildDocker() { git := getGitData() version := calcFullVersion(settings, git) - versionedTag, dockerTags := calcVersionAndTags(version) - runDockerBuild(versionedTag, dockerTags) + //build regular docker image + versionedTag, dockerTags := calcVersionAndTags(version, false) + runDockerBuild(versionedTag, dockerTags, nil, dockerBase) + + if baseOs := os.Getenv(EnvBaseOs); baseOs != "" { + //build ubi docker image + args := []string{fmt.Sprintf("BASE_OS=%s", baseOs)} + ubiVersionedTag, ubiDockerTags := calcVersionAndTags(version, true) + runDockerBuild(ubiVersionedTag, ubiDockerTags, args, dockerUbi) + dockerTags = append(dockerTags, ubiDockerTags...) + } + // Write the versioned image tags to a file in our build // directory so that other targets in the build process can identify // what was built. This is particularly important to know diff --git a/operator/Dockerfile b/operator/docker/base/Dockerfile similarity index 94% rename from operator/Dockerfile rename to operator/docker/base/Dockerfile index ffdceef0c..3d2a8fdb3 100644 --- a/operator/Dockerfile +++ b/operator/docker/base/Dockerfile @@ -4,7 +4,6 @@ ########## # "builder" compiles and tests the code # This stage name is important to the Cloud Platform CI/CD infrastructure, and should be preserved -ARG BASE_OS=alpine:3.9 FROM golang:1.13-stretch as builder # Disable cgo - this makes static binaries that will work on an Alpine image @@ -46,13 +45,12 @@ RUN MO_VERSION=${VERSION_STAMP} mage operator:buildGo # Second stage # Produce a smaller image than the one used to build the code -FROM ${BASE_OS} +FROM alpine:3.9 ENV GOPATH=/go -ARG BASE_OS="" RUN mkdir -p /var/lib/cass-operator/ -RUN echo "${BASE_OS}" > /var/lib/cass-operator/base_os +RUN touch /var/lib/cass-operator/base_os WORKDIR /go # All we need from the builder image is operator executable diff --git a/operator/docker/ubi/Dockerfile b/operator/docker/ubi/Dockerfile new file mode 100644 index 000000000..7bed555ca --- /dev/null +++ b/operator/docker/ubi/Dockerfile @@ -0,0 +1,49 @@ +ARG BASE_OS +FROM datastax/cass-operator:latest AS base + +############################################################# + +FROM ${BASE_OS} AS builder + +# Update the builder layer and create user +RUN microdnf update && rm -rf /var/cache/yum && \ + microdnf install shadow-utils && microdnf clean all && \ + useradd -r -s /bin/false -U -G root cassandra + +############################################################# +FROM ${BASE_OS} + +ARG BASE_OS +ARG VERSION_STAMP=DEV + +LABEL maintainer="DataStax, Inc " +LABEL name="cass-operator" +LABEL vendor="DataStax, Inc" +LABEL release="${VERSION_STAMP}" +LABEL summary="DataStax Kubernetes Operator for Apache Cassandra " +LABEL description="The DataStax Kubernetes Operator for Apache Cassandra®. This operator handles the provisioning and day to day management of Apache Cassandra based clusters. Features include configuration deployment, node remediation, and automatic upgrades." + +# Update the builder layer and create user +RUN microdnf update && rm -rf /var/cache/yum && \ + microdnf install procps-ng && microdnf clean all + +# Copy user accounts information +COPY --from=builder /etc/passwd /etc/passwd +COPY --from=builder /etc/shadow /etc/shadow +COPY --from=builder /etc/group /etc/group +COPY --from=builder /etc/gshadow /etc/gshadow + +# Copy operator binary +COPY --from=base /go/bin/operator /operator +COPY ./operator/docker/ubi/LICENSE /licenses/ + +RUN mkdir -p /var/lib/cass-operator/ +RUN echo ${BASE_OS} > /var/lib/cass-operator/base_os + +RUN chown cassandra:root /operator && \ + chmod 0555 /operator + +USER cassandra:root + + +ENTRYPOINT ["/operator"] \ No newline at end of file diff --git a/operator/docker/ubi/LICENSE b/operator/docker/ubi/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/operator/docker/ubi/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go index f278dc7db..f02737728 100644 --- a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -50,10 +50,10 @@ const ( cassandra_3_11_6 = "datastax/cassandra-mgmtapi-3_11_6:v0.1.5" cassandra_4_0_0 = "datastax/cassandra-mgmtapi-4_0_0:v0.1.5" dse_6_8_0 = "datastax/dse-server:6.8.0" - ubi_cassandra_3_11_6 = "registry.connect.redhat.com/datastax/cassandra:3.11.6" - ubi_cassandra_4_0_0 = "TODO" - ubi_dse_6_8_0 = "registry.connect.redhat.com/datastax/dse-server:6.8.0" - ubi_defaultConfigBuilderImage = "registry.connect.redhat.com/datastax/cass-config-builder:1.0.0" + ubi_cassandra_3_11_6 = "datastax/cassandra:3.11.6-ubi7" + ubi_cassandra_4_0_0 = "datastax/cassandra:4.0-ubi7" + ubi_dse_6_8_0 = "datastax/dse-server:6.8.0-ubi7" + ubi_defaultConfigBuilderImage = "datastax/cass-config-builder:1.0.0-ubi7" EnvBaseImageOs = "BASE_IMAGE_OS" ) @@ -106,15 +106,14 @@ func getImageForUniversalBaseOs(sv string) (string, bool) { case "cassandra-3.11.6": return ubi_cassandra_3_11_6, true case "cassandra-4.0.0": - //TODO no image available yet - return ubi_cassandra_4_0_0, false + return ubi_cassandra_4_0_0, true } return "", false } type CassandraUser struct { SecretName string `json:"secretName"` - Superuser bool `json:"superuser"` + Superuser bool `json:"superuser"` } // CassandraDatacenterSpec defines the desired state of a CassandraDatacenter @@ -274,8 +273,8 @@ func NewDatacenterCondition(conditionType DatacenterConditionType, status corev1 type CassandraDatacenterStatus struct { Conditions []DatacenterCondition `json:"conditions,omitempty"` - // Deprecated. Use usersUpserted instead. The timestamp at - // which CQL superuser credentials were last upserted to the + // Deprecated. Use usersUpserted instead. The timestamp at + // which CQL superuser credentials were last upserted to the // management API // +optional SuperUserUpserted metav1.Time `json:"superUserUpserted,omitempty"` From cb76c87a998d0a99487ee6deff5a1788ef6df0ca Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 25 Jun 2020 14:08:41 -0400 Subject: [PATCH 22/30] only run docker build once now --- .github/workflows/operatorBuildAndDeploy.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index fa9ed1baf..0c9047f87 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -38,22 +38,13 @@ jobs: run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testGenerateClient - - name: Build docker - standard image - env: - MO_BRANCH: ${{ github.event.pull_request.head.ref }} - run: | - export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - mage operator:testAndBuild - cat ./build/tagsToPush.txt > ./build/fullTagsToPush.txt - echo "|" >> ./build/fullTagsToPush.txt - - name: Build docker - ubi image + - name: Build docker - standard and ubi images env: MO_BRANCH: ${{ github.event.pull_request.head.ref }} MO_BASE_OS: 'registry.access.redhat.com/ubi7/ubi-minimal:7.8' run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - cat ./build/tagsToPush.txt >> ./build/fullTagsToPush.txt - name: Deploy to ECR if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' env: @@ -62,7 +53,7 @@ jobs: MO_ECR_REPO: ${{ secrets.ECR_REPO }} run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - export MO_TAGS=$(cat ./build/fullTagsToPush.txt) + export MO_TAGS=$(cat ./build/tagsToPush.txt) mage operator:deployToECR - name: Deploy to GH Packages if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator' From 7808c31af846aaf0e270307976d40fb2a2e218c0 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 25 Jun 2020 14:09:15 -0400 Subject: [PATCH 23/30] debug print in workflow --- .github/workflows/operatorBuildAndDeploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 0c9047f87..9d79d7936 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -43,6 +43,7 @@ jobs: MO_BRANCH: ${{ github.event.pull_request.head.ref }} MO_BASE_OS: 'registry.access.redhat.com/ubi7/ubi-minimal:7.8' run: | + echo "BRANCH: [${MO_BRANCH}]" export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - name: Deploy to ECR From ab4f8b68a7eb142d6874f5b8dcb03221f0c82969 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 25 Jun 2020 14:20:08 -0400 Subject: [PATCH 24/30] more debug --- .github/workflows/operatorBuildAndDeploy.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 9d79d7936..03fe0e672 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -40,10 +40,11 @@ jobs: mage operator:testGenerateClient - name: Build docker - standard and ubi images env: - MO_BRANCH: ${{ github.event.pull_request.head.ref }} + PR_REF: ${{ github.event.pull_request.head.ref }} MO_BASE_OS: 'registry.access.redhat.com/ubi7/ubi-minimal:7.8' run: | - echo "BRANCH: [${MO_BRANCH}]" + if [ ${GITHUB_EVENT_NAME} -eq "pull_request" ]; then export MO_BRANCH=${PR_REF}; fi; + "MO_BRANCH: [${MO_BRANCH}]" export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - name: Deploy to ECR From 0aaf87bfa752a00f36c2df0ad7b9f8777efb996c Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 25 Jun 2020 14:25:45 -0400 Subject: [PATCH 25/30] fixup! more debug --- .github/workflows/operatorBuildAndDeploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 03fe0e672..d411388bb 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -44,7 +44,7 @@ jobs: MO_BASE_OS: 'registry.access.redhat.com/ubi7/ubi-minimal:7.8' run: | if [ ${GITHUB_EVENT_NAME} -eq "pull_request" ]; then export MO_BRANCH=${PR_REF}; fi; - "MO_BRANCH: [${MO_BRANCH}]" + echo "MO_BRANCH: [${MO_BRANCH}]" export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - name: Deploy to ECR From 0b385eb6d631c3cf00f630b8863175d7ddd18967 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 25 Jun 2020 14:38:18 -0400 Subject: [PATCH 26/30] fixup! fixup! more debug --- .github/workflows/operatorBuildAndDeploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index d411388bb..01c1de525 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -24,6 +24,7 @@ jobs: go-version: 1.13 - name: Install Mage run: | + echo "GH_EVENT: [${GITHUB_EVENT_NAME}]" cd /tmp wget https://github.com/magefile/mage/releases/download/v1.9.0/mage_1.9.0_Linux-64bit.tar.gz tar -xvf mage_1.9.0_Linux-64bit.tar.gz From 96080eb4e18e7151af50beef77eb4b1667141d48 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 25 Jun 2020 14:40:48 -0400 Subject: [PATCH 27/30] fixup! fixup! fixup! more debug --- .github/workflows/operatorBuildAndDeploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 01c1de525..a55da7a87 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -24,7 +24,6 @@ jobs: go-version: 1.13 - name: Install Mage run: | - echo "GH_EVENT: [${GITHUB_EVENT_NAME}]" cd /tmp wget https://github.com/magefile/mage/releases/download/v1.9.0/mage_1.9.0_Linux-64bit.tar.gz tar -xvf mage_1.9.0_Linux-64bit.tar.gz @@ -44,8 +43,9 @@ jobs: PR_REF: ${{ github.event.pull_request.head.ref }} MO_BASE_OS: 'registry.access.redhat.com/ubi7/ubi-minimal:7.8' run: | - if [ ${GITHUB_EVENT_NAME} -eq "pull_request" ]; then export MO_BRANCH=${PR_REF}; fi; + if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then export MO_BRANCH=${PR_REF}; fi; echo "MO_BRANCH: [${MO_BRANCH}]" + echo "PR_REF: [${PR_REF}]" export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - name: Deploy to ECR From c1ff59c1e981cd0369b2dba0261ec5baa36399cd Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 25 Jun 2020 14:49:29 -0400 Subject: [PATCH 28/30] use env constant instead of string; more gh workflow debugging --- .github/workflows/operatorBuildAndDeploy.yml | 7 +++++-- operator/cmd/manager/main.go | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index a55da7a87..342823e95 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -43,9 +43,12 @@ jobs: PR_REF: ${{ github.event.pull_request.head.ref }} MO_BASE_OS: 'registry.access.redhat.com/ubi7/ubi-minimal:7.8' run: | - if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then export MO_BRANCH=${PR_REF}; fi; + if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then + export MO_BRANCH=${PR_REF} + else + export MO_BRANCH="master" + fi; echo "MO_BRANCH: [${MO_BRANCH}]" - echo "PR_REF: [${PR_REF}]" export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - name: Deploy to ECR diff --git a/operator/cmd/manager/main.go b/operator/cmd/manager/main.go index ec6ec7915..e46788b4c 100644 --- a/operator/cmd/manager/main.go +++ b/operator/cmd/manager/main.go @@ -230,8 +230,8 @@ func readBaseOsIntoEnv() error { } baseOs := strings.TrimSpace(string(rawVal)) - os.Setenv("BASE_IMAGE_OS", baseOs) - log.Info(fmt.Sprintf("BASE_IMAGE_OS set to '%s'", baseOs)) + os.Setenv(api.EnvBaseImageOs, baseOs) + log.Info(fmt.Sprintf("%s set to '%s'", api.EnvBaseImageOs, baseOs)) return nil } From 44fb640d4df7d573775a795ddee5af5cdf0dd170 Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 25 Jun 2020 14:55:32 -0400 Subject: [PATCH 29/30] workflow should be in good shape now --- .github/workflows/operatorBuildAndDeploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index 342823e95..f7bd8de98 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -48,7 +48,6 @@ jobs: else export MO_BRANCH="master" fi; - echo "MO_BRANCH: [${MO_BRANCH}]" export PATH=$GOROOT/bin:$GOPATH/bin:$PATH mage operator:testAndBuild - name: Deploy to ECR From 200bff9c1a997e39b467087ae5e89e2867c8964d Mon Sep 17 00:00:00 2001 From: Chris Mills Date: Thu, 25 Jun 2020 15:07:58 -0400 Subject: [PATCH 30/30] use correct docker tags file for gh package pushing.. --- .github/workflows/operatorBuildAndDeploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/operatorBuildAndDeploy.yml b/.github/workflows/operatorBuildAndDeploy.yml index f7bd8de98..9cf429e73 100644 --- a/.github/workflows/operatorBuildAndDeploy.yml +++ b/.github/workflows/operatorBuildAndDeploy.yml @@ -68,5 +68,5 @@ jobs: MO_GH_PKG_REPO: 'datastax/cass-operator/operator' run: | export PATH=$GOROOT/bin:$GOPATH/bin:$PATH - export MO_TAGS=$(cat ./build/fullTagsToPush.txt) + export MO_TAGS=$(cat ./build/tagsToPush.txt) mage operator:deployToGHPackages