Skip to content

Commit 5e4a7e0

Browse files
TAM360taimoor-mirza29
authored andcommitted
feat(dev-container): ✨ Devcontainer configuration file
Add Go templates for scaffolding DevContainer related configuration files in a new Kubebuilder project. refactor(dev-container): Add separate post-create.sh script. refactor(dev-container): Use separate shell post create shell script in the container. fix(dev-container): Remove redudant /bin/bash field. :seedling: Bump github.com/onsi/ginkgo/v2 from 2.19.0 to 2.19.1 Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.19.0 to 2.19.1. - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](onsi/ginkgo@v2.19.0...v2.19.1) --- updated-dependencies: - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> :seedling: Bump github.com/onsi/gomega from 1.33.1 to 1.34.1 Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.33.1 to 1.34.1. - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](onsi/gomega@v1.33.1...v1.34.1) --- updated-dependencies: - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> fix: typo in designs template Signed-off-by: Gabriele Quaresima <[email protected]> refactor(.devcontainer/Dockerfile): Use Go to install Kind binary. fix(.devcontainer): 🐛 Paas host network & update post-install script path. Use Host network to connect with the Host OS's Docker network. Also, execute the post-install.sh script from .devcontainer sub-directory, not the root. refactor(.devcontainer): Change go's version to 1.22.0. refactor(.devcontainer/Dockefile): Download Kubebuilder binary directly. refactor(.devcontainer/post-install.sh) Remove Makefile command. refactor(.devcontainer): Add check for verifying the existing Kind cluster. refactor(.devcontainer): Remove debug flag from post-install.sh fix(.devcontainer): Change interpreter from sh to bash in post-install.sh. refactor(templates): Add template for generating .devcontainer settings. ⚠️ (cleanup/fix): ImplementWebhooks method should only be used by the e2e tests and should be under its package (kubernetes-sigs#4065) (cleanup/fix): ImplementWebhooks method should only be used by the e2e tests and should be under its package (cleanup): cleanup tests for plugin/util functions pkg/plugin/utils: add tests to cover funcs 🐛 (go/v4): add missing cancel context to controller's suite-test (kubernetes-sigs#4067) fix: add missing cancel context to controller's suite-test Upgrade the muilt-version sample to the latest :seedling: Bump github.com/onsi/ginkgo/v2 from 2.19.1 to 2.20.0 Bumps [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo) from 2.19.1 to 2.20.0. - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](onsi/ginkgo@v2.19.1...v2.20.0) --- updated-dependencies: - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> 📖 docs:samples:cronjob: change makefile to generate the CRD without description to allow apply CRDs (kubernetes-sigs#4075) docs:samples:cronjob: fix makefile to generate the CRD with less description 🌱 Cleanup hack generate docs by removing code duplication (kubernetes-sigs#4076) (cleanup) hack docs fix(devcontainer.go): Resolve golangci-lint related issues. fix(devcontainer.go): Use bash command instead of '.' due to permission issuses. chore: Remove testDev Container files. docs(devcontainer): Generate documentation.
1 parent eb97367 commit 5e4a7e0

File tree

92 files changed

+1483
-5233
lines changed

Some content is hidden

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

92 files changed

+1483
-5233
lines changed

designs/template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
| Authors | Creation Date | Status | Extra |
22
|---------------|---------------|-------------|---|
3-
| @name | date | Implementeble | - |
3+
| @name | date | Implementable | - |
44

55
Title of the Design/Proposal
66
===================
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Build the manager binary
2+
# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon):
3+
# 1, 1.19, 1.18, 1-bullseye, 1.19-bullseye, 1.18-bullseye, 1-buster, 1.19-buster, 1.18-buster
4+
ARG TAG=1.22
5+
FROM golang:${TAG}
6+
7+
COPY post-install.sh .
8+
9+
# Install dependencies
10+
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
11+
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
12+
13+
RUN go install sigs.k8s.io/[email protected] && \
14+
curl -o kubebuilder \
15+
-L https://github.com/kubernetes-sigs/kubebuilder/releases/latest/download/kubebuilder_linux_amd64 && \
16+
chmod +x kubebuilder && \
17+
mv kubebuilder /usr/local/bin/ && \
18+
chmod +x post-install.sh
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-in-docker
3+
{
4+
"name": "Kubebuilder DevContainer",
5+
"build": {
6+
"dockerfile": "./Dockerfile",
7+
"context": "."
8+
},
9+
10+
"features": {
11+
"ghcr.io/devcontainers/features/docker-in-docker:2.11.0": {
12+
"moby": true,
13+
"azureDnsAutoDetection": true,
14+
"version": "latest"
15+
},
16+
"ghcr.io/devcontainers/features/common-utils:2": {
17+
"installZsh": false,
18+
"upgradePackages": true,
19+
"username": "devcontainer",
20+
"userUid": "1001",
21+
"userGid": "1001"
22+
},
23+
"ghcr.io/devcontainers/features/git:1": {
24+
"ppa": true,
25+
"version": "system"
26+
},
27+
"ghcr.io/devcontainers/features/go:1": {
28+
"version": "1.22.0"
29+
}
30+
},
31+
32+
"runArgs": ["--network=host"],
33+
// "forwardPorts": [],
34+
35+
"postCreateCommand": "bash ./.devcontainer/post-install.sh"
36+
37+
// Configure tool-specific properties.
38+
// "customizations": {},
39+
40+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
41+
// "remoteUser": "root"
42+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -e
3+
4+
go version
5+
kubectl version --client
6+
7+
# Check if Kind cluster already exists.
8+
if kubectl cluster-info &>/dev/null; then
9+
echo "Kind cluster already exists."
10+
else
11+
echo "Kind cluster doesn't exist. Creating new cluster...."
12+
kind create cluster
13+
fi
14+
15+
kubectl get nodes -o wide

docs/book/src/cronjob-tutorial/testdata/project/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ help: ## Display this help.
4545

4646
.PHONY: manifests
4747
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
48-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
48+
# Note that the option maxDescLen=0 was added in the default scaffold in order to sort out the issue
49+
# Too long: must have at most 262144 bytes. By using kubectl apply to create / update resources an annotation
50+
# is created by K8s API to store the latest version of the resource ( kubectl.kubernetes.io/last-applied-configuration).
51+
# However, it has a size limit and if the CRD is too big with so many long descriptions as this one it will cause the failure.
52+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4953

5054
.PHONY: generate
5155
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.

docs/book/src/cronjob-tutorial/testdata/project/api/v1/webhook_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ var _ = BeforeSuite(func() {
138138
})
139139

140140
var _ = AfterSuite(func() {
141-
cancel()
142141
By("tearing down the test environment")
142+
cancel()
143143
err := testEnv.Stop()
144144
Expect(err).NotTo(HaveOccurred())
145145
})

docs/book/src/cronjob-tutorial/testdata/project/config/crd/bases/batch.tutorial.kubebuilder.io_cronjobs.yaml

Lines changed: 0 additions & 4896 deletions
Large diffs are not rendered by default.

docs/book/src/cronjob-tutorial/testdata/project/internal/controller/suite_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ var (
6161
cfg *rest.Config
6262
k8sClient client.Client // You'll be using this client in your tests.
6363
testEnv *envtest.Environment
64-
ctx context.Context
65-
cancel context.CancelFunc
6664
)
65+
var ctx context.Context
66+
var cancel context.CancelFunc
6767

6868
func TestControllers(t *testing.T) {
6969
RegisterFailHandler(Fail)
@@ -169,8 +169,8 @@ You won't need to touch these.
169169
*/
170170

171171
var _ = AfterSuite(func() {
172-
cancel()
173172
By("tearing down the test environment")
173+
cancel()
174174
err := testEnv.Stop()
175175
Expect(err).NotTo(HaveOccurred())
176176
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Build the manager binary
2+
# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon):
3+
# 1, 1.19, 1.18, 1-bullseye, 1.19-bullseye, 1.18-bullseye, 1-buster, 1.19-buster, 1.18-buster
4+
ARG TAG=1.22
5+
FROM golang:${TAG}
6+
7+
COPY post-install.sh .
8+
9+
# Install dependencies
10+
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
11+
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
12+
13+
RUN go install sigs.k8s.io/[email protected] && \
14+
curl -o kubebuilder \
15+
-L https://github.com/kubernetes-sigs/kubebuilder/releases/latest/download/kubebuilder_linux_amd64 && \
16+
chmod +x kubebuilder && \
17+
mv kubebuilder /usr/local/bin/ && \
18+
chmod +x post-install.sh
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-in-docker
3+
{
4+
"name": "Kubebuilder DevContainer",
5+
"build": {
6+
"dockerfile": "./Dockerfile",
7+
"context": "."
8+
},
9+
10+
"features": {
11+
"ghcr.io/devcontainers/features/docker-in-docker:2.11.0": {
12+
"moby": true,
13+
"azureDnsAutoDetection": true,
14+
"version": "latest"
15+
},
16+
"ghcr.io/devcontainers/features/common-utils:2": {
17+
"installZsh": false,
18+
"upgradePackages": true,
19+
"username": "devcontainer",
20+
"userUid": "1001",
21+
"userGid": "1001"
22+
},
23+
"ghcr.io/devcontainers/features/git:1": {
24+
"ppa": true,
25+
"version": "system"
26+
},
27+
"ghcr.io/devcontainers/features/go:1": {
28+
"version": "1.22.0"
29+
}
30+
},
31+
32+
"runArgs": ["--network=host"],
33+
// "forwardPorts": [],
34+
35+
"postCreateCommand": "bash ./.devcontainer/post-install.sh"
36+
37+
// Configure tool-specific properties.
38+
// "customizations": {},
39+
40+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
41+
// "remoteUser": "root"
42+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -e
3+
4+
go version
5+
kubectl version --client
6+
7+
# Check if Kind cluster already exists.
8+
if kubectl cluster-info &>/dev/null; then
9+
echo "Kind cluster already exists."
10+
else
11+
echo "Kind cluster doesn't exist. Creating new cluster...."
12+
kind create cluster
13+
fi
14+
15+
kubectl get nodes -o wide

docs/book/src/getting-started/testdata/project/internal/controller/suite_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package controller
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"path/filepath"
2223
"runtime"
@@ -42,6 +43,8 @@ import (
4243
var cfg *rest.Config
4344
var k8sClient client.Client
4445
var testEnv *envtest.Environment
46+
var ctx context.Context
47+
var cancel context.CancelFunc
4548

4649
func TestControllers(t *testing.T) {
4750
RegisterFailHandler(Fail)
@@ -52,6 +55,8 @@ func TestControllers(t *testing.T) {
5255
var _ = BeforeSuite(func() {
5356
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))
5457

58+
ctx, cancel = context.WithCancel(context.TODO())
59+
5560
By("bootstrapping test environment")
5661
testEnv = &envtest.Environment{
5762
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
@@ -85,6 +90,7 @@ var _ = BeforeSuite(func() {
8590

8691
var _ = AfterSuite(func() {
8792
By("tearing down the test environment")
93+
cancel()
8894
err := testEnv.Stop()
8995
Expect(err).NotTo(HaveOccurred())
9096
})

docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ linters:
2222
- dupl
2323
- errcheck
2424
- exportloopref
25+
- ginkgolinter
2526
- goconst
2627
- gocyclo
2728
- gofmt
@@ -33,8 +34,14 @@ linters:
3334
- misspell
3435
- nakedret
3536
- prealloc
37+
- revive
3638
- staticcheck
3739
- typecheck
3840
- unconvert
3941
- unparam
4042
- unused
43+
44+
linters-settings:
45+
revive:
46+
rules:
47+
- name: comment-spacings

docs/book/src/multiversion-tutorial/testdata/project/Makefile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,16 @@ $(LOCALBIN):
152152

153153
## Tool Binaries
154154
KUBECTL ?= kubectl
155-
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
156-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
157-
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
158-
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
155+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
156+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
157+
ENVTEST ?= $(LOCALBIN)/setup-envtest
158+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
159159

160160
## Tool Versions
161-
KUSTOMIZE_VERSION ?= v5.4.1
161+
KUSTOMIZE_VERSION ?= v5.4.2
162162
CONTROLLER_TOOLS_VERSION ?= v0.15.0
163163
ENVTEST_VERSION ?= release-0.18
164-
GOLANGCI_LINT_VERSION ?= v1.57.2
164+
GOLANGCI_LINT_VERSION ?= v1.59.1
165165

166166
.PHONY: kustomize
167167
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -181,18 +181,20 @@ $(ENVTEST): $(LOCALBIN)
181181
.PHONY: golangci-lint
182182
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
183183
$(GOLANGCI_LINT): $(LOCALBIN)
184-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
184+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
185185

186186
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
187-
# $1 - target path with name of binary (ideally with version)
187+
# $1 - target path with name of binary
188188
# $2 - package url which can be installed
189189
# $3 - specific version of package
190190
define go-install-tool
191-
@[ -f $(1) ] || { \
191+
@[ -f "$(1)-$(3)" ] || { \
192192
set -e; \
193193
package=$(2)@$(3) ;\
194194
echo "Downloading $${package}" ;\
195+
rm -f $(1) || true ;\
195196
GOBIN=$(LOCALBIN) go install $${package} ;\
196-
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
197-
}
197+
mv $(1) $(1)-$(3) ;\
198+
} ;\
199+
ln -sf $(1)-$(3) $(1)
198200
endef

docs/book/src/multiversion-tutorial/testdata/project/api/v1/webhook_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ var _ = BeforeSuite(func() {
138138
})
139139

140140
var _ = AfterSuite(func() {
141-
cancel()
142141
By("tearing down the test environment")
142+
cancel()
143143
err := testEnv.Stop()
144144
Expect(err).NotTo(HaveOccurred())
145145
})

docs/book/src/multiversion-tutorial/testdata/project/api/v2/webhook_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ var _ = BeforeSuite(func() {
138138
})
139139

140140
var _ = AfterSuite(func() {
141-
cancel()
142141
By("tearing down the test environment")
142+
cancel()
143143
err := testEnv.Stop()
144144
Expect(err).NotTo(HaveOccurred())
145145
})

0 commit comments

Comments
 (0)