Skip to content

Commit

Permalink
restored olm packages (#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewChubatiuk authored Jul 3, 2024
1 parent 3e58b8a commit 38601c2
Show file tree
Hide file tree
Showing 55 changed files with 949 additions and 108 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ on:
types:
- opened
- reopened
- synchronize
- ready_for_review
- converted_to_draft
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
name: test and build
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Restore binaries from cache
uses: actions/cache/restore@v4
with:
path: ./bin
key: binary
- name: Setup Go
uses: actions/setup-go@v5
with:
Expand All @@ -33,21 +39,20 @@ jobs:
with:
scan-type: "fs"
ignore-unfixed: true
format: "template"
template: "@/contrib/sarif.tpl"
format: "sarif"
output: "trivy-results.sarif"
severity: "HIGH,CRITICAL,MEDIUM"
vuln-type: "os,library"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results.sarif"
- name: Set output variables
id: vars
run: |
IMAGE_TAG=${GITHUB_SHA:0:7}
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: lint and test
- name: Lint, Test and Build
if: github.event.pull_request.draft == false
env:
GO111MODULE: on
Expand All @@ -57,20 +62,15 @@ jobs:
make lint
make test
TAG=${TAG} make test-e2e
- name: build binary
env:
GO111MODULE: on
TAG: ${{ steps.vars.outputs.IMAGE_TAG }}
run: |
make build
- name: build crosscompile and push to remote registry
env:
TAG: ${{ steps.vars.outputs.IMAGE_TAG }}
run: |
if [ -n '${{secrets.REPO_KEY}}' ]; then
echo ${{secrets.REPO_KEY}} | docker login --username ${{secrets.REPO_USER}} --password-stdin
make publish
else
echo "there is no docker secret, just build"
make build
fi
- name: Prapare binary cache
uses: actions/cache@v4
with:
path: ./bin
key: binary
70 changes: 70 additions & 0 deletions .github/workflows/operatorhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Publish OperatorHub release

on:
workflow_run:
workflows:
- Release
types:
- completed

jobs:
update:
name: Publish new OperatorHub release
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && ! contains(github.event.workflow_run.head_branch, '-') }}
strategy:
matrix:
repo:
- fork: VictoriaMetrics/operatorhub-operators
upstream: k8s-operatorhub/community-operators
- fork: VictoriaMetrics/openshift-community-operators-prod
upstream: redhat-openshift-ecosystem/community-operators-prod
- fork: VictoriaMetrics/openshift-certified-operators
upstream: redhat-openshift-ecosystem/certified-operators
steps:
- name: Check out OperatorHub operators repo fork
uses: actions/checkout@v4
with:
repository: ${{ matrix.repo.upstream }}
ref: main
token: ${{ secrets.VM_BOT_GH_TOKEN }}
path: __k8s-operatorhub-repo

- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.VM_BOT_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.VM_BOT_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
workdir: __k8s-operatorhub-repo

- uses: dawidd6/action-download-artifact@v6
with:
name: olm
workflow: main.yaml
github_token: ${{ secrets.VM_BOT_GH_TOKEN }}
run_id: ${{ github.event.workflow_run.id }}
path: bundle

