-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enhance container by installing operator-sdk * Updated... 24.03. * Update devcontainer.json * Updated logic * Adding mocks * Implemented ClusterSilence logic * Updating logic and tests * Add first version of github workflows * Add pointer helper * Test * Some fixes and minimal testing * Some fixes and minimal testing * Updating .gitignore * Adding initial helm chart * Cleanup Makefile * Fix alertmanager_controller.go * Updated * Updated crd's * Fix workflow * Enhance Makefile * go fmt * Fix linting issues * Add publish workflow * Fix testing * Fix testing
- Loading branch information
1 parent
e97ed4f
commit d1ae5a3
Showing
52 changed files
with
3,181 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
#! /usr/bin/env sh | ||
|
||
cd /workspace/silentstorm | ||
installOperatorSDK () { | ||
if ! type "operator-sdk" > /dev/null; then | ||
ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac) | ||
OS=$(uname | awk '{print tolower($0)}') | ||
OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.34.1 | ||
curl -LO ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH} | ||
mkdir -p /home/${USER}/bin | ||
mv operator-sdk_${OS}_${ARCH} /home/${USER}/bin/operator-sdk | ||
chmod +x /home/${USER}/bin/operator-sdk | ||
fi | ||
} | ||
|
||
cd /workspaces/silentstorm | ||
go mod tidy | ||
installOperatorSDK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
release: | ||
types: | ||
- published | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: docker/metadata-action@v5 | ||
id: meta | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
- uses: docker/build-push-action@v5 | ||
with: | ||
push: true | ||
file: ./Containerfile | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: linux/amd64 | ||
provenance: false | ||
release-helm-chart: | ||
permissions: | ||
contents: write | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event.release.tag_name != '' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- run: | | ||
git config user.name "$GITHUB_ACTOR" | ||
git config user.email "[email protected]" | ||
- uses: azure/setup-helm@v3 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
- run: | | ||
VERSION=$(echo "${{github.event.release.tag_name }}" | sed 's/v//g') | ||
sed -i "s/^version:.*$/version: ${VERSION}/" ./helm/silentstorm/Chart.yaml | ||
sed -i "s/^appVersion:.*$/appVersion: v${VERSION}/" ./helm/silentstorm/Chart.yaml | ||
- uses: helm/[email protected] | ||
with: | ||
charts_dir: helm | ||
env: | ||
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
basic: | ||
name: basic | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22' | ||
cache: false | ||
- uses: actions/checkout@v4 | ||
- run: go mod tidy && git diff --exit-code go.mod go.sum | ||
- run: go run github.com/elastic/[email protected] --config docs/config.yaml --renderer=markdown --output-path docs/api-reference.md | ||
helm: | ||
name: helm-lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: helm lint helm/silentstorm/ --strict | ||
- run: helm template chart helm/silentstorm > /dev/null | ||
golangci: | ||
name: golangci-lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22' | ||
cache: false | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v4 | ||
with: | ||
version: v1.54 | ||
ginkgo: | ||
name: unit-test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: '1.22' | ||
cache: false | ||
- uses: actions/checkout@v4 | ||
- run: go run github.com/onsi/ginkgo/v2/[email protected] -r --randomize-all --randomize-suites --race --trace --fail-on-pending --keep-going --vet off --cover --skip-package ./test/e2e | ||
- run: cat coverprofile.out | grep -v "zz_generated." > coverprofile.out.filtered | ||
- uses: shogo82148/actions-goveralls@v1 | ||
with: | ||
path-to-profile: coverprofile.out.filtered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
*.dll | ||
*.so | ||
*.dylib | ||
bin/* | ||
.bin/* | ||
Dockerfile.cross | ||
|
||
# Test binary, built with `go test -c` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,53 +5,12 @@ | |
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) | ||
VERSION ?= 0.0.1 | ||
|
||
# CHANNELS define the bundle channels used in the bundle. | ||
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") | ||
# To re-generate a bundle for other specific channels without changing the standard setup, you can: | ||
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable) | ||
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable") | ||
ifneq ($(origin CHANNELS), undefined) | ||
BUNDLE_CHANNELS := --channels=$(CHANNELS) | ||
endif | ||
|
||
# DEFAULT_CHANNEL defines the default channel used in the bundle. | ||
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable") | ||
# To re-generate a bundle for any other default channel without changing the default setup, you can: | ||
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable) | ||
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable") | ||
ifneq ($(origin DEFAULT_CHANNEL), undefined) | ||
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) | ||
endif | ||
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) | ||
|
||
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images. | ||
# This variable is used to construct full image tags for bundle and catalog images. | ||
# | ||
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both | ||
# biggold1310.ch/silentstorm-bundle:$VERSION and biggold1310.ch/silentstorm-catalog:$VERSION. | ||
IMAGE_TAG_BASE ?= biggold1310.ch/silentstorm | ||
|
||
# BUNDLE_IMG defines the image:tag used for the bundle. | ||
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>) | ||
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION) | ||
|
||
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command | ||
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) | ||
|
||
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests | ||
# You can enable this value if you would like to use SHA Based Digests | ||
# To enable set flag to true | ||
USE_IMAGE_DIGESTS ?= false | ||
ifeq ($(USE_IMAGE_DIGESTS), true) | ||
BUNDLE_GEN_FLAGS += --use-image-digests | ||
endif | ||
|
||
# Set the Operator SDK version to use. By default, what is installed on the system is used. | ||
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit. | ||
OPERATOR_SDK_VERSION ?= v1.34.1 | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG ?= controller:latest | ||
IMG ?= biggold1310.ch/silentstorm:latest | ||
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. | ||
ENVTEST_K8S_VERSION = 1.28.3 | ||
|
||
|
@@ -103,24 +62,47 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust | |
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
GOFUMPT ?= $(LOCALBIN)/gofumpt | ||
|
||
.PHONY: gofumpt | ||
gofumpt: $(GOFUMPT) ## Download helmify locally if necessary. | ||
$(GOFUMPT): $(LOCALBIN) | ||
test -s $(LOCALBIN)/gofumpt || GOBIN=$(LOCALBIN) go install mvdan.cc/gofumpt@latest | ||
|
||
.PHONY: fmt | ||
fmt: ## Run go fmt against code. | ||
go fmt ./... | ||
fmt: gofumpt ## Run go fmt against code. | ||
$(GOFUMPT) -w ./ | ||
|
||
.PHONY: vet | ||
vet: ## Run go vet against code. | ||
go vet ./... | ||
|
||
GINKGO ?= $(LOCALBIN)/ginkgo | ||
|
||
.PHONY: ginkgo | ||
ginkgo: $(GINKGO) ## Download helmify locally if necessary. | ||
$(GINKGO): $(LOCALBIN) | ||
test -s $(LOCALBIN)/ginkgo || GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/[email protected] | ||
|
||
.PHONY: test | ||
test: manifests generate fmt vet envtest ## Run tests. | ||
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out | ||
test: manifests generate fmt vet envtest mocks ## Run tests. | ||
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) -r --randomize-all --randomize-suites --race --trace --fail-on-pending --keep-going --vet off --cover --skip-package ./test/e2e | ||
|
||
# generate mocks | ||
mocks: mockgen | ||
$(MOCKGEN) -destination internal/mocks/alertmanager/alert/mock.go github.com/prometheus/alertmanager/api/v2/client/alert ClientService | ||
$(MOCKGEN) -destination internal/mocks/alertmanager/alertgroup/mock.go github.com/prometheus/alertmanager/api/v2/client/alertgroup ClientService | ||
$(MOCKGEN) -destination internal/mocks/alertmanager/general/mock.go github.com/prometheus/alertmanager/api/v2/client/general ClientService | ||
$(MOCKGEN) -destination internal/mocks/alertmanager/receiver/mock.go github.com/prometheus/alertmanager/api/v2/client/receiver ClientService | ||
$(MOCKGEN) -destination internal/mocks/alertmanager/silence/mock.go github.com/prometheus/alertmanager/api/v2/client/silence ClientService | ||
$(MOCKGEN) -destination internal/mocks/alertmanager/runtime/mock.go github.com/go-openapi/runtime ClientTransport | ||
|
||
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors. | ||
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up. | ||
test-e2e: | ||
go test ./test/e2e/ -v -ginkgo.v | ||
|
||
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint | ||
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint | ||
GOLANGCI_LINT_VERSION ?= v1.54.2 | ||
golangci-lint: | ||
@[ -f $(GOLANGCI_LINT) ] || { \ | ||
|
@@ -200,7 +182,7 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi | |
##@ Build Dependencies | ||
|
||
## Location to install dependencies to | ||
LOCALBIN ?= $(shell pwd)/bin | ||
LOCALBIN ?= $(shell pwd)/.bin | ||
$(LOCALBIN): | ||
mkdir -p $(LOCALBIN) | ||
|
||
|
@@ -209,10 +191,12 @@ KUBECTL ?= kubectl | |
KUSTOMIZE ?= $(LOCALBIN)/kustomize | ||
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen | ||
ENVTEST ?= $(LOCALBIN)/setup-envtest | ||
MOCKGEN ?= ${LOCALBIN}/mockgen | ||
|
||
## Tool Versions | ||
KUSTOMIZE_VERSION ?= v5.2.1 | ||
CONTROLLER_TOOLS_VERSION ?= v0.13.0 | ||
CONTROLLER_TOOLS_VERSION ?= v0.14.0 | ||
MOCKGEN_VERSION ?= v0.4.0 | ||
|
||
.PHONY: kustomize | ||
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading. | ||
|
@@ -227,13 +211,19 @@ $(KUSTOMIZE): $(LOCALBIN) | |
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten. | ||
$(CONTROLLER_GEN): $(LOCALBIN) | ||
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \ | ||
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) | ||
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION); | ||
|
||
.PHONY: envtest | ||
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. | ||
$(ENVTEST): $(LOCALBIN) | ||
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest | ||
|
||
.PHONY: mockgen | ||
mockgen: $(MOCKGEN) ## Download mockgen locally if necessary. If wrong version is installed, it will be overwritten. | ||
$(MOCKGEN): $(LOCALBIN) | ||
test -s $(LOCALBIN)/mockgen && $(LOCALBIN)/mockgen -version | grep -q $(MOCKGEN_VERSION) || \ | ||
GOBIN=$(LOCALBIN) go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION) | ||
|
||
.PHONY: operator-sdk | ||
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk | ||
operator-sdk: ## Download operator-sdk locally if necessary. | ||
|
@@ -251,58 +241,12 @@ OPERATOR_SDK = $(shell which operator-sdk) | |
endif | ||
endif | ||
|
||
.PHONY: bundle | ||
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files. | ||
$(OPERATOR_SDK) generate kustomize manifests -q | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) | ||
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) | ||
$(OPERATOR_SDK) bundle validate ./bundle | ||
|
||
.PHONY: bundle-build | ||
bundle-build: ## Build the bundle image. | ||
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . | ||
|
||
.PHONY: bundle-push | ||
bundle-push: ## Push the bundle image. | ||
$(MAKE) docker-push IMG=$(BUNDLE_IMG) | ||
|
||
.PHONY: opm | ||
OPM = $(LOCALBIN)/opm | ||
opm: ## Download opm locally if necessary. | ||
ifeq (,$(wildcard $(OPM))) | ||
ifeq (,$(shell which opm 2>/dev/null)) | ||
@{ \ | ||
set -e ;\ | ||
mkdir -p $(dir $(OPM)) ;\ | ||
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ | ||
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\ | ||
chmod +x $(OPM) ;\ | ||
} | ||
else | ||
OPM = $(shell which opm) | ||
endif | ||
endif | ||
|
||
# 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). | ||
# These images MUST exist in a registry and be pull-able. | ||
BUNDLE_IMGS ?= $(BUNDLE_IMG) | ||
HELMIFY ?= $(LOCALBIN)/helmify | ||
|
||
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0). | ||
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION) | ||
|
||
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image. | ||
ifneq ($(origin CATALOG_BASE_IMG), undefined) | ||
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) | ||
endif | ||
.PHONY: helmify | ||
helmify: $(HELMIFY) ## Download helmify locally if necessary. | ||
$(HELMIFY): $(LOCALBIN) | ||
test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@latest | ||
|
||
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'. | ||
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see: | ||
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator | ||
.PHONY: catalog-build | ||
catalog-build: opm ## Build a catalog image. | ||
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) | ||
|
||
# Push the catalog image. | ||
.PHONY: catalog-push | ||
catalog-push: ## Push a catalog image. | ||
$(MAKE) docker-push IMG=$(CATALOG_IMG) | ||
helm: manifests kustomize helmify | ||
$(KUSTOMIZE) build config/default | $(HELMIFY) -crd-dir -image-pull-secrets helm/silentstorm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.