Skip to content

Commit 570eb09

Browse files
committed
feat(devcontainer): ✨ Devcontainer configuration file for
kubebuilder 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 (#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 (#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 (#4075) docs:samples:cronjob: fix makefile to generate the CRD with less description 🌱 Cleanup hack generate docs by removing code duplication (#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. test(devcontainer): Add a GH Action for testing dev-container build. test(devcontainer): Downgrade GH Runner to 20.04 Ubuntu. refactor(templates): Remove commented settings, and fix licencse year. ci(devcontainer): Remove commented code. sparkles: Add support to k8s 1.31 and upgrade dependencies (#4080) Add support to k8s 1.31 Upgrade controller-gen used to generate the docs from 0.15.0 to 0.16.1 docs: improve and make clear info about setup envtest and its binaries ✨ upgrade kustomize from v5.4.2 to v5.4.3 (#4084) upgrade kustomize from v5.4.2 to v5.4.3 refactor(devcontainer): Remove Dockerfile template. docs(devcontainer): Update test data files. ci(devcontainer): Run CI workflow on everpy PR, and push. chore: Fix linting typo. docs(devcontainer): Update test data files. ci(devcontainer): Run CI workflow on everpy PR, and push. chore: Fix linting typo. fix(devcontainer): Add license details in post-install.sh. ci(devcontainer): Update runner image. docs(devcontainer): Regenerate docs with license details. ✨ (go/v4): Remove hard-coded license details from the script template. (#1) * Refactor: remove hard-coded license details from the script. * docs(devcontainer): Regenerate devcontainer docs to reflect binary links with latest tags.
1 parent c7cde51 commit 570eb09

File tree

18 files changed

+470
-1
lines changed

18 files changed

+470
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Test DevContainer Image
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test-devcontainer:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v3
13+
14+
- name: Setup Go 1.22.x
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: "1.22.x"
18+
19+
- name: Setup NodeJS 20.x
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: "20.x"
23+
24+
- name: Setup Devcontainer CLI
25+
run: |
26+
npm install -g @devcontainers/cli
27+
28+
- name: Build and Validate DevContainer
29+
run: |
30+
cd testdata/project-v4
31+
32+
OUTPUT=$(devcontainer up --workspace-folder=./)
33+
STATUS=$(echo "$OUTPUT" | jq -r '.outcome')
34+
35+
if [[ "$STATUS" == "success" ]]; then
36+
echo "Devcontainer setup was successful."
37+
exit 0
38+
else
39+
echo "Devcontainer setup failed."
40+
exit 1
41+
fi
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "Kubebuilder DevContainer",
3+
"image": "golang:1.22",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/git:1": {}
7+
},
8+
9+
"runArgs": ["--network=host"],
10+
11+
"customizations": {
12+
"vscode": {
13+
"settings": {
14+
"terminal.integrated.shell.linux": "/bin/bash"
15+
},
16+
"extensions": [
17+
"ms-kubernetes-tools.vscode-kubernetes-tools",
18+
"ms-azuretools.vscode-docker"
19+
]
20+
}
21+
},
22+
23+
"onCreateCommand": "bash .devcontainer/post-install.sh"
24+
}
25+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -x
3+
4+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
5+
chmod +x ./kind
6+
mv ./kind /usr/local/bin/kind
7+
8+
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
9+
chmod +x kubebuilder
10+
mv kubebuilder /usr/local/bin/
11+
12+
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
13+
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
14+
chmod +x kubectl
15+
mv kubectl /usr/local/bin/kubectl
16+
17+
kind version
18+
kubebuilder version
19+
docker --version
20+
go version
21+
kubectl version --client
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "Kubebuilder DevContainer",
3+
"image": "golang:1.22",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/git:1": {}
7+
},
8+
9+
"runArgs": ["--network=host"],
10+
11+
"customizations": {
12+
"vscode": {
13+
"settings": {
14+
"terminal.integrated.shell.linux": "/bin/bash"
15+
},
16+
"extensions": [
17+
"ms-kubernetes-tools.vscode-kubernetes-tools",
18+
"ms-azuretools.vscode-docker"
19+
]
20+
}
21+
},
22+
23+
"onCreateCommand": "bash .devcontainer/post-install.sh"
24+
}
25+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -x
3+
4+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
5+
chmod +x ./kind
6+
mv ./kind /usr/local/bin/kind
7+
8+
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
9+
chmod +x kubebuilder
10+
mv kubebuilder /usr/local/bin/
11+
12+
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
13+
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
14+
chmod +x kubectl
15+
mv kubectl /usr/local/bin/kubectl
16+
17+
kind version
18+
kubebuilder version
19+
docker --version
20+
go version
21+
kubectl version --client

