From 49ca674b141a80c74afc92d8ce1de48eb74619d4 Mon Sep 17 00:00:00 2001 From: alias-rahil Date: Sun, 13 Mar 2022 19:10:08 +0000 Subject: [PATCH] feat: add hack dockefiles to regenerate code and crd manifest --- .dockerignore | 10 ++++++++++ .gitignore | 2 +- README.md | 27 +++++++++++++++++++++------ hack/Dockerfile.update-codegen | 14 ++++++++++++++ hack/Dockerfile.update-crds | 14 ++++++++++++++ 5 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 hack/Dockerfile.update-codegen create mode 100644 hack/Dockerfile.update-crds diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..17e2b2b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +config/ +hack/ +manifests/ +.vscode/ +.git/ +.dockerignore +.gitignore +Dockerfile +README.md +kluster diff --git a/.gitignore b/.gitignore index 47afa24..2b00056 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ kluster config/ -.vscode +.vscode/ diff --git a/README.md b/README.md index 7177baf..2782e6d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ - # Kluster A example Kubernetes operator to create Kubernetes cluster on DigitalOcean. @@ -10,7 +9,7 @@ This operator was written as part of one of my [YouTube playlist](https://www.yo Here is an example of the Kluster resource -``` +```yaml apiVersion: viveksingh.dev/v1alpha1 kind: Kluster metadata: @@ -32,13 +31,13 @@ Execute below command, from root of the repo Create Kluster CRD -``` +```sh kubectl create -f manifests/viveksingh.dev_klusters.yaml ``` Create RBAC resources and deployment -``` +```sh kubectl create -f manifests/install/ ``` @@ -47,7 +46,7 @@ kubectl create -f manifests/install/ To call DigitalOcean APIs we will have to create a secret with DigitalOcean token that will be used in the Kluster CR that we create. -``` +```sh kubectl create secret generic dosecret --from-literal token= ``` @@ -55,6 +54,22 @@ kubectl create secret generic dosecret --from-literal token= Create the kluster resource to create a k8s cluster in DigitalOcean -``` +```sh kubectl create -f manifests/klusterone.yaml ``` + +# Updating CRD manifest + +Update the CRD manifest (`manifests/viveksingh.dev_klusters.yaml`) using docker: + +```sh +docker buildx build --file hack/Dockerfile.update-crds -o . . +``` + +# Updating the auto-generated code + +Update the auto-generated code (`pkg/client/` and `pkg/apis/viveksingh.dev/v1alpha1/zz_generated.deepcopy.go`) using docker: + +```sh +docker buildx build --file hack/Dockerfile.update-codegen -o . . +``` diff --git a/hack/Dockerfile.update-codegen b/hack/Dockerfile.update-codegen new file mode 100644 index 0000000..b20bf3f --- /dev/null +++ b/hack/Dockerfile.update-codegen @@ -0,0 +1,14 @@ +# hack/Dockerfile.update-codegen + +# Usage: docker buildx build --file hack/Dockerfile.update-codegen -o . . + +FROM golang:1.13 AS build +WORKDIR /go/src/github.com/viveksinghggits/kluster +RUN go mod download k8s.io/code-generator@v0.21.3 +COPY . . +RUN bash /go/pkg/mod/k8s.io/code-generator@v0.21.3/generate-groups.sh all \ + github.com/viveksinghggits/kluster/pkg/client github.com/viveksinghggits/kluster/pkg/apis viveksingh.dev:v1alpha1 \ + --go-header-file /go/pkg/mod/k8s.io/code-generator@v0.21.3/hack/boilerplate.go.txt + +FROM scratch +COPY --from=build /go/src/github.com/viveksinghggits/kluster/pkg pkg diff --git a/hack/Dockerfile.update-crds b/hack/Dockerfile.update-crds new file mode 100644 index 0000000..a27b94d --- /dev/null +++ b/hack/Dockerfile.update-crds @@ -0,0 +1,14 @@ +# hack/Dockerfile.update-crds + +# Usage: docker buildx build --file hack/Dockerfile.update-crds -o . . + +FROM golang:1.13 AS build +WORKDIR /go/src/github.com/viveksinghggits/kluster +RUN GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5 +COPY . . +RUN controller-gen paths=github.com/viveksinghggits/kluster/pkg/apis/viveksingh.dev/v1alpha1 \ + crd:crdVersions=v1 \ + output:crd:artifacts:config=manifests + +FROM scratch +COPY --from=build /go/src/github.com/viveksinghggits/kluster/manifests manifests