Skip to content

Commit d4760ac

Browse files
authored
Replace kind with k3d (#849)
When running some tests I was able to reduce the time they take to run quite a bit by using k3d rather than kind. In smaller tests, this was significant, for example the smoketests ran in less than half the time. On larger tests, it shaves a couple of minutes off (on the ~10 I ran anyways). Pressumably this is just the difference in the time it takes to start/stop k3d vs kind. To make this all work, I had to create a custom kubetest2 deployer for k3d. It's in _e2e/kubetest2-k3d_ and largely is a copy of the kind deployer updated to use k3d instead.
1 parent 9039b0b commit d4760ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+656
-587
lines changed

.github/workflows/e2e-kind-create.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ jobs:
3737
path: "~/.cache/bazel"
3838
key: bazel
3939

40-
- name: End-to-end (kind)
41-
run: make test/e2e/kind-create
40+
- name: End-to-end (k3d)
41+
run: make test/e2e/k3d-create

.github/workflows/e2e-kind-decommission.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ jobs:
3737
path: "~/.cache/bazel"
3838
key: bazel
3939

40-
- name: End-to-end (kind)
41-
run: make test/e2e/kind-decommission
40+
- name: End-to-end (k3d)
41+
run: make test/e2e/k3d-decommission

.github/workflows/e2e-kind-upgrades.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ jobs:
3737
path: "~/.cache/bazel"
3838
key: bazel
3939

40-
- name: End-to-end (kind)
41-
run: make test/e2e/kind-upgrades
40+
- name: End-to-end (k3d)
41+
run: make test/e2e/k3d-upgrades

.github/workflows/e2e-kind-upgradessha256.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ jobs:
3737
path: "~/.cache/bazel"
3838
key: bazel
3939

40-
- name: End-to-end (kind)
41-
run: make test/e2e/kind-upgradessha256
40+
- name: End-to-end (k3d)
41+
run: make test/e2e/k3d-upgradessha256

.github/workflows/e2e-kind-versionchecker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ jobs:
3838
key: bazel
3939

4040
- name: End-to-end (kind)
41-
run: make test/e2e/kind-versionchecker
41+
run: make test/e2e/k3d-versionchecker

.github/workflows/nightly-smoketest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
strategy:
3232
matrix:
3333
# supported Kubenetes versions
34-
NODE_VERSION: [1.18.19, 1.19.11, 1.20.7, 1.21.2, 1.22.1]
34+
NODE_VERSION: [1.19.16, 1.20.15, 1.21.9, 1.22.6, 1.23.3]
3535
steps:
3636
- uses: actions/checkout@v3
3737
- name: Mount bazel cache

DEVELOPER.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ See: https://docs.bazel.build/versions/master/install.html
66

77
Take a look at the [Makefile](https://github.com/cockroachdb/cockroach-operator/blob/master/Makefile) for various
88
targets you can run. The e2e testing requires a container engine like docker running as it starts a K8s cluster with
9-
Kind. The Makefile is simply a wrapper for bazel commands and does not have any build functionality in it.
9+
[k3d]. The Makefile is simply a wrapper for bazel commands and does not have any build functionality in it.
1010

1111
You will also need kubectl and a running Kubernetes cluster to run the k8s targets like `make k8s/apply`.
1212

1313
Bazel has been primarily tested on Linux but "should" run on macOS as well. Windows at this time has not been tested.
1414

15-
TODO: notes on python configuration for the host.
16-
1715
If you are new to Bazel take a look at the Workspace file, as it lays out which rule sets we are using, such as docker
1816
rules and k8s rules. The Makefile notes below talk about the different target groups that run various bazel commands.
1917

@@ -39,25 +37,24 @@ Please run the testing targets locally before you push a PR.
3937

4038
## Running Locally
4139

42-
We use [kind] to run the operator in a local environment. This can provide a faster feedback cycle while developing
40+
We use [k3d] to run the operator in a local environment. This can provide a faster feedback cycle while developing
4341
since there's no need to set up a remote GKE/OpenShift cluster.
4442

45-
[kind]: https://kind.sigs.k8s.io/
43+
[k3d]: https://k3d.io
4644

4745
**make dev/up**
4846

4947
This command will get everything set up for you to begin testing out the operator. Specifically it will:
5048

51-
* Start a local docker registry (via docker run) and configure it to work with kind/K8s
52-
* Start a kind cluster named test (context=kind-test)
49+
* Start a k3d cluster named test (context=k3d-test) with a managed docker registry
5350
* Install the CRDs
54-
* Build a docker image and publish it to the local registry
51+
* Build a docker image and publish it to the k3d registry
5552
* Deploy the operator and wait for it to be available
5653
* Ensure your shell is configured to use the new cluster (kube context)
5754

5855
**make dev/down**
5956

60-
Tears down the kind cluster.
57+
Tears down the k3d cluster.
6158

6259
## Testing CR Database
6360

@@ -108,8 +105,8 @@ When you have removed your example and the persitent volumes you can use the fol
108105
1. If you do not have a GKE cluster we have a helper script `./hack/create-gke-cluster.sh -c test`.
109106
1. Locate the latest released tag here https://github.com/cockroachdb/cockroach-operator/tags
110107
1. Clone the tag `git clone --depth 1 --branch <tag_name> https://github.com/cockroachdb/cockroach-operator`
111-
1. Execute `kubectl apply -f config/crd/bases/crdb.cockroachlabs.com_crdbclusters.yaml`
112-
1. Execute `kubectl apply -f manifests/operator.yaml`
108+
1. Execute `kubectl apply -f install/crds.yaml`
109+
1. Execute `kubectl apply -f install/operator.yaml`
113110
1. Check that the operator has deployed properly
114111

115112
The examples directory contains various examples, for example you can run `kubectl apply -f examples/example.yaml`.

Makefile

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ test/verify:
6060
test/lint:
6161
bazel run //hack:verify-gofmt
6262

63-
# NODE_VERSION refers the to version of the kindest/node image. E.g. 1.22.1
63+
# NODE_VERSION refers the to patch version of Kubernetes (e.g. 1.22.6)
6464
.PHONY: test/smoketest
6565
test/smoketest:
6666
@bazel run //hack/smoketest -- -dir $(PWD) -version $(NODE_VERSION)
@@ -71,10 +71,9 @@ test/smoketest:
7171
test/e2e-short:
7272
bazel test //e2e/... --test_arg=--test.short
7373

74-
#
7574
# End to end testing targets
7675
#
77-
# kind: use make test/e2e/kind
76+
# k3d: use make test/e2e/k3d
7877
# gke: use make test/e2e/gke
7978
#
8079
# kubetest2 binaries from the kubernetes testing team is used
@@ -83,31 +82,32 @@ test/e2e-short:
8382
# Once the repo releases binaries we should vendor the tag or
8483
# download the built binaries.
8584

86-
# This target is used by kubetest2-tester-exec when running a kind test
87-
# This target exportis the kubeconfig from kind and then runs
88-
# k8s:k8s -type kind which checks to see if kind is up and running.
85+
# This target is used by kubetest2-tester-exec when running a k3d test
86+
# It run k8s:k8s -type k3d which checks to see if k3d is up and running.
8987
# Then bazel e2e testing is run.
90-
# An example of calling this is using make test/e2e/testrunner-kind-upgrades
91-
test/e2e/testrunner-kind-%: PACKAGE=$*
92-
test/e2e/testrunner-kind-%:
93-
bazel-bin/hack/bin/kind export kubeconfig --name $(CLUSTER_NAME)
94-
bazel run //hack/k8s:k8s -- -type kind
88+
# An example of calling this is using make test/e2e/testrunner-k3d-upgrades
89+
test/e2e/testrunner-k3d-%: PACKAGE=$*
90+
test/e2e/testrunner-k3d-%:
91+
bazel run //hack/k8s:k8s -- -type k3d
9592
bazel test --stamp //e2e/$(PACKAGE)/... --test_arg=-test.v --test_arg=-test.parallel=8 --test_arg=parallel=true
9693

97-
# Use this target to run e2e tests using a kind k8s cluster.
98-
# This target uses kind to start a k8s cluster and runs the e2e tests
94+
# Use this target to run e2e tests using a k3d k8s cluster.
95+
# This target uses k3d to start a k8s cluster and runs the e2e tests
9996
# against that cluster.
100-
# This is the main entrypoint for running the e2e tests on kind.
101-
# This target runs kubetest2 kind that starts a kind cluster
97+
#
98+
# This is the main entrypoint for running the e2e tests on k3d.
99+
# This target runs kubetest2 k3d that starts a k3d cluster
102100
# Then kubetest2 tester exec is run which runs the make target
103-
# test/e2e/testrunner-kind.
101+
# test/e2e/testrunner-k3d.
104102
# After the tests run the cluster is deleted.
105103
# If you need a unique cluster name override CLUSTER_NAME.
106-
test/e2e/kind-%: PACKAGE=$*
107-
test/e2e/kind-%:
108-
bazel build //hack/bin/...
109-
PATH=${PATH}:bazel-bin/hack/bin kubetest2 kind --cluster-name=$(CLUSTER_NAME) \
110-
--up --down -v 10 --test=exec -- make test/e2e/testrunner-kind-$(PACKAGE)
104+
test/e2e/k3d-%: PACKAGE=$*
105+
test/e2e/k3d-%:
106+
bazel build //hack/bin/... //e2e/kubetest2-k3d/...
107+
PATH=bazel-bin/hack/bin:bazel-bin/e2e/kubetest2-k3d/kubetest2-k3d_/:${PATH} \
108+
bazel-bin/hack/bin/kubetest2 k3d \
109+
--cluster-name=$(CLUSTER_NAME) --image rancher/k3s:v1.23.3-k3s1 --servers 3 \
110+
--up --down -v 10 --test=exec -- make test/e2e/testrunner-k3d-$(PACKAGE)
111111

112112
# This target is used by kubetest2-eks to run e2e tests.
113113
.PHONY: test/e2e/testrunner-eks
@@ -118,7 +118,7 @@ test/e2e/testrunner-eks:
118118
bazel test --stamp //e2e/decommission/... --action_env=KUBECONFIG=$(TMPDIR)/$(CLUSTER_NAME)-eks.kubeconfig.yaml
119119

120120
# Use this target to run e2e tests with a eks cluster.
121-
# This target uses kind to start a eks k8s cluster and runs the e2e tests
121+
# This target uses kubetest2 to start a eks k8s cluster and runs the e2e tests
122122
# against that cluster.
123123
.PHONY: test/e2e/eks
124124
test/e2e/eks:
@@ -148,9 +148,9 @@ test/e2e/testrunner-gke:
148148
bazel test --stamp //e2e/decommission/...
149149

150150
# Use this target to run e2e tests with a gke cluster.
151-
# This target uses kind to start a gke k8s cluster and runs the e2e tests
151+
# This target uses kubetest2 to start a gke k8s cluster and runs the e2e tests
152152
# against that cluster.
153-
# This is the main entrypoint for running the e2e tests on gke kind.
153+
# This is the main entrypoint for running the e2e tests on gke.
154154
# This target runs kubetest2 gke that starts a gke cluster
155155
# Then kubetest2 tester exec is run which runs the make target
156156
# test/e2e/testrunner-gke.
@@ -175,7 +175,7 @@ test/e2e/testrunner-openshift:
175175
bazel test --stamp //e2e/decommission/... --action_env=KUBECONFIG=$(HOME)/openshift-$(CLUSTER_NAME)/auth/kubeconfig
176176

177177
# Use this target to run e2e tests with a openshift cluster.
178-
# This target uses kind to start a openshift cluster and runs the e2e tests
178+
# This target uses kubetest2 to start a openshift cluster and runs the e2e tests
179179
# against that cluster. A full TLD is required to creat an openshift clutser.
180180
# This target runs kubetest2 openshift that starts a openshift cluster
181181
# Then kubetest2 tester exec is run which runs the make target
@@ -257,7 +257,7 @@ dev/syncdeps:
257257
@make dev/syncbazel
258258

259259
.PHONY: dev/up
260-
dev/up:
260+
dev/up: dev/down
261261
@hack/dev.sh up
262262

263263
.PHONY: dev/down

config/templates/example.yaml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
volumeMode: Filesystem
3333
resources:
3434
requests:
35-
# This is intentionally low to make it work on local kind clusters.
35+
# This is intentionally low to make it work on local k3d clusters.
3636
cpu: 500m
3737
memory: 2Gi
3838
limits:

config/templates/smoketest.yaml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
volumeMode: Filesystem
3232
resources:
3333
requests:
34-
# This is intentionally low to make it work on local kind clusters.
34+
# This is intentionally low to make it work on local k3d clusters.
3535
cpu: 300m
3636
memory: 300Mi
3737
limits:

e2e/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ filegroup(
2121
"//e2e/create:all-srcs",
2222
"//e2e/decommission:all-srcs",
2323
"//e2e/kubetest2-eks:all-srcs",
24+
"//e2e/kubetest2-k3d:all-srcs",
2425
"//e2e/kubetest2-openshift:all-srcs",
2526
"//e2e/openshift:all-srcs",
2627
"//e2e/pvcresize:all-srcs",

e2e/create/create_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestCreateInsecureCluster(t *testing.T) {
6363

6464
builder := testutil.NewBuilder("crdb").WithNodeCount(3).
6565
WithImage(e2e.MajorVersion).WithClusterLogging("logging-configmap").
66-
WithPVDataStore("1Gi", "standard" /* default storage class in KIND */)
66+
WithPVDataStore("1Gi")
6767

6868
steps := testutil.Steps{
6969
{
@@ -103,7 +103,7 @@ func TestCreatesSecureCluster(t *testing.T) {
103103

104104
builder := testutil.NewBuilder("crdb").WithNodeCount(3).WithTLS().
105105
WithImage(e2e.MajorVersion).
106-
WithPVDataStore("1Gi", "standard" /* default storage class in KIND */)
106+
WithPVDataStore("1Gi")
107107

108108
steps := testutil.Steps{
109109
{
@@ -159,7 +159,7 @@ func TestCreateSecureClusterWithInvalidVersion(t *testing.T) {
159159

160160
builder := testutil.NewBuilder("crdb").WithNodeCount(3).WithTLS().
161161
WithImage(testcase.imageVersion).
162-
WithPVDataStore("1Gi", "standard" /* default storage class in KIND */)
162+
WithPVDataStore("1Gi")
163163
if testcase.cockroachVersion != "" {
164164
os.Setenv(relatedImageEnvName, e2e.NonExistentVersion)
165165
builder = builder.WithCockroachDBVersion(testcase.cockroachVersion)
@@ -219,7 +219,7 @@ func TestCreateSecureClusterWithNonCRDBImage(t *testing.T) {
219219

220220
builder := testutil.NewBuilder("crdb").WithNodeCount(3).WithTLS().
221221
WithImage(testcase.imageVersion).
222-
WithPVDataStore("1Gi", "standard" /* default storage class in KIND */)
222+
WithPVDataStore("1Gi")
223223

224224
if testcase.cockroachVersion != "" {
225225
os.Setenv(relatedImageEnvName, e2e.InvalidImage)
@@ -265,7 +265,7 @@ func TestCreateSecureClusterWithCRDBVersionSet(t *testing.T) {
265265
sb.StartManager(subT, controller.InitClusterReconcilerWithLogger(testLog))
266266

267267
builder := testutil.NewBuilder("crdb").WithNodeCount(3).WithTLS().
268-
WithPVDataStore("1Gi", "standard" /* default storage class in KIND */).
268+
WithPVDataStore("1Gi").
269269
WithCockroachDBVersion(crdbVersion).WithImageObject(nil)
270270

271271
require.NoError(subT, sb.Create(builder.Cr()))

e2e/decommission/decommission_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestDecommissionFunctionalityWithPrune(t *testing.T) {
6262
WithNodeCount(4).
6363
WithTLS().
6464
WithImage(e2e.MajorVersion).
65-
WithPVDataStore("1Gi", "standard" /* default storage class in KIND */)
65+
WithPVDataStore("1Gi")
6666

6767
testutil.Steps{
6868
{
@@ -124,7 +124,7 @@ func TestDecommissionFunctionality(t *testing.T) {
124124
WithNodeCount(4).
125125
WithTLS().
126126
WithImage(e2e.MajorVersion).
127-
WithPVDataStore("1Gi", "standard" /* default storage class in KIND */)
127+
WithPVDataStore("1Gi")
128128

129129
testutil.Steps{
130130
{

e2e/kubetest2-k3d/BUILD.bazel

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["main.go"],
6+
importpath = "github.com/cockroachdb/cockroach-operator/e2e/kubetest2-k3d",
7+
visibility = ["//visibility:private"],
8+
deps = [
9+
"//e2e/kubetest2-k3d/deployer:go_default_library",
10+
"@io_k8s_sigs_kubetest2//pkg/app:go_default_library",
11+
],
12+
)
13+
14+
go_binary(
15+
name = "kubetest2-k3d",
16+
embed = [":go_default_library"],
17+
visibility = ["//visibility:public"],
18+
)
19+
20+
filegroup(
21+
name = "package-srcs",
22+
srcs = glob(["**"]),
23+
tags = ["automanaged"],
24+
visibility = ["//visibility:private"],
25+
)
26+
27+
filegroup(
28+
name = "all-srcs",
29+
srcs = [
30+
":package-srcs",
31+
"//e2e/kubetest2-k3d/deployer:all-srcs",
32+
],
33+
tags = ["automanaged"],
34+
visibility = ["//visibility:public"],
35+
)

e2e/kubetest2-k3d/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# kubetest2-k3d
2+
3+
This package providers a deployer interface for kubetest2 that uses k3d. It is largely based on the kubetest2-kind
4+
package, but updated to use k3d for the underlying cluster.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = [
6+
"build.go",
7+
"deployer.go",
8+
"down.go",
9+
"dumplogs.go",
10+
"up.go",
11+
],
12+
importpath = "github.com/cockroachdb/cockroach-operator/e2e/kubetest2-k3d/deployer",
13+
visibility = ["//visibility:public"],
14+
deps = [
15+
"@com_github_octago_sflags//gen/gpflag:go_default_library",
16+
"@com_github_spf13_pflag//:go_default_library",
17+
"@io_k8s_klog//:go_default_library",
18+
"@io_k8s_sigs_kubetest2//pkg/exec:go_default_library",
19+
"@io_k8s_sigs_kubetest2//pkg/metadata:go_default_library",
20+
"@io_k8s_sigs_kubetest2//pkg/process:go_default_library",
21+
"@io_k8s_sigs_kubetest2//pkg/types:go_default_library",
22+
],
23+
)
24+
25+
filegroup(
26+
name = "package-srcs",
27+
srcs = glob(["**"]),
28+
tags = ["automanaged"],
29+
visibility = ["//visibility:private"],
30+
)
31+
32+
filegroup(
33+
name = "all-srcs",
34+
srcs = [":package-srcs"],
35+
tags = ["automanaged"],
36+
visibility = ["//visibility:public"],
37+
)

0 commit comments

Comments
 (0)