pkg/plugins/golang/v4/scaffolds/init.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,7 @@ func (s *initScaffolder) Scaffold() error {
162162
&e2e.Test{},
163163
&e2e.SuiteTest{},
164164
&utils.Utils{},
165+
&templates.DevContainer{},
166+
&templates.DevContainerPostInstallScript{},
165167
)
166168
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package templates
18+
19+
import (
20+
"sigs.k8s.io/kubebuilder/v4/pkg/machinery"
21+
)
22+
23+
const devContainerTemplate = `{
24+
"name": "Kubebuilder DevContainer",
25+
"image": "golang:1.22",
26+
"features": {
27+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
28+
"ghcr.io/devcontainers/features/git:1": {}
29+
},
30+
31+
"runArgs": ["--network=host"],
32+
33+
"customizations": {
34+
"vscode": {
35+
"settings": {
36+
"terminal.integrated.shell.linux": "/bin/bash"
37+
},
38+
"extensions": [
39+
"ms-kubernetes-tools.vscode-kubernetes-tools",
40+
"ms-azuretools.vscode-docker"
41+
]
42+
}
43+
},
44+
45+
"onCreateCommand": "bash .devcontainer/post-install.sh"
46+
}
47+
48+
`
49+
50+
const postInstallScript = `#!/bin/bash
51+
set -x
52+
53+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
54+
chmod +x ./kind
55+
mv ./kind /usr/local/bin/kind
56+
57+
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
58+
chmod +x kubebuilder
59+
mv kubebuilder /usr/local/bin/
60+
61+
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
62+
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
63+
chmod +x kubectl
64+
mv kubectl /usr/local/bin/kubectl
65+
66+
kind version
67+
kubebuilder version
68+
docker --version
69+
go version
70+
kubectl version --client
71+
`
72+
73+
var _ machinery.Template = &DevContainer{}
74+
var _ machinery.Template = &DevContainerPostInstallScript{}
75+
76+
// DevCotaniner scaffoldds a `devcontainer.json` configurations file for
77+
// creating Kubebuilder & Kind based DevContainer.
78+
type DevContainer struct {
79+
machinery.TemplateMixin
80+
}
81+
82+
type DevContainerPostInstallScript struct {
83+
machinery.TemplateMixin
84+
}
85+
86+
func (f *DevContainer) SetTemplateDefaults() error {
87+
if f.Path == "" {
88+
f.Path = ".devcontainer/devcontainer.json"
89+
}
90+
91+
f.TemplateBody = devContainerTemplate
92+
93+
return nil
94+
}
95+
96+
func (f *DevContainerPostInstallScript) SetTemplateDefaults() error {
97+
if f.Path == "" {
98+
f.Path = ".devcontainer/post-install.sh"
99+
}
100+
101+
f.TemplateBody = postInstallScript
102+
103+
return nil
104+
}

test/check-license.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ set -o pipefail
2121
source $(dirname "$0")/common.sh
2222

2323
echo "Checking for license header..."
24-
allfiles=$(listFiles|grep -v ./internal/bindata/...)
24+
allfiles=$(listFiles | grep -v -e './internal/bindata/...' -e '.devcontainer/post-install.sh')
2525
licRes=""
2626
for file in $allfiles; do
2727
if ! head -n4 "${file}" | grep -Eq "(Copyright|generated|GENERATED|Licensed)" ; then
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "Kubebuilder DevContainer",
3+
"image": "golang:1.22",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/git:1": {}
7+
},
8+
9+
"runArgs": ["--network=host"],
10+
11+
"customizations": {
12+
"vscode": {
13+
"settings": {
14+
"terminal.integrated.shell.linux": "/bin/bash"
15+
},
16+
"extensions": [
17+
"ms-kubernetes-tools.vscode-kubernetes-tools",
18+
"ms-azuretools.vscode-docker"
19+
]
20+
}
21+
},
22+
23+
"onCreateCommand": "bash .devcontainer/post-install.sh"
24+
}
25+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -x
3+
4+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
5+
chmod +x ./kind
6+
mv ./kind /usr/local/bin/kind
7+
8+
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
9+
chmod +x kubebuilder
10+
mv kubebuilder /usr/local/bin/
11+
12+
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
13+
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
14+
chmod +x kubectl
15+
mv kubectl /usr/local/bin/kubectl
16+
17+
kind version
18+
kubebuilder version
19+
docker --version
20+
go version
21+
kubectl version --client

0 commit comments

Comments
 (0)