Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K8SPSMDB-1183 bundle generations for psmdb #1681

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* @hors @egegunes @inelpandzic @pooknull
* @hors @egegunes @inelpandzic @pooknull @nmarukovich
/e2e-tests/ @nmarukovich @ptankov @jvpasinatto @eleo007
Jenkinsfile @nmarukovich @ptankov @jvpasinatto @eleo007
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ updates:
time: "01:00"
reviewers:
- hors
- tplavcic
- nmarukovich
ignore:
# ignore patch updates for all dependencies
- dependency-name: "*"
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,7 @@ bin/
### VisualStudioCode ###
.vscode/*
.history

projects/
installers/olm/operator_*.yaml
installers/olm/bundles
10 changes: 10 additions & 0 deletions config/bundle/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../crd
- ../rbac/namespace
- ../manager/namespace
images:
- name: percona-server-mongodb-operator
newName: perconalab/percona-server-mongodb-operator
newTag: main
5 changes: 5 additions & 0 deletions config/community/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../operator
2 changes: 1 addition & 1 deletion config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resources:
- bases/psmdb.percona.com_perconaservermongodbs.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesJson6902:
patches:
- path: patches/deprecated-1.2.json
target:
name: perconaservermongodbs.psmdb.percona.com
Expand Down
8 changes: 8 additions & 0 deletions config/manager/cluster/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- cw-operator.yaml
images:
- name: psmdb-operator
newName: perconalab/percona-server-mongodb-operator
newTag: main
8 changes: 8 additions & 0 deletions config/manager/namespace/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- operator.yaml
images:
- name: psmdb-operator
newName: perconalab/percona-server-mongodb-operator
newTag: main
6 changes: 6 additions & 0 deletions config/marketplace/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../operator

6 changes: 6 additions & 0 deletions config/operator/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../bundle

7 changes: 7 additions & 0 deletions config/rbac/cluster/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- service_account.yaml
- role.yaml
- role_binding.yaml
7 changes: 7 additions & 0 deletions config/rbac/namespace/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- service_account.yaml
- role.yaml
- role_binding.yaml
6 changes: 6 additions & 0 deletions config/redhat/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../operator

139 changes: 139 additions & 0 deletions installers/olm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
NAME ?= percona-server-mongodb-operator
IMAGE_TAG_OWNER ?= perconalab
IMAGE_TAG_BASE ?= $(IMAGE_TAG_OWNER)/$(NAME)
SED := $(shell which gsed || which sed)
VERSION ?= $(shell git rev-parse --abbrev-ref HEAD | $(SED) -e 's^/^-^g; s^[.]^-^g;' | tr '[:upper:]' '[:lower:]')
IMAGE ?= $(IMAGE_TAG_BASE):$(VERSION)
MODE ?= namespace
DEPLOYDIR = ./deploy

BUNDLEDIR = $(DEPLOYDIR)/csv/redhat
BUNDLE_CHANNELS := --channels=stable
BUNDLE_DEFAULT_CHANNEL := --default-channel=stable
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.23
.DEFAULT_GOAL := help
.SUFFIXES:

CONTAINER ?= docker
OPENSHIFT_VERSIONS ?= v4.13-v4.16
PACKAGE_CHANNEL ?= stable
MIN_KUBE_VERSION ?= 1.24.0
DOCKER_DEFAULT_PLATFORM ?= linux/amd64
SHELL := /bin/bash
REPO_ROOT = $(shell git rev-parse --show-toplevel)

GREEN := $(shell tput setaf 2)
RESET := $(shell tput sgr0)

export VERSION
export BUNDLE_REPO
export OPENSHIFT_VERSIONS
export PACKAGE_CHANNEL
export MIN_KUBE_VERSION
export DOCKER_DEFAULT_PLATFORM
export MODE

REPO_ROOT = $(shell git rev-parse --show-toplevel)

distros = community redhat marketplace

check-version:
ifndef VERSION
$(error VERSION is not set)
endif

KUSTOMIZE = $(REPO_ROOT)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work for me, when I execute make bundles I get an error in this line:
/bin/bash: ..repos/percona-server-mongodb-operator/bin/kustomize: No such file or directory

Yes, I don't have kustomize in bin/ folder, but this go-get-tool should be able to download it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I will check it too. And I agree that go-get-tool should download it.

$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update this? I see in github there is v5.5.0 version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use this version for all our operators in all our makefile. I can check can we update it or not)


.PHONY: bundles
bundles: ## Build OLM bundles
bundles: check-version $(distros:%=bundles/%)

# https://olm.operatorframework.io/docs/tasks/creating-operator-bundle/#validating-your-bundle
# https://github.com/operator-framework/community-operators/blob/8a36a33/docs/packaging-required-criteria-ocp.md
.PHONY: bundles/community
bundles/community:
cd ../../config/manager/$(MODE)/ && $(KUSTOMIZE) edit set image psmdb-operator=$(IMAGE)
./generate.sh community

env operator-sdk bundle validate $@ --select-optional='suite=operatorframework'
env operator-sdk bundle validate $@ --select-optional='name=community' --optional-values='index-path=$@/Dockerfile'
@echo "$(GREEN)!!!!!!!!!!! Build stored in installers/olm/bundles/community !!!!!!!!!!!!!!!$(RESET)"

.PHONY: bundles/redhat
bundles/redhat:
cd ../../config/manager/$(MODE)/ && $(KUSTOMIZE) edit set image psmdb-operator=$(IMAGE)
./generate.sh redhat
env operator-sdk bundle validate $@ --select-optional='suite=operatorframework'
@echo "$(GREEN)!!!!!!!!!!! Build stored in installers/olm/bundles/redhat !!!!!!!!!!!!!!!$(RESET)"

# The 'marketplace' configuration is currently identical to the 'redhat', so we just copy it here.
.PHONY: bundles/marketplace
bundles/marketplace:
cd ../../config/manager/$(MODE)/ && $(KUSTOMIZE) edit set image psmdb-operator=$(IMAGE)
./generate.sh marketplace
env operator-sdk bundle validate $@ --select-optional='suite=operatorframework'
@echo "$(GREEN)!!!!!!!!!!! Build stored in installers/olm/bundles/marketplace !!!!!!!!!!!!!!!$(RESET)"

.PHONY: clean
clean: clean-deprecated
clean: ## Remove generated files and downloaded tools
rm -rf ./bundles ./projects ./tools

.PHONY: clean-deprecated
clean-deprecated:
rm -rf ./package

.PHONY: help
help: ALIGN=18
help: ## Print this message
@awk -F ': ## ' -- "/^[^':]+: ## /"' { printf "'$$(tput bold)'%-$(ALIGN)s'$$(tput sgr0)' %s\n", $$1, $$2 }' $(MAKEFILE_LIST)

.PHONY: install-olm
install-olm: ## Install OLM in Kubernetes
env operator-sdk olm install

.PHONY: tools
tools: ## Download tools needed to build bundles

tools: tools/$(SYSTEM)/jq
tools/$(SYSTEM)/jq:
install -d '$(dir $@)'
curl -fSL -o '$@' "https://github.com/stedolan/jq/releases/download/jq-1.7.1/jq-$$(SYSTEM='$(SYSTEM)'; \
case "$$SYSTEM" in \
(linux-*) echo "$${SYSTEM/-amd/}";; (darwin-*) echo "$${SYSTEM/darwin-*/osx-amd64}";; (*) echo '$(SYSTEM)';; \
esac)"
chmod u+x '$@'

