Skip to content

Commit 0f651cc

Browse files
committed
Fix the development environment for linux, darwin and M1 arch
1 parent bddf5e1 commit 0f651cc

File tree

13 files changed

+91
-27
lines changed

13 files changed

+91
-27
lines changed

DEVELOPER.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ since there's no need to set up a remote GKE/OpenShift cluster.
4444

4545
**make dev/up**
4646

47+
Pre-requisite: The command sets up a k3d registry, and to push an image to it, the registry name must resolve to
48+
localhost or 127.0.0.1. Please add the following line to your /etc/hosts file:
49+
50+
```shell
51+
127.0.0.1 registry.localhost
52+
```
53+
4754
This command will get everything set up for you to begin testing out the operator. Specifically it will:
4855

4956
* Start a k3d cluster named test (context=k3d-test) with a managed docker registry
@@ -56,6 +63,18 @@ This command will get everything set up for you to begin testing out the operato
5663

5764
Tears down the k3d cluster.
5865

66+
[Existing Cluster & Repo]:
67+
68+
export DEV_REGISTRY="Your_Registry"
69+
**make k8s/apply**
70+
71+
This command will deploy the operator to an existing cluster. It will build the operator image and push it to the DEV_REGISTRY.
72+
This newly built image will be used to deploy the operator.
73+
74+
**make k8s/delete**
75+
76+
Tears down the cockroach operator deployment applied on the cluster.
77+
5978
## Testing CR Database
6079

6180
Notes on how to test an existing CR Database.
@@ -71,6 +90,9 @@ SELECT * FROM bank.accounts;
7190

7291
## Developer Install Instructions
7392

93+
Pre-requisite:
94+
1. Install kustomize
95+
7496
These instructions are for developers only. If you want to try the alpha please use the instructions in the next
7597
section.
7698

@@ -79,13 +101,18 @@ Install the operator
79101
```console
80102
$ git clone https://github.com/cockroachdb/cockroach-operator.git
81103
$ export CLUSTER=test
104+
$ export APP_VERSION=v$(cat version.txt)
105+
$ export DEV_REGISTRY=us.gcr.io/$(gcloud config get-value project)
82106
# create a gke cluster
83107
$ ./hack/create-gke-cluster.sh -c $CLUSTER
84108

85-
$ DEV_REGISTRY=us.gcr.io/$(gcloud config get-value project) \
109+
$ bazel run //hack/crdbversions:crdbversions -- -operator-image ${DEV_REGISTRY}/cockroach-operator \
110+
-operator-version ${APP_VERSION} -crdb-versions $(PWD)/crdb-versions.yaml -repo-root $(PWD)
111+
112+
$ DEV_REGISTRY=${DEV_REGISTRY} \
86113
K8S_CLUSTER=$(kubectl config view --minify -o=jsonpath='{.contexts[0].context.cluster}') \
87114
bazel run --stamp --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \
88-
//manifests:install_operator.apply
115+
--define APP_VERSION=${APP_VERSION} //config/default:install.apply
89116
```
90117

91118
There are various examples that can be installed. The files are located in the examples directory.

Makefile

+2-4
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ test/preflight-%: release/generate-bundle
221221
#
222222
.PHONY: dev/build
223223
dev/build: dev/syncdeps
224-
bazel build //...
224+
bazel build //... --define APP_VERSION=$(APP_VERSION)
225225

226226
.PHONY: dev/fmt
227227
dev/fmt:
@@ -280,17 +280,15 @@ dev/down:
280280
#
281281
.PHONY: k8s/apply
282282
k8s/apply:
283-
K8S_CLUSTER=gke_$(GCP_PROJECT)_$(GCP_ZONE)_$(CLUSTER_NAME) \
284283
DEV_REGISTRY=$(DEV_REGISTRY) \
285284
bazel run --stamp --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \
286285
//config/default:install.apply \
287286
--define APP_VERSION=$(APP_VERSION)
288287

