Skip to content

Commit

Permalink
updating bazel and deps
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislovecnm committed Sep 1, 2020
1 parent f25c1e9 commit d6adccf
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 26 deletions.
3 changes: 2 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"],
Expand Down
22 changes: 11 additions & 11 deletions cmd/cockroach-operator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)

Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 2 additions & 0 deletions hack/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"])
Expand Down
16 changes: 16 additions & 0 deletions hack/build/repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
12 changes: 6 additions & 6 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions pkg/update/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
2 changes: 1 addition & 1 deletion pkg/update/oss_update_cockroach_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
50 changes: 47 additions & 3 deletions pkg/update/update_cockroach_version_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit d6adccf

Please sign in to comment.