diff --git a/BUILD.bazel b/BUILD.bazel index 4fdf112bd..5b288142c 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -23,7 +23,7 @@ container_push( image = "//cmd/cockroach-operator:operator_image", registry = "{STABLE_DOCKER_REGISTRY}", repository = "{STABLE_IMAGE_REPOSITORY}", - tag = "{STABLE_DOCKER_TAG}" + tag = "{STABLE_DOCKER_TAG}", ) filegroup( @@ -65,6 +65,7 @@ filegroup( "//pkg/resource:all-srcs", "//pkg/testutil:all-srcs", "//pkg/tls:all-srcs", + "//pkg/update:all-srcs", ], tags = ["automanaged"], visibility = ["//visibility:public"], diff --git a/cmd/cockroach-operator/BUILD.bazel b/cmd/cockroach-operator/BUILD.bazel index 1c9961ed5..dce34b725 100644 --- a/cmd/cockroach-operator/BUILD.bazel +++ b/cmd/cockroach-operator/BUILD.bazel @@ -27,32 +27,32 @@ go_binary( pkg_tar( name = "licenses", - package_dir = "/licenses", srcs = ["//:license"], mode = "0755", + package_dir = "/licenses", ) container_image( name = "ubi_base_image", + # References container_pull from WORKSPACE + base = "@redhat_ubi_minimal//image", labels = { - "name":"CockroachDB Operator", - "vendor":"Cockroach Labs", - # FIXME - labels do not support a stamped variable such as {STABLE_DOCKER_TAG} - "version":"v1.0.0-rc.0", - "release":"0", - "summary":"CockroachDB is a Distributed SQL database", - "description":"CockroachDB is a PostgreSQL wire-compatible DistributedSQL database", + "name": "CockroachDB Operator", + "vendor": "Cockroach Labs", + # FIXME - labels do not support a stamped variable such as {STABLE_DOCKER_TAG} + "version": "v1.0.0-rc.0", + "release": "0", + "summary": "CockroachDB is a Distributed SQL database", + "description": "CockroachDB is a PostgreSQL wire-compatible DistributedSQL database", }, tars = [":licenses"], - # References container_pull from WORKSPACE - base = "@redhat_ubi_minimal//image", ) go_image( name = "operator_image", - binary = ":cockroach-operator", # using the ubi image instead of the go base image base = ":ubi_base_image", + binary = ":cockroach-operator", visibility = ["//visibility:public"], ) diff --git a/go.mod b/go.mod index 752b5ad63..c70fea226 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/cockroachdb/cockroach-operator go 1.14 require ( - github.com/Masterminds/semver v1.5.0 github.com/Masterminds/semver/v3 v3.1.0 github.com/banzaicloud/k8s-objectmatcher v1.3.2 github.com/cenkalti/backoff v2.2.1+incompatible @@ -25,7 +24,6 @@ require ( k8s.io/client-go v9.0.0+incompatible k8s.io/code-generator v0.18.5 k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6 - k8s.io/kubernetes v1.13.0 sigs.k8s.io/controller-runtime v0.5.4 sigs.k8s.io/controller-tools v0.2.9-0.20200414181213-645d44dca7c0 sigs.k8s.io/kubetest2 v0.0.0-20200807173356-3d574132ed2e diff --git a/go.sum b/go.sum index 49aad268b..5d2b38736 100644 --- a/go.sum +++ b/go.sum @@ -72,8 +72,6 @@ github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced3 github.com/GoogleCloudPlatform/testgrid v0.0.7/go.mod h1:lmtHGBL0M/MLbu1tR9BWV7FGZ1FEFIdPqmJiHNCL7y8= github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd/go.mod h1:64YHyfSL2R96J44Nlwm39UHepQbyR5q10x7iYa1ks2E= github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= -github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/semver/v3 v3.0.3/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= github.com/Masterminds/semver/v3 v3.1.0 h1:Y2lUDsFKVRSYGojLJ1yLxSXdMmMYTYls0rCvoqmMUQk= github.com/Masterminds/semver/v3 v3.1.0/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= diff --git a/hack/BUILD.bazel b/hack/BUILD.bazel index a1114d14c..edb02558e 100644 --- a/hack/BUILD.bazel +++ b/hack/BUILD.bazel @@ -1,3 +1,5 @@ +# gazelle:exclude verify_boilerplate_test.go + load("@io_bazel_rules_go//go:def.bzl", "go_test") package(default_visibility = ["//visibility:public"]) diff --git a/hack/build/repos.bzl b/hack/build/repos.bzl index f0aeb4634..4b94c6a31 100644 --- a/hack/build/repos.bzl +++ b/hack/build/repos.bzl @@ -4185,3 +4185,19 @@ def go_repositories(): sum = "h1:aykwPMVyQyncZ8iLNVMXgJ1l3c6W0+LSOPmqp8JdCjs=", version = "v3.1.1", ) + go_repository( + name = "com_github_cenkalti_backoff", + build_file_generation = "on", + build_file_proto_mode = "disable", + importpath = "github.com/cenkalti/backoff", + sum = "h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=", + version = "v2.2.1+incompatible", + ) + go_repository( + name = "com_github_masterminds_semver", + build_file_generation = "on", + build_file_proto_mode = "disable", + importpath = "github.com/Masterminds/semver", + sum = "h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=", + version = "v1.5.0", + ) diff --git a/hack/update-deps.sh b/hack/update-deps.sh index d1384ed3e..1c8dd77b1 100755 --- a/hack/update-deps.sh +++ b/hack/update-deps.sh @@ -47,13 +47,13 @@ update_bazel=( "$gazelle" "$kazel" ) -update_deps_licenses=( - $(realpath "$6") - "$go" - "$jq" -) +#update_deps_licenses=( +# $(realpath "$6") +# "$go" +# "$jq" +#) -shift 6 +shift 5 cd "$BUILD_WORKSPACE_DIRECTORY" trap 'echo "FAILED" >&2' ERR diff --git a/pkg/update/BUILD.bazel b/pkg/update/BUILD.bazel new file mode 100644 index 000000000..73e3274bc --- /dev/null +++ b/pkg/update/BUILD.bazel @@ -0,0 +1,38 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "internal.go", + "oss_update_cockroach_version.go", + "update.go", + "update_cockroach_version_common.go", + ], + importpath = "github.com/cockroachdb/cockroach-operator/pkg/update", + visibility = ["//visibility:public"], + deps = [ + "@com_github_cenkalti_backoff//:go_default_library", + "@com_github_lib_pq//:go_default_library", + "@com_github_masterminds_semver_v3//:go_default_library", + "@com_github_pkg_errors//:go_default_library", + "@io_k8s_api//apps/v1:go_default_library", + "@io_k8s_api//core/v1:go_default_library", + "@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library", + "@io_k8s_client_go//kubernetes:go_default_library", + "@org_uber_go_zap//:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/update/oss_update_cockroach_version.go b/pkg/update/oss_update_cockroach_version.go index 6c03b6b67..a52e5d6de 100644 --- a/pkg/update/oss_update_cockroach_version.go +++ b/pkg/update/oss_update_cockroach_version.go @@ -8,7 +8,7 @@ import ( "database/sql" - "github.com/Masterminds/semver" + "github.com/Masterminds/semver/v3" "github.com/cenkalti/backoff" "github.com/lib/pq" "github.com/pkg/errors" diff --git a/pkg/update/update_cockroach_version_common.go b/pkg/update/update_cockroach_version_common.go index 886dd3d43..466f67788 100644 --- a/pkg/update/update_cockroach_version_common.go +++ b/pkg/update/update_cockroach_version_common.go @@ -4,12 +4,12 @@ import ( "context" "fmt" - semver "github.com/Masterminds/semver" + semver "github.com/Masterminds/semver/v3" "github.com/pkg/errors" "go.uber.org/zap" v1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/kubernetes/pkg/api/v1/pod" ) // makeUpdateCockroachVersionFunction takes a cockroachImage string and returns @@ -55,7 +55,7 @@ func makeIsCRBPodIsRunningNewVersionFunction( } // CRDB pod is updated to new Cockroach image. Now check // that the pod is in a ready state before proceeding. - if !pod.IsPodReady(crdbPod) { + if !IsPodReady(crdbPod) { return fmt.Errorf("%s pod not ready yet", podName) } l.Sugar().Infof("%s is running new version on %s", podName, stsNamespace) @@ -66,6 +66,50 @@ func makeIsCRBPodIsRunningNewVersionFunction( } } +// TODO this code is from https://github.com/kubernetes/kubernetes/blob/master/pkg/api/v1/pod/util.go +// We need to determine if this functionality is available via the client-go + +// IsPodReady returns true if a pod is ready; false otherwise. +func IsPodReady(pod *corev1.Pod) bool { + return IsPodReadyConditionTrue(pod.Status) +} + +// IsPodReadyConditionTrue returns true if a pod is ready; false otherwise. +func IsPodReadyConditionTrue(status corev1.PodStatus) bool { + condition := GetPodReadyCondition(status) + return condition != nil && condition.Status == corev1.ConditionTrue +} + +// GetPodReadyCondition extracts the pod ready condition from the given status and returns that. +// Returns nil if the condition is not present. +func GetPodReadyCondition(status corev1.PodStatus) *corev1.PodCondition { + _, condition := GetPodCondition(&status, corev1.PodReady) + return condition +} + +// GetPodCondition extracts the provided condition from the given status and returns that. +// Returns nil and -1 if the condition is not present, and the index of the located condition. +func GetPodCondition(status *corev1.PodStatus, conditionType corev1.PodConditionType) (int, *corev1.PodCondition) { + if status == nil { + return -1, nil + } + return GetPodConditionFromList(status.Conditions, conditionType) +} + +// GetPodConditionFromList extracts the provided condition from the given list of condition and +// returns the index of the condition and the condition. Returns -1 and nil if the condition is not present. +func GetPodConditionFromList(conditions []corev1.PodCondition, conditionType corev1.PodConditionType) (int, *corev1.PodCondition) { + if conditions == nil { + return -1, nil + } + for i := range conditions { + if conditions[i].Type == conditionType { + return i, &conditions[i] + } + } + return -1, nil +} + // Note that while CockroachDB considers 19.2 to be a major release, if we follow // semantic versioning (https://semver.org/spec/v2.0.0.html), both 19.1 and 19.2 // is a minor release of version 19. The code below parses the version as if it