Skip to content

Commit 49f3614

Browse files
authored
Merge pull request #6 from bank-vaults/reloader-POC-2
feat: reloader POC 2
2 parents 26a6639 + 8f5522b commit 49f3614

File tree

16 files changed

+1990
-0
lines changed

16 files changed

+1990
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.devenv/
2+
/.direnv/
3+
/.pre-commit-config.yaml
4+
/bin/
5+
/build/
6+
/tmp/

.golangci.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
run:
2+
timeout: 10m
3+
4+
linters-settings:
5+
gci:
6+
sections:
7+
- standard
8+
- default
9+
- prefix(github.com/bank-vaults/vault-secrets-reloader)
10+
goimports:
11+
local-prefixes: github.com/bank-vaults/vault-secrets-reloader
12+
misspell:
13+
locale: US
14+
nolintlint:
15+
allow-leading-space: false # require machine-readable nolint directives (with no leading space)
16+
allow-unused: false # report any unused nolint directives
17+
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
18+
revive:
19+
confidence: 0
20+
21+
linters:
22+
enable:
23+
- gci
24+
- goimports
25+
- misspell
26+
- nolintlint
27+
- revive

.licensei.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
approved = [
2+
"mit",
3+
"apache-2.0",
4+
"bsd-3-clause",
5+
"bsd-2-clause",
6+
"mpl-2.0",
7+
"isc"
8+
]
9+
10+
ignored = [
11+
"github.com/ghodss/yaml", # MIT
12+
"sigs.k8s.io/yaml", # Forked from above
13+
"github.com/gogo/protobuf", # 3-Clause BSD
14+
"logur.dev/adapter/logrus", # MIT
15+
"logur.dev/logur", # MIT
16+
"github.com/hashicorp/vault/api", # MPL-2.0
17+
18+
# Unsupported VCS
19+
"google.golang.org/protobuf",
20+
]
21+
22+
[header]
23+
authors = ["Cisco", "Bank-Vaults Maintainers"]
24+
ignorePaths = [".direnv", ".devenv", "vendor"]
25+
ignoreFiles = ["zz_generated.*.go"]
26+
template = """// Copyright © :YEAR: :AUTHOR:
27+
//
28+
// Licensed under the Apache License, Version 2.0 (the "License");
29+
// you may not use this file except in compliance with the License.
30+
// You may obtain a copy of the License at
31+
//
32+
// http://www.apache.org/licenses/LICENSE-2.0
33+
//
34+
// Unless required by applicable law or agreed to in writing, software
35+
// distributed under the License is distributed on an "AS IS" BASIS,
36+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37+
// See the License for the specific language governing permissions and
38+
// limitations under the License."""

