diff --git a/BUILD.bazel b/BUILD.bazel index 7b37cc124..e2e5c98da 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -32,6 +32,7 @@ oci_push( image = "//cmd/cockroach-operator:index", remote_tags = ":tags", repository = "${DOCKER_REGISTRY}/${DOCKER_IMAGE_REPOSITORY}", + visibility = ["//visibility:public"], ) filegroup( diff --git a/WORKSPACE b/WORKSPACE index 82f81dd75..1aa552fec 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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 # ################################################### diff --git a/config/crd/BUILD.bazel b/config/crd/BUILD.bazel index b2620cd95..9657de911 100644 --- a/config/crd/BUILD.bazel +++ b/config/crd/BUILD.bazel @@ -12,7 +12,6 @@ # 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( @@ -20,9 +19,12 @@ kustomization( 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"], ) diff --git a/config/default/BUILD.bazel b/config/default/BUILD.bazel index 95c973a6c..278aa152d 100644 --- a/config/default/BUILD.bazel +++ b/config/default/BUILD.bazel @@ -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 @@ -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"], ) diff --git a/config/default/apply_k8s.sh b/config/default/apply_k8s.sh new file mode 100755 index 000000000..3292ee319 --- /dev/null +++ b/config/default/apply_k8s.sh @@ -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" diff --git a/config/webhook/BUILD.bazel b/config/webhook/BUILD.bazel index 229e5068f..91bdb188d 100644 --- a/config/webhook/BUILD.bazel +++ b/config/webhook/BUILD.bazel @@ -12,7 +12,6 @@ # 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( @@ -20,9 +19,12 @@ kustomization( 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"], ) diff --git a/hack/dev.sh b/hack/dev.sh index 311cb2c64..b5a124783 100755 --- a/hack/dev.sh +++ b/hack/dev.sh @@ -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() {