Skip to content

Commit

Permalink
Fix the development workflow which was failing in make dev/build.
Browse files Browse the repository at this point in the history
Removed rules_k8s bazel dependency as it is deprecated and not supported with rules_oci.
  • Loading branch information
prafull01 committed Jan 27, 2025
1 parent ab1f129 commit f178f37
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 63 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ oci_push(
image = "//cmd/cockroach-operator:index",
remote_tags = ":tags",
repository = "${DOCKER_REGISTRY}/${DOCKER_IMAGE_REPOSITORY}",
visibility = ["//visibility:public"],
)

filegroup(
Expand Down
36 changes: 0 additions & 36 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -129,42 +129,6 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

################################
# Load rules_k8s and configure #
################################
http_archive(
name = "io_bazel_rules_k8s",
sha256 = "ce5b9bc0926681e2e7f2147b49096f143e6cbc783e71bc1d4f36ca76b00e6f4a",
strip_prefix = "rules_k8s-0.7",
urls = ["https://github.com/bazelbuild/rules_k8s/archive/refs/tags/v0.7.tar.gz"],
)

load("@io_bazel_rules_k8s//k8s:k8s.bzl", "k8s_repositories")

k8s_repositories()

load("@io_bazel_rules_k8s//k8s:k8s.bzl", "k8s_defaults")

#############################################################
# Setting up the defaults for rules k8s. The varible values
# are replaced by hack/build/print-workspace-status.sh
# Using environment variables that are prefixed with the word
# 'STAMP_' causes the rules_k8s files to rebuild when the
# --stamp and evn values change.
#############################################################
k8s_defaults(
# This becomes the name of the @repository and the rule
# you will import in your BUILD files.
name = "k8s_deploy",
# This is the name of the cluster as it appears in:
# kubectl config view --minify -o=jsonpath='{.contexts[0].context.cluster}'
# You are able to override the default cluster by setting the env variable K8S_CLUSTER
cluster = "{STABLE_CLUSTER}",
# You are able to override the default registry by setting the env variable DEV_REGISTRY
image_chroot = "{STABLE_IMAGE_REGISTRY}",
kind = "deployment",
)

###################################################
# Load kubernetes repo-infra for tools like kazel #
###################################################
Expand Down
10 changes: 6 additions & 4 deletions config/crd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@k8s_deploy//:defaults.bzl", "k8s_deploy")
load("//hack/build:kustomize.bzl", "kustomization")

kustomization(
name = "manifest",
srcs = [":all-srcs"],
)

k8s_deploy(
name = "crd",
template = ":manifest",
# Use a shell script to apply the manifest via kubectl
sh_binary(
name = "apply_k8s_crd",
srcs = ["//config/default:apply_k8s_script"],
args = ["$(location :manifest)"],
data = [":manifest"],
visibility = ["//visibility:public"],
)

Expand Down
25 changes: 10 additions & 15 deletions config/default/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# 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.
load("@k8s_deploy//:defaults.bzl", "k8s_deploy")
load("@io_bazel_rules_k8s//k8s:objects.bzl", "k8s_objects")
load("//hack/build:kustomize.bzl", "kustomization")

# Builds the whole enchilada including the crds, rbac sa(s)/roles/bindings, manager
Expand All @@ -28,21 +26,18 @@ kustomization(
],
)

k8s_deploy(
name = "image",
images = {
# when running locally, use the image from the local codebase
"cockroach-operator:$(APP_VERSION)": "//cmd/cockroach-operator:operator_image",
},
resolver_args = ["--allow_unused_images"],
template = ":manifest",
filegroup(
name = "apply_k8s_script",
srcs = ["apply_k8s.sh"], # List the shell script here
visibility = ["//visibility:public"], # Make it accessible to other packages
)

k8s_objects(
name = "install",
objects = [
":image",
],
# Use a shell script to apply the manifest via kubectl
sh_binary(
name = "apply_k8s_app",
srcs = ["apply_k8s.sh"],
args = ["$(location :manifest)"],
data = [":manifest"],
visibility = ["//visibility:public"],
)

Expand Down
11 changes: 11 additions & 0 deletions config/default/apply_k8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e

MANIFEST="$1"

if [ -z "$MANIFEST" ]; then
echo "Manifest file not provided."
exit 1
fi

kubectl apply -f "$MANIFEST"
10 changes: 6 additions & 4 deletions config/webhook/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@k8s_deploy//:defaults.bzl", "k8s_deploy")
load("//hack/build:kustomize.bzl", "kustomization")

kustomization(
name = "manifest",
srcs = [":all-srcs"],
)

k8s_deploy(
name = "webhook",
template = ":manifest",
# Use a shell script to apply the manifest via kubectl
sh_binary(
name = "apply_k8s_webhook",
srcs = ["//config/default:apply_k8s_script"],
args = ["$(location :manifest)"],
data = [":manifest"],
visibility = ["//visibility:public"],
)

Expand Down
11 changes: 7 additions & 4 deletions hack/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ install_operator() {
# ${REGISTRY_NAME} must be mapped to localhost or 127.0.0.1 to push the image to the k3d registry.
bazel run //hack/crdbversions:crdbversions -- -operator-image ${DEV_REGISTRY}/cockroach-operator -operator-version ${APP_VERSION} -crdb-versions $(PWD)/crdb-versions.yaml -repo-root $(PWD)
K8S_CLUSTER="k3d-${CLUSTER_NAME}" \
DEV_REGISTRY="${DEV_REGISTRY}" \
DOCKER_REGISTRY="${DEV_REGISTRY}" \
DOCKER_IMAGE_REPOSITORY="cockroach-operator" \
APP_VERSION="${APP_VERSION}" \
bazel run \
--stamp \
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \
--define APP_VERSION=${APP_VERSION} \
//config/default:install.apply
//:push_operator_image
bazel run \
--stamp \
//config/default:apply_k8s_app
}

wait_for_ready() {
Expand Down

0 comments on commit f178f37

Please sign in to comment.