Makefile

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
2+
3+
# Default values for environment variables used in the Makefile
4+
KUBECONFIG ?= $(HOME)/.kube/config
5+
TEST_KIND_CLUSTER ?= vault-secrets-reloader
6+
# Target image name
7+
IMG ?= ghcr.io/bank-vaults/vault-secrets-reloader:dev
8+
9+
10+
# Setting SHELL to bash allows bash commands to be executed by recipes.
11+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
12+
SHELL = /usr/bin/env bash -o pipefail
13+
.SHELLFLAGS = -ec
14+
15+
##@ General
16+
17+
# Targets commented with ## will be visible in "make help" info.
18+
# Comments marked with ##@ will be used as categories for a group of targets.
19+
20+
.PHONY: help
21+
default: help
22+
help: ## Display this help
23+
@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)
24+
25+
##@ Checks
26+
27+
.PHONY: license-check
28+
license-check: ## Run license check
29+
$(LICENSEI) check
30+
$(LICENSEI) header
31+
32+
.PHONY: fmt
33+
fmt: ## Run go fmt against code
34+
$(GOLANGCI_LINT) run --fix
35+
36+
.PHONY: lint-go
37+
lint-go: # Run golang lint check
38+
$(GOLANGCI_LINT) run $(if ${CI},--out-format github-actions,)
39+
40+
.PHONY: lint
41+
# lint-helm lint-docker lint-yaml
42+
lint: lint-go ## Run lint checks
43+
44+
##@ Development
45+
46+
.PHONY: run
47+
run: ## Run manager from your host
48+
go run main.go -log_level=debug -collector_sync_period=30s -reloader_run_period=1m
49+
50+
.PHONY: up
51+
up: ## Start kind development environment
52+
$(KIND) create cluster --name $(TEST_KIND_CLUSTER)
53+
sleep 10
54+
helm upgrade --install vault-operator oci://ghcr.io/bank-vaults/helm-charts/vault-operator \
55+
--set image.tag=latest \
56+
--set image.bankVaultsTag=latest \
57+
--wait
58+
# kubectl kustomize https://github.com/bank-vaults/vault-operator/deploy/rbac | kubectl apply -f -
59+
kubectl create namespace bank-vaults-infra --dry-run=client -o yaml | kubectl apply -f -
60+
kubectl apply -f $(shell pwd)/e2e/deploy/vault/
61+
sleep 60
62+
helm upgrade --install vault-secrets-webhook oci://ghcr.io/bank-vaults/helm-charts/vault-secrets-webhook \
63+
--set replicaCount=1 \
64+
--set image.tag=latest \
65+
--set image.pullPolicy=IfNotPresent \
66+
--set podsFailurePolicy=Fail \
67+
--set secretsFailurePolicy=Fail \
68+
--set vaultEnv.tag=latest \
69+
--namespace bank-vaults-infra
70+
71+
.PHONY: down
72+
down: ## Destroy kind development environment
73+
$(KIND) delete cluster --name $(TEST_KIND_CLUSTER)
74+
75+
##@ Build
76+
77+
.PHONY: build
78+
build: ## Build manager binary
79+
@mkdir -p build
80+
go build -race -o build/controller .
81+
82+
##@ Deployment
83+
84+
##@ Dependencies
85+
86+
# Dependency tool chain
87+
GOLANGCI_VERSION = 1.53.3
88+
LICENSEI_VERSION = 0.8.0
89+
KIND_VERSION = 0.20.0
90+
# CODE_GENERATOR_VERSION = 0.27.1
91+
# HELM_DOCS_VERSION = 1.11.0
92+
# KUSTOMIZE_VERSION = 5.1.0
93+
# CONTROLLER_TOOLS_VERSION = 0.12.1
94+
95+
## Location to install dependencies to
96+
LOCALBIN ?= $(shell pwd)/bin
97+
$(LOCALBIN):
98+
mkdir -p $(LOCALBIN)
99+
100+
# KUSTOMIZE ?= $(or $(shell which kustomize),$(LOCALBIN)/kustomize)
101+
# $(KUSTOMIZE): $(LOCALBIN)
102+
# @if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q v$(KUSTOMIZE_VERSION); then \
103+
# echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
104+
# rm -rf $(LOCALBIN)/kustomize; \
105+
# fi
106+
# test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@v$(KUSTOMIZE_VERSION)
107+
#
108+
# CONTROLLER_GEN ?= $(or $(shell which controller-gen),$(LOCALBIN)/controller-gen)
109+
# $(CONTROLLER_GEN): $(LOCALBIN)
110+
# test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q v$(CONTROLLER_TOOLS_VERSION) || \
111+
# GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@v$(CONTROLLER_TOOLS_VERSION)
112+
#
113+
# ENVTEST ?= $(or $(shell which setup-envtest),$(LOCALBIN)/setup-envtest)
114+
# $(ENVTEST): $(LOCALBIN)
115+
# test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
116+
117+
GOLANGCI_LINT ?= $(or $(shell which golangci-lint),$(LOCALBIN)/golangci-lint)
118+
$(GOLANGCI_LINT): $(LOCALBIN)
119+
test -s $(LOCALBIN)/golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- v${GOLANGCI_VERSION}
120+
121+
LICENSEI ?= $(or $(shell which licensei),$(LOCALBIN)/licensei)
122+
$(LICENSEI): $(LOCALBIN)
123+
test -s $(LOCALBIN)/licensei || curl -sfL https://raw.githubusercontent.com/goph/licensei/master/install.sh | bash -s -- v${LICENSEI_VERSION}
124+
125+
KIND ?= $(or $(shell which kind),$(LOCALBIN)/kind)
126+
$(KIND): $(LOCALBIN)
127+
@if [ ! -s "$(LOCALBIN)/kind" ]; then \
128+
curl -Lo $(LOCALBIN)/kind https://kind.sigs.k8s.io/dl/v${KIND_VERSION}/kind-$(shell uname -s | tr '[:upper:]' '[:lower:]')-$(shell uname -m | sed -e "s/aarch64/arm64/; s/x86_64/amd64/"); \
129+
chmod +x $(LOCALBIN)/kind; \
130+
fi
131+
132+
# HELM ?= $(or $(shell which helm),$(LOCALBIN)/helm)
133+
# $(HELM): $(LOCALBIN)
134+
# test -s $(LOCALBIN)/helm || curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | USE_SUDO=false HELM_INSTALL_DIR=$(LOCALBIN) bash
135+
#
136+
# HELM_DOCS ?= $(or $(shell which helm-docs),$(LOCALBIN)/helm-docs)
137+
# $(HELM_DOCS): $(LOCALBIN)
138+
# @if [ ! -s "$(LOCALBIN)/helm-docs" ]; then \
139+
# curl -L https://github.com/norwoodj/helm-docs/releases/download/v${HELM_DOCS_VERSION}/helm-docs_${HELM_DOCS_VERSION}_$(shell uname)_x86_64.tar.gz | tar -zOxf - helm-docs > ./bin/helm-docs; \
140+
# chmod +x $(LOCALBIN)/helm-docs; \
141+
# fi
142+
143+
# TODO: add support for hadolint and yamllint dependencies
144+
HADOLINT ?= hadolint
145+
YAMLLINT ?= yamllint
146+
147+
.PHONY: deps
148+
deps: $(HELM) $(CONTROLLER_GEN) $(KUSTOMIZE) $(KIND)
149+
deps: $(HELM_DOCS) $(ENVTEST) $(GOLANGCI_LINT) $(LICENSEI)
150+
deps: ## Download and install dependencies

