Skip to content

Commit e28c602

Browse files
committed
initial commit
Signed-off-by: Thomas Kooi <[email protected]>
0 parents  commit e28c602

Some content is hidden

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

57 files changed

+3497
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/
4+
testbin/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# This workflow lets you compile your Go project using a SLSA3 compliant builder.
7+
# This workflow will generate a so-called "provenance" file describing the steps
8+
# that were performed to generate the final binary.
9+
# The project is an initiative of the OpenSSF (openssf.org) and is developed at
10+
# https://github.com/slsa-framework/slsa-github-generator.
11+
# The provenance file can be verified using https://github.com/slsa-framework/slsa-verifier.
12+
# For more information about SLSA and how it improves the supply-chain, visit slsa.dev.
13+
14+
name: SLSA Go releaser
15+
on:
16+
workflow_dispatch:
17+
release:
18+
types: [created]
19+
20+
permissions: read-all
21+
22+
jobs:
23+
# ========================================================================================================================================
24+
# Prerequesite: Create a .slsa-goreleaser.yml in the root directory of your project.
25+
# See format in https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/go/README.md#configuration-file
26+
#=========================================================================================================================================
27+
build:
28+
permissions:
29+
id-token: write # To sign.
30+
contents: write # To upload release assets.
31+
actions: read # To read workflow path.
32+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
33+
with:
34+
go-version: 1.21
35+
# =============================================================================================================
36+
# Optional: For more options, see https://github.com/slsa-framework/slsa-github-generator#golang-projects
37+
# =============================================================================================================

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
bin
9+
testbin/*
10+
11+
# Test binary, build with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Kubernetes Generated files - skip generated files, except for vendored files
18+
19+
!vendor/**/zz_generated.*
20+
21+
# editor and IDE paraphernalia
22+
.idea
23+
*.swp
24+
*.swo
25+
*~

.reviewdog.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# reviewdog.yml
2+
3+
runner:
4+
govet:
5+
cmd: go vet $(go list ./... | grep -v /.go/)
6+
format: govet
7+
level: warning
8+
gosec:
9+
cmd: gosec -quiet -no-fail -fmt golint $(go list ./... | grep -v /.go/)
10+
format: golint
11+
level: warning
12+
staticcheck:
13+
cmd: staticcheck -fail none $(go list ./... | grep -v /.go/)
14+
errorformat:
15+
- "%f:%l:%c: %m"

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Build the manager binary
2+
FROM golang:1.20 as builder
3+
4+
WORKDIR /workspace
5+
# Copy the Go Modules manifests
6+
COPY go.mod go.mod
7+
COPY go.sum go.sum
8+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
10+
RUN go mod download
11+
12+
# Copy the go source
13+
COPY main.go main.go
14+
COPY api/ api/
15+
COPY controllers/ controllers/
16+
17+
# Build
18+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
19+
20+
# Use distroless as minimal base image to package the manager binary
21+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
22+
FROM gcr.io/distroless/static:nonroot
23+
WORKDIR /
24+
COPY --from=builder /workspace/manager .
25+
USER 65532:65532
26+
27+
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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.23
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+
# Setting SHELL to bash allows bash commands to be executed by recipes.
15+
# This is a requirement for 'setup-envtest.sh' in the test target.
16+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
17+
SHELL = /usr/bin/env bash -o pipefail
18+
.SHELLFLAGS = -ec
19+
20+
.PHONY: all
21+
all: build
22+
23+
##@ General
24+
25+
# The help target prints out all targets with their descriptions organized
26+
# beneath their categories. The categories are represented by '##@' and the
27+
# target descriptions by '##'. The awk commands is responsible for reading the
28+
# entire set of makefiles included in this invocation, looking for lines of the
29+
# file as xyz: ## something, and then pretty-format the target and help. Then,
30+
# if there's a line with ##@ something, that gets pretty-printed as a category.
31+
# More info on the usage of ANSI control characters for terminal formatting:
32+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
33+
# More info on the awk command:
34+
# http://linuxcommand.org/lc3_adv_awk.php
35+
36+
.PHONY: help
37+
help: ## Display this help.
38+
@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)
39+
40+
##@ Development
41+
42+
.PHONY: manifests
43+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
44+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
45+
46+
.PHONY: generate
47+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
48+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
49+
50+
.PHONY: fmt
51+
fmt: ## Run go fmt against code.
52+
go fmt ./...
53+
54+
.PHONY: vet
55+
vet: ## Run go vet against code.
56+
go vet ./...
57+
58+
.PHONY: test
59+
test: manifests generate fmt vet envtest ## Run tests.
60+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
61+
62+
##@ Build
63+
64+
.PHONY: build
65+
build: generate fmt vet ## Build manager binary.
66+
go build -o bin/manager main.go
67+
68+
.PHONY: run
69+
run: manifests generate fmt vet ## Run a controller from your host.
70+
go run ./main.go
71+
72+
.PHONY: docker-build
73+
docker-build: test ## Build docker image with the manager.
74+
docker build -t ${IMG} .
75+
76+
.PHONY: docker-push
77+
docker-push: ## Push docker image with the manager.
78+
docker push ${IMG}
79+
80+
##@ Deployment
81+
82+
ifndef ignore-not-found
83+
ignore-not-found = false
84+
endif
85+
86+
.PHONY: install
87+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
88+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
89+
90+
.PHONY: uninstall
91+
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.
92+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
93+
94+
.PHONY: deploy
95+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
96+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
97+
$(KUSTOMIZE) build config/default | kubectl apply -f -
98+
99+
.PHONY: undeploy
100+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
101+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
102+
103+
##@ Build Dependencies
104+
105+
## Location to install dependencies to
106+
LOCALBIN ?= $(shell pwd)/bin
107+
$(LOCALBIN):
108+
mkdir -p $(LOCALBIN)
109+
110+
## Tool Binaries
111+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
112+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
113+
ENVTEST ?= $(LOCALBIN)/setup-envtest
114+
115+
## Tool Versions
116+
KUSTOMIZE_VERSION ?= v3.8.7
117+
CONTROLLER_TOOLS_VERSION ?= v0.8.0
118+
119+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
120+
.PHONY: kustomize
121+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
122+
$(KUSTOMIZE): $(LOCALBIN)
123+
curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
124+
125+
.PHONY: controller-gen
126+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
127+
$(CONTROLLER_GEN): $(LOCALBIN)
128+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
129+
130+
.PHONY: envtest
131+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
132+
$(ENVTEST): $(LOCALBIN)
133+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