- name: Add operatorhub bundle
id: update
run: |
mv bundle/* __k8s-operatorhub-repo/operators/victoriametrics-operator/
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
push-to-fork: VictoriaMetrics/operatorhub-operators
add-paths: operators/victoriametrics-operator
signoff: true
author: Github Actions <[email protected]>
path: __k8s-operatorhub-repo
push-to-fork: ${{ matrix.repo.fork }}
branch: vm-operator-release-{{ github.event.release.tag_name }}
token: ${{ secrets.VM_BOT_GH_TOKEN }}
delete-branch: true
title: "victoriametrics-operator: update operator ${{ github.event.release.tag_name }}"
body: |
Added OLM package for [VictoriaMetrics operator ${{ github.event.release.tag_name }}"](https://github.com/VictoriaMetrics/operator/releases/tag/${{ github.event.release.tag_name }})
> Auto-generated by `Github Actions Bot`
22 changes: 17 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,36 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Restore binaries from cache
uses: actions/cache/restore@v4
with:
path: ./bin
key: binary
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
id: go
- name: build binary
- name: lint, test and build
env:
TAG: ${{ github.event.release.tag_name }}
run: |
make lint
make test
make build
- name: build crosscompile and push to remote registry
env:
TAG: "${{ github.event.release.tag_name }}"
run: |
echo ${{secrets.REPO_KEY}} | docker login --username ${{secrets.REPO_USER}} --password-stdin
make publish
TAG=${TAG} make olm
- name: Prapare binary cache
uses: actions/cache@v4
with:
path: ./bin
key: binary
- uses: actions/upload-artifact@v4
with:
name: olm
path: bundle
retention-days: 1
- name: Upload Release CRDs
id: upload-release-crds
uses: actions/upload-release-asset@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sandbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.VM_BOT_GH_TOKEN }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6
with:
path: "__vm-ops-repo"
branch: sandbox-operator-release-automation
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ Dockerfile.cross
.idea
bin/
build/_output
bundle_crd.zip
bundle*
operator.zip
bundle.Dockerfile
coverage.txt
doc-print
build/_test
Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ARG REPO
ARG ROOT

# Build the manager binary
FROM golang:1.22 AS builder
Expand All @@ -18,21 +19,20 @@ COPY cmd/ cmd/
COPY api/ api/
COPY internal/ internal/
ARG REPO
ARG ROOT

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ${REPO} ./cmd/${REPO}/...
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o app ${ROOT}/

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
ARG REPO
ENV REPO=${REPO}
WORKDIR /
COPY --from=builder /workspace/${REPO} .
COPY --from=builder /workspace/app .
USER 65532:65532

ENTRYPOINT ["/${REPO}"]
ENTRYPOINT ["/app"]
27 changes: 25 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Image URL to use all building/pushing image targets
REGISTRY ?= docker.io
REPO ?= operator
ROOT ?= ./cmd
ORG ?= victoriametrics
TAG ?= v0.46.0
VERSION ?= $(TAG:v%=%)
NAMESPACE ?= vm
BUILDINFO_TAG ?= $(shell echo $$(git describe --long --all | tr '/' '-')$$( \
git diff-index --quiet HEAD -- || echo '-dirty-'$$(git diff-index -u HEAD | openssl sha1 | cut -d' ' -f2 | cut -c 1-8)))
OVERLAY ?= config/default

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.30.0
PLATFORM = $(shell uname -o)

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -136,6 +139,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
docker-build: ## Build docker image with the manager.
$(CONTAINER_TOOL) build \
--build-arg REPO=$(REPO) \
--build-arg ROOT=$(ROOT) \
${DOCKER_BUILD_ARGS} \
-t $(REGISTRY)/$(ORG)/$(REPO):$(TAG) \
-t $(REGISTRY)/$(ORG)/$(REPO):$(BUILDINFO_TAG) .
Expand Down Expand Up @@ -164,6 +168,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
--push \
--platform=$(PLATFORMS) \
--build-arg REPO=$(REPO) \
--build-arg ROOT=$(ROOT) \
${DOCKER_BUILD_ARGS} \
--tag $(REGISTRY)/$(ORG)/$(REPO):$(TAG) \
--tag $(REGISTRY)/$(ORG)/$(REPO):$(BUILDINFO_TAG) \
Expand All @@ -172,15 +177,26 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
rm Dockerfile.cross

publish:
REPO=operator $(MAKE) docker-buildx
REPO=config-reloader $(MAKE) docker-buildx
REPO=operator ROOT=./cmd $(MAKE) docker-buildx
REPO=config-reloader ROOT=./cmd/config-reloader $(MAKE) docker-buildx

.PHONY: build-installer
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
mkdir -p dist
cd config/manager && $(KUSTOMIZE) edit set image manager=$(REGISTRY)/$(ORG)/$(REPO):$(TAG)
$(KUSTOMIZE) build config/default > dist/install.yaml

olm: operator-sdk docs
rm -rf bundle*
$(OPERATOR_SDK) generate kustomize manifests -q
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle \
-q --overwrite --version $(VERSION) --channels=beta --output-dir=bundle/$(VERSION)
$(if $(findstring $(PLATFORM),Darwin), \
sed -i '', \
sed -i) 's/$(ORG)\/$(REPO):.*/$(ORG)\/$(REPO):$(TAG)/g' bundle/$(VERSION)/manifests/*
$(OPERATOR_SDK) bundle validate ./bundle/$(VERSION)
cp config/manifests/ci.yaml bundle/

##@ Deployment

ifndef ignore-not-found
Expand Down Expand Up @@ -237,6 +253,7 @@ CLIENT_GEN = $(LOCALBIN)/client-gen-$(CODEGENERATOR_VERSION)
LISTER_GEN = $(LOCALBIN)/lister-gen-$(CODEGENERATOR_VERSION)
INFORMER_GEN = $(LOCALBIN)/informer-gen-$(CODEGENERATOR_VERSION)
KIND = $(LOCALBIN)/kind-$(KIND_VERSION)
OPERATOR_SDK = $(LOCALBIN)/operator-sdk-$(OPERATOR_SDK_VERSION)
ENVCONFIG_DOCS = $(LOCALBIN)/envconfig-docs-$(ENVCONFIG_DOCS_VERSION)
CRD_REF_DOCS = $(LOCALBIN)/crd-ref-docs-$(CRD_REF_DOCS_VERSION)

Expand All @@ -247,6 +264,7 @@ ENVTEST_VERSION ?= release-0.18
GOLANGCI_LINT_VERSION ?= v1.59.1
CODEGENERATOR_VERSION ?= v0.30.2
KIND_VERSION ?= v0.23.0
OPERATOR_SDK_VERSION ?= v1.35.0
ENVCONFIG_DOCS_VERSION ?= latest
CRD_REF_DOCS_VERSION ?= latest

Expand Down Expand Up @@ -293,6 +311,11 @@ envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))

.PHONY: operator-sdk
operator-sdk: $(OPERATOR_SDK)
$(OPERATOR_SDK): $(LOCALBIN)
$(call go-install-tool,$(OPERATOR_SDK),github.com/operator-framework/operator-sdk/cmd/operator-sdk,$(OPERATOR_SDK_VERSION))

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
Expand Down
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,13 @@ resources:
conversion: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMScrapeConfig
path: github.com/VictoriaMetrics/operator/api/operator/v1beta1
version: v1beta1
version: "3"
Loading

0 comments on commit 38601c2

Please sign in to comment.