e2e/deploy/vault/rbac.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
kind: ServiceAccount
2+
apiVersion: v1
3+
metadata:
4+
name: vault
5+
6+
---
7+
kind: Role
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
metadata:
10+
name: vault
11+
rules:
12+
- apiGroups: [""]
13+
resources: ["secrets"]
14+
verbs: ["*"]
15+
- apiGroups: [""]
16+
resources: ["pods"]
17+
verbs: ["get", "update", "patch"]
18+
19+
---
20+
kind: RoleBinding
21+
apiVersion: rbac.authorization.k8s.io/v1
22+
metadata:
23+
name: vault
24+
roleRef:
25+
kind: Role
26+
name: vault
27+
apiGroup: rbac.authorization.k8s.io
28+
subjects:
29+
- kind: ServiceAccount
30+
name: vault
31+
32+
---
33+
# This binding allows the deployed Vault instance to authenticate clients
34+
# through Kubernetes ServiceAccounts (if configured so).
35+
apiVersion: rbac.authorization.k8s.io/v1
36+
kind: ClusterRoleBinding
37+
metadata:
38+
name: vault-auth-delegator
39+
roleRef:
40+
apiGroup: rbac.authorization.k8s.io
41+
kind: ClusterRole
42+
name: system:auth-delegator
43+
subjects:
44+
- kind: ServiceAccount
45+
name: vault
46+
namespace: default

0 commit comments

Comments
 (0)