PROJECT

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
domain: k8s.containerinfra.com
2+
layout:
3+
- go.kubebuilder.io/v3
4+
projectName: kube-secrets-operator
5+
repo: github.com/containerinfra/kube-secrets-operator
6+
resources:
7+
- api:
8+
crdVersion: v1
9+
namespaced: true
10+
controller: true
11+
domain: k8s.containerinfra.com
12+
group: apps
13+
kind: DatabaseServer
14+
path: github.com/containerinfra/kube-secrets-operator/api/v1
15+
version: v1
16+
version: "3"

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# kube-secrets-operator
2+
3+
## Description
4+
// TODO(user): An in-depth paragraph about your project and overview of use
5+
6+
## Getting Started
7+
You’ll need a Kubernetes cluster to run against. You can use [KIND](https://sigs.k8s.io/kind) to get a local cluster for testing, or run against a remote cluster.
8+
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).
9+
10+
### Running on the cluster
11+
1. Install Instances of Custom Resources:
12+
13+
```sh
14+
kubectl apply -f config/samples/
15+
```
16+
17+
2. Build and push your image to the location specified by `IMG`:
18+
19+
```sh
20+
make docker-build docker-push IMG=<some-registry>/kube-secrets-operator:tag
21+
```
22+
23+
3. Deploy the controller to the cluster with the image specified by `IMG`:
24+
25+
```sh
26+
make deploy IMG=<some-registry>/kube-secrets-operator:tag
27+
```
28+
29+
### Uninstall CRDs
30+
To delete the CRDs from the cluster:
31+
32+
```sh
33+
make uninstall
34+
```
35+
36+
### Undeploy controller
37+
UnDeploy the controller to the cluster:
38+
39+
```sh
40+
make undeploy
41+
```
42+
43+
## Contributing
44+
// TODO(user): Add detailed information on how you would like others to contribute to this project
45+
46+
### How it works
47+
This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)
48+
49+
It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controller/)
50+
which provides a reconcile function responsible for synchronizing resources untile the desired state is reached on the cluster
51+
52+
### Test It Out
53+
1. Install the CRDs into the cluster:
54+
55+
```sh
56+
make install
57+
```
58+
59+
2. Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
60+
61+
```sh
62+
make run
63+
```
64+
65+
**NOTE:** You can also run this in one step by running: `make install run`
66+
67+
### Modifying the API definitions
68+
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
69+
70+
```sh
71+
make manifests
72+
```
73+
74+
**NOTE:** Run `make --help` for more information on all potential `make` targets
75+
76+
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
77+
78+
## License
79+
80+
Copyright 2023.
81+
82+
Licensed under the Apache License, Version 2.0 (the "License");
83+
you may not use this file except in compliance with the License.
84+
You may obtain a copy of the License at
85+
86+
http://www.apache.org/licenses/LICENSE-2.0
87+
88+
Unless required by applicable law or agreed to in writing, software
89+
distributed under the License is distributed on an "AS IS" BASIS,
90+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
91+
See the License for the specific language governing permissions and
92+
limitations under the License.

0 commit comments

Comments
 (0)