Skip to content

Commit b8de4f3

Browse files
committed
init
1 parent e783aa4 commit b8de4f3

Some content is hidden

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

44 files changed

+2128
-0
lines changed

Diff for: .dockerignore

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

Diff for: Dockerfile

+27
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"]

Diff for: Makefile

+222
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
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+
# ankri.io/heimdall-bundle:$VERSION and ankri.io/heimdall-catalog:$VERSION.
32+
IMAGE_TAG_BASE ?= ankri.io/heimdall
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+
.PHONY: all
57+
all: build
58+
59+
##@ General
60+
61+
# The help target prints out all targets with their descriptions organized
62+
# beneath their categories. The categories are represented by '##@' and the
63+
# target descriptions by '##'. The awk commands is responsible for reading the
64+
# entire set of makefiles included in this invocation, looking for lines of the
65+
# file as xyz: ## something, and then pretty-format the target and help. Then,
66+
# if there's a line with ##@ something, that gets pretty-printed as a category.
67+
# More info on the usage of ANSI control characters for terminal formatting:
68+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
69+
# More info on the awk command:
70+
# http://linuxcommand.org/lc3_adv_awk.php
71+
72+
.PHONY: help
73+
help: ## Display this help.
74+
@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)
75+
76+
##@ Development
77+
78+
.PHONY: manifests
79+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
80+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
81+
82+
.PHONY: generate
83+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
84+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
85+
86+
.PHONY: fmt
87+
fmt: ## Run go fmt against code.
88+
go fmt ./...
89+
90+
.PHONY: vet
91+
vet: ## Run go vet against code.
92+
go vet ./...
93+
94+
.PHONY: test
95+
test: manifests generate fmt vet envtest ## Run tests.
96+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
97+
98+
##@ Build
99+
100+
.PHONY: build
101+
build: generate fmt vet ## Build manager binary.
102+
go build -o bin/manager main.go
103+
104+
.PHONY: run
105+
run: manifests generate fmt vet ## Run a controller from your host.
106+
go run ./main.go
107+
108+
.PHONY: docker-build
109+
docker-build: test ## Build docker image with the manager.
110+
docker build -t ${IMG} .
111+
112+
.PHONY: docker-push
113+
docker-push: ## Push docker image with the manager.
114+
docker push ${IMG}
115+
116+
##@ Deployment
117+
118+
ifndef ignore-not-found
119+
ignore-not-found = false
120+
endif
121+
122+
.PHONY: install
123+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
124+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
125+
126+
.PHONY: uninstall
127+
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.
128+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
129+
130+
.PHONY: deploy
131+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
132+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
133+
$(KUSTOMIZE) build config/default | kubectl apply -f -
134+
135+
.PHONY: undeploy
136+
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.
137+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
138+
139+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
140+
.PHONY: controller-gen
141+
controller-gen: ## Download controller-gen locally if necessary.
142+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
143+
144+
KUSTOMIZE = $(shell pwd)/bin/kustomize
145+
.PHONY: kustomize
146+
kustomize: ## Download kustomize locally if necessary.
147+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
148+
149+
ENVTEST = $(shell pwd)/bin/setup-envtest
150+
.PHONY: envtest
151+
envtest: ## Download envtest-setup locally if necessary.
152+
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
153+
154+
# go-get-tool will 'go get' any package $2 and install it to $1.
155+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
156+
define go-get-tool
157+
@[ -f $(1) ] || { \
158+
set -e ;\
159+
TMP_DIR=$$(mktemp -d) ;\
160+
cd $$TMP_DIR ;\
161+
go mod init tmp ;\
162+
echo "Downloading $(2)" ;\
163+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
164+
rm -rf $$TMP_DIR ;\
165+
}
166+
endef
167+
168+
.PHONY: bundle
169+
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
170+
operator-sdk generate kustomize manifests -q
171+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
172+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
173+
operator-sdk bundle validate ./bundle
174+
175+
.PHONY: bundle-build
176+
bundle-build: ## Build the bundle image.
177+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
178+
179+
.PHONY: bundle-push
180+
bundle-push: ## Push the bundle image.
181+
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
182+
183+
.PHONY: opm
184+
OPM = ./bin/opm
185+
opm: ## Download opm locally if necessary.
186+
ifeq (,$(wildcard $(OPM)))
187+
ifeq (,$(shell which opm 2>/dev/null))
188+
@{ \
189+
set -e ;\
190+
mkdir -p $(dir $(OPM)) ;\
191+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
192+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.19.1/$${OS}-$${ARCH}-opm ;\
193+
chmod +x $(OPM) ;\
194+
}
195+
else
196+
OPM = $(shell which opm)
197+
endif
198+
endif
199+
200+
# 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).
201+
# These images MUST exist in a registry and be pull-able.
202+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
203+
204+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
205+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
206+
207+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
208+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
209+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
210+
endif
211+
212+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
213+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
214+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
215+
.PHONY: catalog-build
216+
catalog-build: opm ## Build a catalog image.
217+
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
218+
219+
# Push the catalog image.
220+
.PHONY: catalog-push
221+
catalog-push: ## Push a catalog image.
222+
$(MAKE) docker-push IMG=$(CATALOG_IMG)

Diff for: PROJECT

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
domain: ankri.io
2+
layout:
3+
- go.kubebuilder.io/v3
4+
plugins:
5+
manifests.sdk.operatorframework.io/v2: {}
6+
scorecard.sdk.operatorframework.io/v2: {}
7+
projectName: heimdall
8+
repo: github.com/itayankri/Heimdall
9+
resources:
10+
- api:
11+
crdVersion: v1
12+
namespaced: true
13+
controller: true
14+
domain: ankri.io
15+
group: valhalla
16+
kind: Valhalla
17+
path: github.com/itayankri/Heimdall/api/v1alpha1
18+
version: v1alpha1
19+
version: "3"

Diff for: api/v1alpha1/groupversion_info.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha1 contains API Schema definitions for the valhalla v1alpha1 API group
18+
//+kubebuilder:object:generate=true
19+
//+groupName=valhalla.ankri.io
20+
package v1alpha1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "valhalla.ankri.io", Version: "v1alpha1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

Diff for: api/v1alpha1/valhalla_types.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// ValhallaSpec defines the desired state of Valhalla
27+
type ValhallaSpec struct {
28+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29+
// Important: Run "make" to regenerate code after modifying this file
30+
31+
// Foo is an example field of Valhalla. Edit valhalla_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
33+
}
34+
35+
// ValhallaStatus defines the observed state of Valhalla
36+
type ValhallaStatus struct {
37+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38+
// Important: Run "make" to regenerate code after modifying this file
39+
}
40+
41+
//+kubebuilder:object:root=true
42+
//+kubebuilder:subresource:status
43+
44+
// Valhalla is the Schema for the valhallas API
45+
type Valhalla struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec ValhallaSpec `json:"spec,omitempty"`
50+
Status ValhallaStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// ValhallaList contains a list of Valhalla
56+
type ValhallaList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []Valhalla `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&Valhalla{}, &ValhallaList{})
64+
}

0 commit comments

Comments
 (0)