289288
.PHONY: k8s/delete
290289
k8s/delete:
291-
K8S_CLUSTER=gke_$(GCP_PROJECT)_$(GCP_ZONE)_$(CLUSTER_NAME) \
292290
DEV_REGISTRY=$(DEV_REGISTRY) \
293-
bazel run --stamp --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \
291+
bazel run --stamp --incompatible_use_cc_configure_from_rules_cc \
294292
//config/default:install.delete \
295293
--define APP_VERSION=$(APP_VERSION)
296294

WORKSPACE

+16-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ go_dependencies()
6969
######################################
7070
http_archive(
7171
name = "io_bazel_rules_docker",
72-
sha256 = "1f4e59843b61981a96835dc4ac377ad4da9f8c334ebe5e0bb3f58f80c09735f4",
73-
strip_prefix = "rules_docker-0.19.0",
74-
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.19.0/rules_docker-v0.19.0.tar.gz"],
72+
sha256 = "92779d3445e7bdc79b961030b996cb0c91820ade7ffa7edca69273f404b085d5",
73+
strip_prefix = "rules_docker-0.20.0",
74+
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.20.0/rules_docker-v0.20.0.tar.gz"],
7575
)
7676

7777
load(
@@ -103,6 +103,19 @@ container_pull(
103103
tag = "latest",
104104
)
105105

106+
http_archive(
107+
name = "rules_pkg",
108+
sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
109+
urls = [
110+
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
111+
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
112+
],
113+
)
114+
115+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
116+
117+
rules_pkg_dependencies()
118+
106119
################################
107120
# Load rules_k8s and configure #
108121
################################

cmd/cockroach-operator/BUILD.bazel

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
22
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
33
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
4-
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
4+
load("@rules_pkg//:pkg.bzl", "pkg_tar")
55
load("@io_bazel_rules_docker//docker/util:run.bzl", "container_run_and_commit_layer")
66

77
go_library(
@@ -55,6 +55,7 @@ container_run_and_commit_layer(
5555

5656
container_image(
5757
name = "ubi_base_image",
58+
architecture = "amd64",
5859
# References container_pull from WORKSPACE
5960
base = "@redhat_ubi_minimal//image",
6061
labels = {

config/default/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ k8s_deploy(
3232
name = "image",
3333
images = {
3434
# when running locally, use the image from the local codebase
35-
"cockroachdb/cockroach-operator:$(APP_VERSION)": "//cmd/cockroach-operator:operator_image",
35+
"cockroach-operator:$(APP_VERSION)": "//cmd/cockroach-operator:operator_image",
3636
},
3737
resolver_args = ["--allow_unused_images"],
3838
template = ":manifest",

config/templates/deployment_image.yaml.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ spec:
2424
spec:
2525
containers:
2626
- name: cockroach-operator
27-
image: cockroachdb/cockroach-operator:{{.OperatorVersion}}
27+
image: {{.OperatorImage}}:{{.OperatorVersion}}
2828
env:
2929
{{- range .CrdbVersions}}
3030
{{- /*

hack/bin/BUILD.bazel

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ genrule(
4242
name = "fetch_preflight",
4343
srcs = select({
4444
":k8": ["@preflight_linux//file"],
45+
":m1": ["@preflight_linux//file"],
46+
":darwin": ["@preflight_linux//file"],
4547
}),
4648
outs = ["preflight"],
4749
cmd = "cp $(SRCS) $@",
@@ -75,8 +77,8 @@ genrule(
7577
genrule(
7678
name = "io_kubernetes_kube-apiserver",
7779
srcs = select({
78-
":m1": ["@kube-apiserver_darwin_amd64//file"],
79-
":darwin": ["@kube-apiserver_darwin_amd64//file"],
80+
":m1": ["@kube-apiserver_linux_amd64//file"],
81+
":darwin": ["@kube-apiserver_linux_amd64//file"],
8082
":k8": ["@kube-apiserver_linux_amd64//file"],
8183
}),
8284
outs = ["kube-apiserver"],

hack/build/repos.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -5336,8 +5336,8 @@ def _go_dependencies():
53365336
build_file_generation = "on",
53375337
build_file_proto_mode = "disable",
53385338
importpath = "gopkg.in/yaml.v3",
5339-
sum = "h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=",
5340-
version = "v3.0.0-20210107192922-496545a6307b",
5339+
sum = "h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=",
5340+
version = "v3.0.0",
53415341
)
53425342
go_repository(
53435343
name = "io_etcd_go_bbolt",

hack/common.sh

+21-6
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,22 @@ command -v kubectl >/dev/null 2>&1 || { \
2828
command -v kustomize >/dev/null 2>&1 || { \
2929
echo >&2 "I require kustomize but it's not installed. Aborting."; exit 1; }
3030

31-
usage() { echo "Usage: $0 [-c <cluster name>]" 1>&2; exit 1; }
31+
usage() { echo "Usage: $0 [-c <cluster name> -r <REGION> -z <ZONE>]" 1>&2; exit 1; }
3232
# parse -c flag for the CLUSTER_NAME using getopts
33-
while getopts ":c:i:" opt; do
33+
while getopts ":c:i:z:r:" opt; do
3434
case ${opt} in
3535
c)
3636
CLUSTER_NAME=$OPTARG
3737
;;
3838
i)
3939
IMAGE_NAME=$OPTARG
4040
;;
41+
z)
42+
ZONE=$OPTARG
43+
;;
44+
r)
45+
REGION=$OPTARG
46+
;;
4147
\?)
4248
echo "Invalid flag on command line: $OPTARG" 1>&2
4349
;;
@@ -55,20 +61,29 @@ if [ -z "${CLUSTER_NAME}" ]; then
5561
usage
5662
fi
5763

58-
# Get the default zone and use it or die
59-
ZONE=$(gcloud config get-value compute/zone)
64+
# If user did not pass in -z flag then get the default zone and use it or die
6065
if [ -z "${ZONE}" ]; then
66+
# Get the default zone and use it or die
67+
ZONE=$(gcloud config get-value compute/zone)
68+
if [ -z "${ZONE}" ]; then
6169
echo "gcloud cli must be configured with a default zone." 1>&2
6270
echo "run 'gcloud config set compute/zone ZONE'." 1>&2
6371
echo "replace 'ZONE' with the zone name like us-west1-a." 1>&2
72+
echo "Or provide 'ZONE' as input to script as follows:" 1>&2
73+
usage
6474
exit 1;
75+
fi
6576
fi
6677

67-
#Get the default region and use it or die
68-
REGION=$(gcloud config get-value compute/region)
78+
#If user did not pass in -r flag then get the default region and use it or die
6979
if [ -z "${REGION}" ]; then
80+
REGION=$(gcloud config get-value compute/region)
81+
if [ -z "${REGION}" ]; then
7082
echo "gcloud cli must be configured with a default region." 1>&2
7183
echo "run 'gcloud config set compute/region REGION'." 1>&2
7284
echo "replace 'REGION' with the region name like us-west1." 1>&2
85+
echo "Or provide 'REGION' as input to script as follows:" 1>&2
86+
usage
7387
exit 1;
88+
fi
7489
fi

hack/crdbversions/main.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type crdbVersion struct {
5959
type templateData struct {
6060
CrdbVersions []crdbVersion
6161
LatestStableCrdbVersion string
62+
OperatorImage string
6263
OperatorVersion string
6364
GeneratedWarning string
6465
Year string
@@ -68,6 +69,7 @@ func main() {
6869
log.SetFlags(0)
6970
crdbVersionsFile := flag.String("crdb-versions", "", "YAML file with CRDB versions")
7071
operatorVersion := flag.String("operator-version", "", "Current operator version")
72+
operatorImage := flag.String("operator-image", "cockroachdb/cockroach-operator", "Current operator image")
7173
repoRoot := flag.String("repo-root", "", "Git repository root")
7274
flag.Parse()
7375

@@ -87,7 +89,7 @@ func main() {
8789
log.Fatalf("Cannot read versions file: %s", err)
8890
}
8991

90-
data, err := generateTemplateData(vs, *operatorVersion)
92+
data, err := generateTemplateData(vs, *operatorVersion, *operatorImage)
9193
if err != nil {
9294
log.Fatalf("Cannot generate template data: %s", err)
9395
}
@@ -139,10 +141,11 @@ func readCrdbVersions(r io.Reader) ([]crdbVersion, error) {
139141
return versions.CrdbVersions, nil
140142
}
141143

142-
func generateTemplateData(crdbVersions []crdbVersion, operatorVersion string) (templateData, error) {
144+
func generateTemplateData(crdbVersions []crdbVersion, operatorVersion, operatorImage string) (templateData, error) {
143145
var data templateData
144146
data.Year = fmt.Sprint(time.Now().Year())
145147
data.OperatorVersion = operatorVersion
148+
data.OperatorImage = operatorImage
146149
data.CrdbVersions = crdbVersions
147150

148151
latestStable := crdbVersions[len(crdbVersions)-1].Tag

hack/crdbversions/main_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestGenerateTemplateData(t *testing.T) {
6565
crdbVersions = append(crdbVersions, crdbVersion{Tag: r})
6666
}
6767

68-
data, err := generateTemplateData(crdbVersions, "2.0.1")
68+
data, err := generateTemplateData(crdbVersions, "2.0.1", "cockroachdb/cockroach-operator")
6969
require.NoError(t, err)
7070
require.Len(t, data.CrdbVersions, len(crdbVersions))
7171
require.Equal(t, "1.2.3", data.LatestStableCrdbVersion)

hack/create-gke-cluster.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ CLUSTER_NAME=""
2929
# TODO maybe set default zone?
3030
ZONE=""
3131

32+
REGION=""
33+
3234
# shellcheck disable=SC1090
3335
source "$ROOT"/common.sh
3436
# shellcheck disable=SC1090
@@ -39,7 +41,7 @@ enable-service compute.googleapis.com
3941
enable-service container.googleapis.com
4042

4143
GKE_VERSION=$(gcloud container get-server-config \
42-
--format="value(validMasterVersions[0])")
44+
--format="value(validMasterVersions[0])" --region=$REGION)
4345

4446
# Get a comma separated list of zones from the default region
4547
ZONESINREGION=""

hack/dev.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CLUSTER_NAME="dev"
2222
NODE_IMAGE="rancher/k3s:v1.23.3-k3s1"
2323
REGISTRY_NAME="registry.localhost"
2424
REGISTRY_PORT=5000
25+
DEV_REGISTRY="${REGISTRY_NAME}:${REGISTRY_PORT}"
2526

2627
main() {
2728
case "${1:-}" in
@@ -45,8 +46,10 @@ install_operator() {
4546
# Can't seem to figure out how to leverage the stamp variables here. So for
4647
# now I've added a defined make variable which can be used for substitution
4748
# in //config/default/BUILD.bazel.
49+
# ${REGISTRY_NAME} must be mapped to localhost or 127.0.0.1 to push the image to the k3d registry.
50+
bazel run //hack/crdbversions:crdbversions -- -operator-image ${DEV_REGISTRY}/cockroach-operator -operator-version ${APP_VERSION} -crdb-versions $(PWD)/crdb-versions.yaml -repo-root $(PWD)
4851
K8S_CLUSTER="k3d-${CLUSTER_NAME}" \
49-
DEV_REGISTRY="${REGISTRY_NAME}:${REGISTRY_PORT}" \
52+
DEV_REGISTRY="${DEV_REGISTRY}" \
5053
bazel run \
5154
--stamp \
5255
--platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 \

0 commit comments

Comments
 (0)