Skip to content

Commit

Permalink
feat(dev-container): ✨ Devcontainer configuration file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TAM360 authored and taimoor-mirza29 committed Aug 14, 2024
1 parent eb97367 commit 5e4a7e0
Show file tree
Hide file tree
Showing 92 changed files with 1,483 additions and 5,233 deletions.
2 changes: 1 addition & 1 deletion designs/template.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| Authors | Creation Date | Status | Extra |
|---------------|---------------|-------------|---|
| @name | date | Implementeble | - |
| @name | date | Implementable | - |

Title of the Design/Proposal
===================
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Build the manager binary
# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon):
# 1, 1.19, 1.18, 1-bullseye, 1.19-bullseye, 1.18-bullseye, 1-buster, 1.19-buster, 1.18-buster
ARG TAG=1.22
FROM golang:${TAG}

COPY post-install.sh .

# Install dependencies
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

RUN go install sigs.k8s.io/[email protected] && \
curl -o kubebuilder \
-L https://github.com/kubernetes-sigs/kubebuilder/releases/latest/download/kubebuilder_linux_amd64 && \
chmod +x kubebuilder && \
mv kubebuilder /usr/local/bin/ && \
chmod +x post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-in-docker
{
"name": "Kubebuilder DevContainer",
"build": {
"dockerfile": "./Dockerfile",
"context": "."
},

"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2.11.0": {
"moby": true,
"azureDnsAutoDetection": true,
"version": "latest"
},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": false,
"upgradePackages": true,
"username": "devcontainer",
"userUid": "1001",
"userGid": "1001"
},
"ghcr.io/devcontainers/features/git:1": {
"ppa": true,
"version": "system"
},
"ghcr.io/devcontainers/features/go:1": {
"version": "1.22.0"
}
},

"runArgs": ["--network=host"],
// "forwardPorts": [],

"postCreateCommand": "bash ./.devcontainer/post-install.sh"

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e

go version
kubectl version --client

# Check if Kind cluster already exists.
if kubectl cluster-info &>/dev/null; then
echo "Kind cluster already exists."
else
echo "Kind cluster doesn't exist. Creating new cluster...."
kind create cluster
fi

kubectl get nodes -o wide
6 changes: 5 additions & 1 deletion docs/book/src/cronjob-tutorial/testdata/project/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ help: ## Display this help.

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Note that the option maxDescLen=0 was added in the default scaffold in order to sort out the issue
# Too long: must have at most 262144 bytes. By using kubectl apply to create / update resources an annotation
# is created by K8s API to store the latest version of the resource ( kubectl.kubernetes.io/last-applied-configuration).
# 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.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ var _ = BeforeSuite(func() {
})

var _ = AfterSuite(func() {
cancel()
By("tearing down the test environment")
cancel()
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
})

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ var (
cfg *rest.Config
k8sClient client.Client // You'll be using this client in your tests.
testEnv *envtest.Environment
ctx context.Context
cancel context.CancelFunc
)
var ctx context.Context
var cancel context.CancelFunc

func TestControllers(t *testing.T) {
RegisterFailHandler(Fail)
Expand Down Expand Up @@ -169,8 +169,8 @@ You won't need to touch these.
*/

var _ = AfterSuite(func() {
cancel()
By("tearing down the test environment")
cancel()
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Build the manager binary
# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon):
# 1, 1.19, 1.18, 1-bullseye, 1.19-bullseye, 1.18-bullseye, 1-buster, 1.19-buster, 1.18-buster
ARG TAG=1.22
FROM golang:${TAG}

COPY post-install.sh .

# Install dependencies
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

RUN go install sigs.k8s.io/[email protected] && \
curl -o kubebuilder \
-L https://github.com/kubernetes-sigs/kubebuilder/releases/latest/download/kubebuilder_linux_amd64 && \
chmod +x kubebuilder && \
mv kubebuilder /usr/local/bin/ && \
chmod +x post-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-in-docker
{
"name": "Kubebuilder DevContainer",
"build": {
"dockerfile": "./Dockerfile",
"context": "."
},

"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2.11.0": {
"moby": true,
"azureDnsAutoDetection": true,
"version": "latest"
},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": false,
"upgradePackages": true,
"username": "devcontainer",
"userUid": "1001",
"userGid": "1001"
},
"ghcr.io/devcontainers/features/git:1": {
"ppa": true,
"version": "system"
},
"ghcr.io/devcontainers/features/go:1": {
"version": "1.22.0"
}
},

"runArgs": ["--network=host"],
// "forwardPorts": [],

"postCreateCommand": "bash ./.devcontainer/post-install.sh"

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e

go version
kubectl version --client

# Check if Kind cluster already exists.
if kubectl cluster-info &>/dev/null; then
echo "Kind cluster already exists."
else
echo "Kind cluster doesn't exist. Creating new cluster...."
kind create cluster
fi

kubectl get nodes -o wide
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package controller

import (
"context"
"fmt"
"path/filepath"
"runtime"
Expand All @@ -42,6 +43,8 @@ import (
var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment
var ctx context.Context
var cancel context.CancelFunc

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

ctx, cancel = context.WithCancel(context.TODO())

By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
Expand Down Expand Up @@ -85,6 +90,7 @@ var _ = BeforeSuite(func() {

var _ = AfterSuite(func() {
By("tearing down the test environment")
cancel()
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
})
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ linters:
- dupl
- errcheck
- exportloopref
- ginkgolinter
- goconst
- gocyclo
- gofmt
Expand All @@ -33,8 +34,14 @@ linters:
- misspell
- nakedret
- prealloc
- revive
- staticcheck
- typecheck
- unconvert
- unparam
- unused

linters-settings:
revive:
rules:
- name: comment-spacings
24 changes: 13 additions & 11 deletions docs/book/src/multiversion-tutorial/testdata/project/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ $(LOCALBIN):

## Tool Binaries
KUBECTL ?= kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint

## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.1
KUSTOMIZE_VERSION ?= v5.4.2
CONTROLLER_TOOLS_VERSION ?= v0.15.0
ENVTEST_VERSION ?= release-0.18
GOLANGCI_LINT_VERSION ?= v1.57.2
GOLANGCI_LINT_VERSION ?= v1.59.1

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

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ var _ = BeforeSuite(func() {
})

var _ = AfterSuite(func() {
cancel()
By("tearing down the test environment")
cancel()
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
})
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ var _ = BeforeSuite(func() {
})

var _ = AfterSuite(func() {
cancel()
By("tearing down the test environment")
cancel()
err := testEnv.Stop()
Expect(err).NotTo(HaveOccurred())
})
Loading

0 comments on commit 5e4a7e0

Please sign in to comment.