Skip to content

Commit a5b95e3

Browse files
authored
Merge pull request #3758 from stmcginnis/docs/getting-started-updates
📖 Clean up getting started docs
2 parents d13a95f + f14dbc1 commit a5b95e3

Some content is hidden

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

52 files changed

+3430
-145
lines changed

docs/book/src/getting-started.md

Lines changed: 51 additions & 61 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
bin/*
9+
Dockerfile.cross
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Go workspace file
18+
go.work
19+
20+
# Kubernetes Generated files - skip generated files, except for vendored files
21+
!vendor/**/zz_generated.*
22+
23+
# editor and IDE paraphernalia
24+
.idea
25+
.vscode
26+
*.swp
27+
*.swo
28+
*~
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
run:
2+
deadline: 5m
3+
allow-parallel-runners: true
4+
5+
issues:
6+
# don't skip warning about doc comments
7+
# don't exclude the default set of lint
8+
exclude-use-default: false
9+
# restore some of the defaults
10+
# (fill in the rest as needed)
11+
exclude-rules:
12+
- path: "api/*"
13+
linters:
14+
- lll
15+
- path: "internal/*"
16+
linters:
17+
- dupl
18+
- lll
19+
linters:
20+
disable-all: true
21+
enable:
22+
- dupl
23+
- errcheck
24+
- exportloopref
25+
- goconst
26+
- gocyclo
27+
- gofmt
28+
- goimports
29+
- gosimple
30+
- govet
31+
- ineffassign
32+
- lll
33+
- misspell
34+
- nakedret
35+
- prealloc
36+
- staticcheck
37+
- typecheck
38+
- unconvert
39+
- unparam
40+
- unused
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Build the manager binary
2+
FROM golang:1.21 AS builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
WORKDIR /workspace
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.mod
9+
COPY go.sum go.sum
10+
# cache deps before building and copying source so that we don't need to re-download as much
11+
# and so that source changes don't invalidate our downloaded layer
12+
RUN go mod download
13+
14+
# Copy the go source
15+
COPY cmd/main.go cmd/main.go
16+
COPY api/ api/
17+
COPY internal/controller/ internal/controller/
18+
19+
# Build
20+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
25+
26+
# Use distroless as minimal base image to package the manager binary
27+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
28+
FROM gcr.io/distroless/static:nonroot
29+
WORKDIR /
30+
COPY --from=builder /workspace/manager .
31+
USER 65532:65532
32+
33+
ENTRYPOINT ["/manager"]
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5+
ENVTEST_K8S_VERSION = 1.29.0
6+
7+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8+
ifeq (,$(shell go env GOBIN))
9+
GOBIN=$(shell go env GOPATH)/bin
10+
else
11+
GOBIN=$(shell go env GOBIN)
12+
endif
13+
14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
20+
# Setting SHELL to bash allows bash commands to be executed by recipes.
21+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
22+
SHELL = /usr/bin/env bash -o pipefail
23+
.SHELLFLAGS = -ec
24+
25+
.PHONY: all
26+
all: build
27+
28+
##@ General
29+
30+
# The help target prints out all targets with their descriptions organized
31+
# beneath their categories. The categories are represented by '##@' and the
32+
# target descriptions by '##'. The awk command is responsible for reading the
33+
# entire set of makefiles included in this invocation, looking for lines of the
34+
# file as xyz: ## something, and then pretty-format the target and help. Then,
35+
# if there's a line with ##@ something, that gets pretty-printed as a category.
36+
# More info on the usage of ANSI control characters for terminal formatting:
37+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
38+
# More info on the awk command:
39+
# http://linuxcommand.org/lc3_adv_awk.php
40+
41+
.PHONY: help
42+
help: ## Display this help.
43+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
44+
45+
##@ Development
46+
47+
.PHONY: manifests
48+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
49+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
50+
51+
.PHONY: generate
52+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
53+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
54+
55+
.PHONY: fmt
56+
fmt: ## Run go fmt against code.
57+
go fmt ./...
58+
59+
.PHONY: vet
60+
vet: ## Run go vet against code.
61+
go vet ./...
62+
63+
.PHONY: test
64+
test: manifests generate fmt vet envtest ## Run tests.
65+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
66+
67+
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
68+
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
69+
test-e2e:
70+
go test ./test/e2e/ -v -ginkgo.v
71+
72+
.PHONY: lint
73+
lint: golangci-lint ## Run golangci-lint linter & yamllint
74+
$(GOLANGCI_LINT) run
75+
76+
.PHONY: lint-fix
77+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
78+
$(GOLANGCI_LINT) run --fix
79+
80+
##@ Build
81+
82+
.PHONY: build
83+
build: manifests generate fmt vet ## Build manager binary.
84+
go build -o bin/manager cmd/main.go
85+
86+
.PHONY: run
87+
run: manifests generate fmt vet ## Run a controller from your host.
88+
go run ./cmd/main.go
89+
90+
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
91+
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
92+
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
93+
.PHONY: docker-build
94+
docker-build: ## Build docker image with the manager.
95+
$(CONTAINER_TOOL) build -t ${IMG} .
96+
97+
.PHONY: docker-push
98+
docker-push: ## Push docker image with the manager.
99+
$(CONTAINER_TOOL) push ${IMG}
100+
101+
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
102+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
103+
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
104+
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
105+
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
106+
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
107+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
108+
.PHONY: docker-buildx
109+
docker-buildx: ## Build and push docker image for the manager for cross-platform support
110+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
111+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
112+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
113+
$(CONTAINER_TOOL) buildx use project-v3-builder
114+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
115+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
116+
rm Dockerfile.cross
117+
118+
.PHONY: build-installer
119+
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
120+
mkdir -p dist
121+
echo "---" > dist/install.yaml # Clean previous content
122+
@if [ -d "config/crd" ]; then \
123+
$(KUSTOMIZE) build config/crd > dist/install.yaml; \
124+
echo "---" >> dist/install.yaml; \
125+
fi
126+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
127+
$(KUSTOMIZE) build config/default >> dist/install.yaml
128+
129+
##@ Deployment
130+
131+
ifndef ignore-not-found
132+
ignore-not-found = false
133+
endif
134+
135+
.PHONY: install
136+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
137+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
138+
139+
.PHONY: uninstall
140+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
141+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
142+
143+
.PHONY: deploy
144+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
145+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
146+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
147+
148+
.PHONY: undeploy
149+
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
150+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
151+
152+
##@ Dependencies
153+
154+
## Location to install dependencies to
155+
LOCALBIN ?= $(shell pwd)/bin
156+
$(LOCALBIN):
157+
mkdir -p $(LOCALBIN)
158+
159+
## Tool Binaries
160+
KUBECTL ?= kubectl
161+
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
162+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
163+
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
164+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
165+
166+
## Tool Versions
167+
KUSTOMIZE_VERSION ?= v5.3.0
168+
CONTROLLER_TOOLS_VERSION ?= v0.14.0
169+
ENVTEST_VERSION ?= latest
170+
GOLANGCI_LINT_VERSION ?= v1.54.2
171+
172+
.PHONY: kustomize
173+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
174+
$(KUSTOMIZE): $(LOCALBIN)
175+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
176+
177+
.PHONY: controller-gen
178+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
179+
$(CONTROLLER_GEN): $(LOCALBIN)
180+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
181+
182+
.PHONY: envtest
183+
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
184+
$(ENVTEST): $(LOCALBIN)
185+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
186+
187+
.PHONY: golangci-lint
188+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
189+
$(GOLANGCI_LINT): $(LOCALBIN)
190+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
191+
192+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
193+
# $1 - target path with name of binary (ideally with version)
194+
# $2 - package url which can be installed
195+
# $3 - specific version of package
196+
define go-install-tool
197+
@[ -f $(1) ] || { \
198+
set -e; \
199+
package=$(2)@$(3) ;\
200+
echo "Downloading $${package}" ;\
201+
GOBIN=$(LOCALBIN) go install $${package} ;\
202+
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
203+
}
204+
endef
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
5+
componentConfig: true
6+
domain: example.com
7+
layout:
8+
- go.kubebuilder.io/v4
9+
plugins:
10+
deploy-image.go.kubebuilder.io/v1-alpha:
11+
resources:
12+
- domain: example.com
13+
group: cache
14+
kind: Memcached
15+
options:
16+
containerCommand: memcached,-m=64,-o,modern,-v
17+
containerPort: "11211"
18+
image: memcached:1.4.36-alpine
19+
runAsUser: "1001"
20+
version: v1alpha1
21+
projectName: project
22+
repo: example.com/memcached
23+
resources:
24+
- api:
25+
crdVersion: v1
26+
namespaced: true
27+
controller: true
28+
domain: example.com
29+
group: cache
30+
kind: Memcached
31+
path: example.com/memcached/api/v1alpha1
32+
version: v1alpha1
33+
version: "3"

0 commit comments

Comments
 (0)