tools: tools/$(SYSTEM)/kubectl
tools/$(SYSTEM)/kubectl:
install -d '$(dir $@)'
curl -fSL -o '$@' 'https://dl.k8s.io/release/$(shell curl -Ls https://dl.k8s.io/release/stable-1.21.txt)/bin/$(OS_KERNEL)/$(OS_MACHINE)/kubectl'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update this? stable-1.21

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which one do you want to use?

chmod u+x '$@'

# quay.io/operator-framework/operator-sdk
tools: tools/$(SYSTEM)/operator-sdk
tools/$(SYSTEM)/operator-sdk:
install -d '$(dir $@)'
curl -fSL -o '$@' 'https://github.com/operator-framework/operator-sdk/releases/download/v1.19.1/operator-sdk_$(OS_KERNEL)_$(OS_MACHINE)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update this?

chmod u+x '$@'

tools: tools/$(SYSTEM)/opm
tools/$(SYSTEM)/opm:
install -d '$(dir $@)'
curl -fSL -o '$@' 'https://github.com/operator-framework/operator-registry/releases/download/v1.33.0/$(OS_KERNEL)-$(OS_MACHINE)-opm'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update this? Also, shoud this be aligned with the version from operator-sdk?

chmod u+x '$@'

tools/$(SYSTEM)/venv:
install -d '$(dir $@)'
python3 -m venv '$@'

tools: tools/$(SYSTEM)/yq
tools/$(SYSTEM)/yq: | tools/$(SYSTEM)/venv
'tools/$(SYSTEM)/venv/bin/python' -m pip install yq
cd '$(dir $@)' && ln -s venv/bin/yq

30 changes: 30 additions & 0 deletions installers/olm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
1. To generate bundle correctly please set env variables (default values for these variables you can check in makefile):
```bash
# operator version
export VERSION=1.18.0
# By default we use perconalab for tag owner. Please update this variable to use another repo
export IMAGE_TAG_OWNER=percona
# Min k8s version
export MIN_KUBE_VERSION=1.27.0
# Openshift versions:
export OPENSHIFT_VERSIONS="v4.13-v4.16"
# Set namespace or cluster (to generate bundles for cluster-wide)
MODE=namespace
```
2. Also it could be useful to check variable in makefile and update if you need something extra. For the most cases to update these variables is enough
3. Choose the mode (cluster (for cluster-wide) or namespace) and update config/bundle/kustomization.yaml.
```yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../crd
- ../rbac/namespace # replace namespace to cluster for cluster-wide
- ../manager/namespace # replace namespace to cluster for cluster-wide
images:
- name: percona-server-mongodb-operator
newName: perconalab/percona-server-mongodb-operator
newTag: main
```
4. Update spec.description in bundle.csv.yaml with features added in this release.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

give full path

5. Run bundle generation:
```make bundles```
16 changes: 16 additions & 0 deletions installers/olm/bundle.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Used to build the bundle image. This file is ignored by the community operator
# registries which work with bundle directories instead.
# https://operator-framework.github.io/community-operators/packaging-operator/

FROM scratch AS builder

COPY manifests/ /build/manifests/
COPY metadata/ /build/metadata/

FROM scratch

# ANNOTATIONS is replaced with bundle.annotations.yaml
LABEL \
${ANNOTATIONS}

COPY --from=builder /build/ /
12 changes: 12 additions & 0 deletions installers/olm/bundle.annotations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
annotations:
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
operators.operatorframework.io.bundle.manifests.v1: manifests/
operators.operatorframework.io.bundle.metadata.v1: metadata/
operators.operatorframework.io.bundle.package.v1: percona-server-mongodb-operator
operators.operatorframework.io.bundle.channels.v1: stable
operators.operatorframework.io.bundle.channel.default.v1: stable
com.redhat.openshift.versions: 'v4.13'
org.opencontainers.image.authors: [email protected]
org.opencontainers.image.url: https://percona.com
org.opencontainers.image.vendor: Percona
Loading