Skip to content

Commit 179b945

Browse files
pb82NissesSenap
authored andcommitted
initial commit
1 parent e6189fd commit 179b945

File tree

3,482 files changed

+1238504
-0
lines changed

Some content is hidden

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

3,482 files changed

+1238504
-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/

.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+
*~

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.16 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: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# VERSION defines the project version for the bundle.
2+
# Update this value when you upgrade the version of your project.
3+
# To re-generate a bundle for another specific version without changing the standard setup, you can:
4+
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
5+
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6+
VERSION ?= 0.0.1
7+
8+
# CHANNELS define the bundle channels used in the bundle.
9+
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
10+
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
11+
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
12+
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
13+
ifneq ($(origin CHANNELS), undefined)
14+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
15+
endif
16+
17+
# DEFAULT_CHANNEL defines the default channel used in the bundle.
18+
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
19+
# To re-generate a bundle for any other default channel without changing the default setup, you can:
20+
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
21+
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
22+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
23+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
24+
endif
25+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
26+
27+
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
28+
# This variable is used to construct full image tags for bundle and catalog images.
29+
#
30+
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
31+
# integreatly.org/grafana-operator-experimental-bundle:$VERSION and integreatly.org/grafana-operator-experimental-catalog:$VERSION.
32+
IMAGE_TAG_BASE ?= integreatly.org/grafana-operator-experimental
33+
34+
# BUNDLE_IMG defines the image:tag used for the bundle.
35+
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
36+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
37+
38+
# Image URL to use all building/pushing image targets
39+
IMG ?= controller:latest
40+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
41+
ENVTEST_K8S_VERSION = 1.22
42+
43+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
44+
ifeq (,$(shell go env GOBIN))
45+
GOBIN=$(shell go env GOPATH)/bin
46+
else
47+
GOBIN=$(shell go env GOBIN)
48+
endif
49+
50+
# Setting SHELL to bash allows bash commands to be executed by recipes.
51+
# This is a requirement for 'setup-envtest.sh' in the test target.
52+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
53+
SHELL = /usr/bin/env bash -o pipefail
54+
.SHELLFLAGS = -ec
55+
56+
all: build
57+
58+
##@ General
59+
60+
# The help target prints out all targets with their descriptions organized
61+
# beneath their categories. The categories are represented by '##@' and the
62+
# target descriptions by '##'. The awk commands is responsible for reading the
63+
# entire set of makefiles included in this invocation, looking for lines of the
64+
# file as xyz: ## something, and then pretty-format the target and help. Then,
65+
# if there's a line with ##@ something, that gets pretty-printed as a category.
66+
# More info on the usage of ANSI control characters for terminal formatting:
67+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
68+
# More info on the awk command:
69+
# http://linuxcommand.org/lc3_adv_awk.php
70+
71+
help: ## Display this help.
72+
@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)
73+
74+
##@ Development
75+
76+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
77+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
78+
79+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
80+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
81+
82+
fmt: ## Run go fmt against code.
83+
go fmt ./...
84+
85+
vet: ## Run go vet against code.
86+
go vet ./...
87+
88+
test: manifests generate fmt vet envtest ## Run tests.
89+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
90+
91+
##@ Build
92+
93+
build: generate fmt vet ## Build manager binary.
94+
go build -o bin/manager main.go
95+
96+
run: manifests generate fmt vet ## Run a controller from your host.
97+
go run ./main.go
98+
99+
docker-build: test ## Build docker image with the manager.
100+
docker build -t ${IMG} .
101+
102+
docker-push: ## Push docker image with the manager.
103+
docker push ${IMG}
104+
105+
##@ Deployment
106+
107+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
108+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
109+
110+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
111+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
112+
113+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
114+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
115+
$(KUSTOMIZE) build config/default | kubectl apply -f -
116+
117+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
118+
$(KUSTOMIZE) build config/default | kubectl delete -f -
119+
120+
121+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
122+
controller-gen: ## Download controller-gen locally if necessary.
123+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
124+
125+
KUSTOMIZE = $(shell pwd)/bin/kustomize
126+
kustomize: ## Download kustomize locally if necessary.
127+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
128+
129+
ENVTEST = $(shell pwd)/bin/setup-envtest
130+
envtest: ## Download envtest-setup locally if necessary.
131+
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
132+
133+
# go-get-tool will 'go get' any package $2 and install it to $1.
134+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
135+
define go-get-tool
136+
@[ -f $(1) ] || { \
137+
set -e ;\
138+
TMP_DIR=$$(mktemp -d) ;\
139+
cd $$TMP_DIR ;\
140+
go mod init tmp ;\
141+
echo "Downloading $(2)" ;\
142+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
143+
rm -rf $$TMP_DIR ;\
144+
}
145+
endef
146+
147+
.PHONY: bundle
148+
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
149+
operator-sdk generate kustomize manifests -q
150+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
151+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
152+
operator-sdk bundle validate ./bundle
153+
154+
.PHONY: bundle-build
155+
bundle-build: ## Build the bundle image.
156+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
157+
158+
.PHONY: bundle-push
159+
bundle-push: ## Push the bundle image.
160+
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
161+
162+
.PHONY: opm
163+
OPM = ./bin/opm
164+
opm: ## Download opm locally if necessary.
165+
ifeq (,$(wildcard $(OPM)))
166+
ifeq (,$(shell which opm 2>/dev/null))
167+
@{ \
168+
set -e ;\
169+
mkdir -p $(dir $(OPM)) ;\
170+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
171+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
172+
chmod +x $(OPM) ;\
173+
}
174+
else
175+
OPM = $(shell which opm)
176+
endif
177+
endif
178+
179+
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
180+
# These images MUST exist in a registry and be pull-able.
181+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
182+
183+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
184+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
185+
186+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
187+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
188+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
189+
endif
190+
191+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
192+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
193+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
194+
.PHONY: catalog-build
195+
catalog-build: opm ## Build a catalog image.
196+
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
197+
198+
# Push the catalog image.
199+
.PHONY: catalog-push
200+
catalog-push: ## Push a catalog image.
201+
$(MAKE) docker-push IMG=$(CATALOG_IMG)

PROJECT

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
domain: integreatly.org
2+
layout:
3+
- go.kubebuilder.io/v3
4+
plugins:
5+
manifests.sdk.operatorframework.io/v2: {}
6+
scorecard.sdk.operatorframework.io/v2: {}
7+
projectName: grafana-operator-experimental
8+
repo: github.com/grafana-operator/grafana-operator-experimental
9+
resources:
10+
- api:
11+
crdVersion: v1
12+
namespaced: true
13+
controller: true
14+
domain: integreatly.org
15+
group: grafana
16+
kind: Grafana
17+
path: github.com/grafana-operator/grafana-operator-experimental/api/v1beta1
18+
version: v1beta1
19+
version: "3"

0 commit comments

Comments
 (0)