diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index fcb580427..97bd121a2 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,3 +1,3 @@ -* @hors @egegunes @inelpandzic @pooknull -/e2e-tests/ @tplavcic @nmarukovich @ptankov @jvpasinatto @eleo007 -Jenkinsfile @tplavcic @nmarukovich @ptankov @jvpasinatto @eleo007 +* @hors @egegunes @inelpandzic @pooknull @nmarukovich +/e2e-tests/ @nmarukovich @ptankov @jvpasinatto @eleo007 +Jenkinsfile @nmarukovich @ptankov @jvpasinatto @eleo007 diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 79c61c9a2..007e404bb 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -23,7 +23,7 @@ updates: time: "01:00" reviewers: - hors - - tplavcic + - nmarukovich ignore: # ignore patch updates for all dependencies - dependency-name: "*" diff --git a/.gitignore b/.gitignore index 9a4b4a663..41a54b66b 100644 --- a/.gitignore +++ b/.gitignore @@ -85,3 +85,8 @@ e2e-tests/init-deploy/smallrun deploy/crds .editorconfig +projects/ +installers/olm/operator_*.yaml +installers/olm/bundles + + diff --git a/Makefile b/Makefile index 4a97bea17..4eb543ef9 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,6 @@ 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) DEPLOYDIR = ./deploy - # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.23 diff --git a/config/bundle/kustomization.yaml b/config/bundle/kustomization.yaml new file mode 100644 index 000000000..2c38e6d57 --- /dev/null +++ b/config/bundle/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../crd +- ../rbac/namespace +- ../manager/namespace +images: +- name: percona-xtradb-cluster-operator + newName: perconalab/percona-xtradb-cluster-operator + newTag: main diff --git a/config/community/kustomization.yaml b/config/community/kustomization.yaml new file mode 100644 index 000000000..305a5f27b --- /dev/null +++ b/config/community/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- ../operator diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index f283ad3f5..e5edcb591 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -7,7 +7,7 @@ resources: - bases/pxc.percona.com_perconaxtradbclusterrestores.yaml #+kubebuilder:scaffold:crdkustomizeresource -patchesJson6902: +patches: - path: patches/deprecated-1.2.json target: name: perconaxtradbclusters.pxc.percona.com diff --git a/config/manager/cluster/kustomization.yaml b/config/manager/cluster/kustomization.yaml new file mode 100644 index 000000000..39dd3ef8c --- /dev/null +++ b/config/manager/cluster/kustomization.yaml @@ -0,0 +1,13 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- manager-cluster.yaml +commonLabels: + app.kubernetes.io/component: operator + app.kubernetes.io/instance: percona-xtradb-cluster-operator + app.kubernetes.io/name: percona-xtradb-cluster-operator + app.kubernetes.io/part-of: percona-xtradb-cluster-operator +images: +- name: pxc-operator + newName: perconalab/percona-xtradb-cluster-operator + newTag: 1.15.0 diff --git a/config/manager/cluster/manager-cluster.yaml b/config/manager/cluster/manager-cluster.yaml new file mode 100644 index 000000000..15474a1de --- /dev/null +++ b/config/manager/cluster/manager-cluster.yaml @@ -0,0 +1,69 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: percona-xtradb-cluster-operator +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/component: operator + app.kubernetes.io/instance: percona-xtradb-cluster-operator + app.kubernetes.io/name: percona-xtradb-cluster-operator + app.kubernetes.io/part-of: percona-xtradb-cluster-operator + strategy: + rollingUpdate: + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + labels: + app.kubernetes.io/component: operator + app.kubernetes.io/instance: percona-xtradb-cluster-operator + app.kubernetes.io/name: percona-xtradb-cluster-operator + app.kubernetes.io/part-of: percona-xtradb-cluster-operator + spec: + terminationGracePeriodSeconds: 600 + containers: + - command: + - percona-xtradb-cluster-operator + env: + - name: LOG_STRUCTURED + value: 'false' + - name: LOG_LEVEL + value: INFO + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.annotations['olm.targetNamespaces'] + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OPERATOR_NAME + value: percona-xtradb-cluster-operator + - name: DISABLE_TELEMETRY + value: "false" + image: perconalab/percona-xtradb-cluster-operator:main + imagePullPolicy: Always + resources: + limits: + cpu: 200m + memory: 500Mi + requests: + cpu: 100m + memory: 20Mi + livenessProbe: + failureThreshold: 3 + httpGet: + path: /metrics + port: metrics + scheme: HTTP + name: percona-xtradb-cluster-operator + ports: + - containerPort: 8080 + name: metrics + protocol: TCP + serviceAccountName: percona-xtradb-cluster-operator + + diff --git a/config/manager/namespace/kustomization.yaml b/config/manager/namespace/kustomization.yaml new file mode 100644 index 000000000..d280a80c3 --- /dev/null +++ b/config/manager/namespace/kustomization.yaml @@ -0,0 +1,13 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- manager-namespace.yaml +commonLabels: + app.kubernetes.io/component: operator + app.kubernetes.io/instance: percona-xtradb-cluster-operator + app.kubernetes.io/name: percona-xtradb-cluster-operator + app.kubernetes.io/part-of: percona-xtradb-cluster-operator +images: +- name: pxc-operator + newName: perconalab/percona-xtradb-cluster-operator + newTag: 1.15.0 diff --git a/config/manager/namespace/manager-namespace.yaml b/config/manager/namespace/manager-namespace.yaml new file mode 100644 index 000000000..0432a725a --- /dev/null +++ b/config/manager/namespace/manager-namespace.yaml @@ -0,0 +1,68 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: percona-xtradb-cluster-operator +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/component: operator + app.kubernetes.io/instance: percona-xtradb-cluster-operator + app.kubernetes.io/name: percona-xtradb-cluster-operator + app.kubernetes.io/part-of: percona-xtradb-cluster-operator + strategy: + rollingUpdate: + maxUnavailable: 1 + type: RollingUpdate + template: + metadata: + labels: + app.kubernetes.io/component: operator + app.kubernetes.io/instance: percona-xtradb-cluster-operator + app.kubernetes.io/name: percona-xtradb-cluster-operator + app.kubernetes.io/part-of: percona-xtradb-cluster-operator + spec: + terminationGracePeriodSeconds: 600 + containers: + - command: + - percona-xtradb-cluster-operator + env: + - name: LOG_STRUCTURED + value: 'false' + - name: LOG_LEVEL + value: INFO + - name: WATCH_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OPERATOR_NAME + value: percona-xtradb-cluster-operator + - name: DISABLE_TELEMETRY + value: "false" + image: perconalab/percona-xtradb-cluster-operator:main + imagePullPolicy: Always + livenessProbe: + failureThreshold: 3 + httpGet: + path: /metrics + port: metrics + scheme: HTTP + resources: + limits: + cpu: 200m + memory: 500Mi + requests: + cpu: 100m + memory: 20Mi + name: percona-xtradb-cluster-operator + ports: + - containerPort: 8080 + name: metrics + protocol: TCP + serviceAccountName: percona-xtradb-cluster-operator diff --git a/config/marketplace/kustomization.yaml b/config/marketplace/kustomization.yaml new file mode 100644 index 000000000..42bd0a3da --- /dev/null +++ b/config/marketplace/kustomization.yaml @@ -0,0 +1,6 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- ../operator + diff --git a/config/operator/kustomization.yaml b/config/operator/kustomization.yaml new file mode 100644 index 000000000..adbe6c3d6 --- /dev/null +++ b/config/operator/kustomization.yaml @@ -0,0 +1,6 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- ../bundle + diff --git a/config/rbac/cluster/kustomization.yaml b/config/rbac/cluster/kustomization.yaml new file mode 100644 index 000000000..82cfb0841 --- /dev/null +++ b/config/rbac/cluster/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- service_account.yaml +- role.yaml +- role_binding.yaml diff --git a/config/rbac/cluster/role.yaml b/config/rbac/cluster/role.yaml new file mode 100644 index 000000000..77ec086ed --- /dev/null +++ b/config/rbac/cluster/role.yaml @@ -0,0 +1,130 @@ +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: percona-xtradb-cluster-operator +rules: + - apiGroups: + - pxc.percona.com + resources: + - perconaxtradbclusters + - perconaxtradbclusters/status + - perconaxtradbclusterbackups + - perconaxtradbclusterbackups/status + - perconaxtradbclusterrestores + - perconaxtradbclusterrestores/status + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - admissionregistration.k8s.io + resources: + - validatingwebhookconfigurations + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - "" + resources: + - pods + - pods/exec + - pods/log + - configmaps + - services + - persistentvolumeclaims + - secrets + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - apps + resources: + - deployments + - replicasets + - statefulsets + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - batch + resources: + - jobs + - cronjobs + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - policy + resources: + - poddisruptionbudgets + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - events.k8s.io + - "" + resources: + - events + verbs: + - create + - patch + - get + - list + - watch + - apiGroups: + - certmanager.k8s.io + - cert-manager.io + resources: + - issuers + - certificates + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - deletecollection \ No newline at end of file diff --git a/config/rbac/cluster/role_binding.yaml b/config/rbac/cluster/role_binding.yaml new file mode 100644 index 000000000..6d7f74e86 --- /dev/null +++ b/config/rbac/cluster/role_binding.yaml @@ -0,0 +1,13 @@ +--- +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: service-account-percona-xtradb-cluster-operator +subjects: + - kind: ServiceAccount + name: percona-xtradb-cluster-operator + namespace: "pxc-operator" +roleRef: + kind: ClusterRole + name: percona-xtradb-cluster-operator + apiGroup: rbac.authorization.k8s.io diff --git a/config/rbac/cluster/service_account.yaml b/config/rbac/cluster/service_account.yaml new file mode 100644 index 000000000..c5ad4a153 --- /dev/null +++ b/config/rbac/cluster/service_account.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: percona-xtradb-cluster-operator diff --git a/config/rbac/namespace/kustomization.yaml b/config/rbac/namespace/kustomization.yaml new file mode 100644 index 000000000..82cfb0841 --- /dev/null +++ b/config/rbac/namespace/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- service_account.yaml +- role.yaml +- role_binding.yaml diff --git a/config/rbac/namespace/role.yaml b/config/rbac/namespace/role.yaml new file mode 100644 index 000000000..3cb156b4c --- /dev/null +++ b/config/rbac/namespace/role.yaml @@ -0,0 +1,118 @@ +--- +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: percona-xtradb-cluster-operator +rules: + - apiGroups: + - pxc.percona.com + resources: + - perconaxtradbclusters + - perconaxtradbclusters/status + - perconaxtradbclusterbackups + - perconaxtradbclusterbackups/status + - perconaxtradbclusterrestores + - perconaxtradbclusterrestores/status + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - "" + resources: + - pods + - pods/exec + - pods/log + - configmaps + - services + - persistentvolumeclaims + - secrets + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - apps + resources: + - deployments + - replicasets + - statefulsets + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - batch + resources: + - jobs + - cronjobs + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - policy + resources: + - poddisruptionbudgets + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - apiGroups: + - events.k8s.io + - "" + resources: + - events + verbs: + - create + - patch + - get + - list + - watch + - apiGroups: + - certmanager.k8s.io + - cert-manager.io + resources: + - issuers + - certificates + verbs: + - get + - list + - watch + - create + - update + - patch + - delete + - deletecollection \ No newline at end of file diff --git a/config/rbac/namespace/role_binding.yaml b/config/rbac/namespace/role_binding.yaml new file mode 100644 index 000000000..25a5860da --- /dev/null +++ b/config/rbac/namespace/role_binding.yaml @@ -0,0 +1,12 @@ +--- +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: service-account-percona-xtradb-cluster-operator +subjects: + - kind: ServiceAccount + name: percona-xtradb-cluster-operator +roleRef: + kind: Role + name: percona-xtradb-cluster-operator + apiGroup: rbac.authorization.k8s.io diff --git a/config/rbac/namespace/service_account.yaml b/config/rbac/namespace/service_account.yaml new file mode 100644 index 000000000..c5ad4a153 --- /dev/null +++ b/config/rbac/namespace/service_account.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: percona-xtradb-cluster-operator diff --git a/config/redhat/kustomization.yaml b/config/redhat/kustomization.yaml new file mode 100644 index 000000000..42bd0a3da --- /dev/null +++ b/config/redhat/kustomization.yaml @@ -0,0 +1,6 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: +- ../operator + diff --git a/installers/olm/Makefile b/installers/olm/Makefile new file mode 100644 index 000000000..447cbfe4f --- /dev/null +++ b/installers/olm/Makefile @@ -0,0 +1,133 @@ +NAME ?= percona-xtradb-cluster-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) + +distros = community redhat marketplace + +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) + +check-version: +ifndef VERSION + $(error VERSION is not set) +endif + +KUSTOMIZE = $(REPO_ROOT)/bin/kustomize +kustomize: ## Download kustomize locally if necessary. + $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.3) + +.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 pxc-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' + +.PHONY: bundles/redhat +bundles/redhat: + cd ../../config/manager/$(MODE)/ && $(KUSTOMIZE) edit set image pxc-operator=$(IMAGE) + ./generate.sh redhat + env operator-sdk bundle validate $@ --select-optional='suite=operatorframework' + +# 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 pxc-operator=$(IMAGE) + ./generate.sh marketplace + env operator-sdk bundle validate $@ --select-optional='suite=operatorframework' + +.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' + 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)' + 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' + 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 + diff --git a/installers/olm/README.md b/installers/olm/README.md new file mode 100644 index 000000000..a202e7250 --- /dev/null +++ b/installers/olm/README.md @@ -0,0 +1,3 @@ +1. Set VERSION env variable +2. Choose the mode (cluster or namespace) and update bundle/kustomization.yaml and makefile with necessary mode. +3. ```make bundles``` \ No newline at end of file diff --git a/installers/olm/bundle.Dockerfile b/installers/olm/bundle.Dockerfile new file mode 100644 index 000000000..ca6ac1a88 --- /dev/null +++ b/installers/olm/bundle.Dockerfile @@ -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/ / diff --git a/installers/olm/bundle.annotations.yaml b/installers/olm/bundle.annotations.yaml new file mode 100644 index 000000000..3f13e46c1 --- /dev/null +++ b/installers/olm/bundle.annotations.yaml @@ -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-xtradb-cluster-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: info@percona.com + org.opencontainers.image.url: https://percona.com + org.opencontainers.image.vendor: Percona diff --git a/installers/olm/bundle.csv.yaml b/installers/olm/bundle.csv.yaml new file mode 100644 index 000000000..c9c27d4d1 --- /dev/null +++ b/installers/olm/bundle.csv.yaml @@ -0,0 +1,278 @@ +# https://olm.operatorframework.io/docs/concepts/crds/clusterserviceversion/ +# https://docs.openshift.com/container-platform/4.7/operators/operator_sdk/osdk-generating-csvs.html +# https://redhat-connect.gitbook.io/certified-operator-guide/ocp-deployment/operator-metadata/creating-the-csv +# https://pkg.go.dev/github.com/operator-framework/api@v0.10.1/pkg/operators/v1alpha1#ClusterServiceVersion + +apiVersion: operators.coreos.com/v1alpha1 +kind: ClusterServiceVersion +metadata: + name: '' + annotations: + features.operators.openshift.io/disconnected: "false" + features.operators.openshift.io/fips-compliant: "false" + features.operators.openshift.io/proxy-aware: "false" + features.operators.openshift.io/tls-profiles: "false" + features.operators.openshift.io/token-auth-aws: "false" + features.operators.openshift.io/token-auth-azure: "false" + features.operators.openshift.io/token-auth-gcp: "false" + features.operators.openshift.io/cnf: "false" + features.operators.openshift.io/cni: "false" + features.operators.openshift.io/csi: "false" + support: percona/percona.com + # The following affect how the package is indexed at OperatorHub.io: + # https://operatorhub.io/?category=Database + # https://sdk.operatorframework.io/docs/advanced-topics/operator-capabilities/operator-capabilities/ + categories: Database + capabilities: Deep Insights + description: >- + Percona Operator for MySQL based on Percona XtraDB Cluster manages the lifecycle of Percona XtraDB + cluster instances. + + # The following appear on the details page at OperatorHub.io: + # https://operatorhub.io/operator/postgresql + createdAt: "%Y-%m-%dT%H:%M:%S.%3Z" + repository: 'https://github.com/percona/percona-xtradb-cluster-operator' + alm-examples: >- + +spec: + # The following affect how the package is indexed at OperatorHub.io: + # https://operatorhub.io/ + displayName: Percona Operator for MySQL based on Percona XtraDB Cluster + provider: + # These values become labels on the PackageManifest. + name: Percona + url: https://www.percona.com/ + keywords: + - mysql + - percona + - database + - pxc + - galera + - database + - sql + - operator + + # The following appear on the details page at OperatorHub.io: + # https://operatorhub.io/operator/percona-xtradb-cluster-operator + description: |- + + ## Percona is Cloud Native + + Percona Operator for MySQL based on Percona XtraDB Cluster is an open-source drop in replacement for + MySQL Enterprise with synchronous replication running on Kubernetes. It + automates the deployment and management of the members in your Percona + XtraDB Cluster environment. It can be used to instantiate a new Percona + XtraDB Cluster, or to scale an existing environment. + + + Consult the + [documentation](https://percona.github.io/percona-xtradb-cluster-operator/) + on the Percona Operator for MySQL based on Percona XtraDB Cluster for complete + details on capabilities and options. + + + ### Supported Features + + + * **Scale Your Cluster** change the `size` parameter to [add or remove + members](https://percona.github.io/percona-xtradb-cluster-operator/install/scaling) + of the cluster. Three is the minimum recommended size for a functioning + cluster. + + + * **Manage Your Users** [add, remove, or + change](https://percona.github.io/percona-xtradb-cluster-operator/configure/users) + the privileges of database users + + + * **Automate Your Backups** [configure cluster + backups](https://percona.github.io/percona-xtradb-cluster-operator/configure/operator) + to run on a scheduled basis. Backups can be stored on a persistent volume or S3-compatible + storage. Leverage [Point-in-time recovery](https://www.percona.com/doc/kubernetes-operator-for-pxc/backups.html#storing-binary-logs-for-point-in-time-recovery) + to reduce RPO/RTO. + + * **Proxy integration** choose HAProxy or ProxySQL as a proxy in front of + the Percona XtraDB Cluster. Proxies are deployed and configured automatically + with the Operator. + + + ### Common Configurations + + + * **Set Resource Limits** - set limitation on requests to CPU and memory + resources. + + + * **Customize Storage** - set the desired Storage Class and Access Mode for + your database cluster data. + + + * **Control Scheduling** - define how your PXC Pods are scheduled onto the + K8S cluster with tolerations, pod disruption budgets, node selector and + affinity settings. + + * Automatic synchronization of MySQL users with ProxySQL + + * HAProxy Support + + * Fully automated minor version updates (Smart Update) + + * Update Reader members before Writer member at cluster upgrades + + * Support MySQL versions 5.7 and 8.0 + + ### Before You Start + + + Add the PXC user `Secret` to Kubernetes. User information must be placed in + the data section of the `secrets.yaml` + + file with Base64-encoded logins and passwords for the user accounts. + + + Below is a sample `secrets.yaml` file for the correct formatting. + + + ``` + + apiVersion: v1 + + kind: Secret + + metadata: + name: my-cluster-secrets + type: Opaque + + data: + root: cm9vdF9wYXNzd29yZA== + xtrabackup: YmFja3VwX3Bhc3N3b3Jk + monitor: bW9uaXRvcg== + clustercheck: Y2x1c3RlcmNoZWNrcGFzc3dvcmQ= + proxyadmin: YWRtaW5fcGFzc3dvcmQ= + pmmserver: c3VwYXxefHBheno= + operator: b3BlcmF0b3JhZG1pbg== + replication: cmVwbF9wYXNzd29yZAo= + ``` + + ### Release Highlights + + * General availability of the automated volume resizing + + * Allowing haproxy-replica Service to cycle through the reader instances only + + * Fixing the overloaded allowUnsafeConfigurations flag + version: + links: + - name: Percona + url: https://www.percona.com/ + - name: Documentation + url: https://docs.percona.com/percona-operator-for-mysql/pxc/index.html + maintainers: + - name: Percona + email: info@percona.com + icon: + - base64data: >- + PHN2ZyB3aWR0aD0iMjI3IiBoZWlnaHQ9IjE5NCIgdmlld0JveD0iMCAwIDIyNyAxOTQiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGQ9Ik01OS4yODk5IDE5My40M0w0My41NDk5IDE2NS4xMkw1Ny42NDk5IDEzOS43MUw0NS4wNjk5IDExNi45NUgxNi4zMjk5TDAuNjI5ODgzIDg5LjAxTDE2LjA1OTkgNjAuNzlINDkuMDA5OUw2Mi44Mjk5IDg1LjgzSDg4LjAxOTlMMTAyLjQxIDYwLjU2SDEzNC45NkwxNTAuMzUgODguNTJMMTM2LjI3IDExNC4wM0wxND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N0b3AtY29sb3I9IiMwRTVGQjUiLz4KPC9saW5lYXJHcmFkaWVudD4KPC9kZWZzPgo8L3N2Zz4= + mediatype: image/svg+xml + + customresourcedefinitions: + owned: + - description: Instance of a Percona XtraDB Cluster + displayName: PerconaXtraDBCluster + kind: PerconaXtraDBCluster + name: perconaxtradbclusters.pxc.percona.com + version: v1 + specDescriptors: [ ] + statusDescriptors: [ ] + resources: + - version: v1 + kind: Deployment + name: '' + - version: v1 + kind: Service + name: '' + - version: v1 + kind: ReplicaSet + name: '' + - version: v1 + kind: Pod + name: '' + - version: v1 + kind: Secret + name: '' + - version: v1 + kind: ConfigMap + name: '' + - description: Instance of a Percona XtraDB Cluster Backup + displayName: PerconaXtraDBClusterBackup + kind: PerconaXtraDBClusterBackup + name: perconaxtradbclusterbackups.pxc.percona.com + version: v1 + specDescriptors: [ ] + statusDescriptors: [ ] + resources: + - version: v1 + kind: Deployment + name: '' + - version: v1 + kind: Service + name: '' + - version: v1 + kind: ReplicaSet + name: '' + - version: v1 + kind: Pod + name: '' + - version: v1 + kind: Secret + name: '' + - version: v1 + kind: ConfigMap + name: '' + - description: Instance of a Percona XtraDB Cluster Restore + displayName: PerconaXtraDBClusterRestore + kind: PerconaXtraDBClusterRestore + name: perconaxtradbclusterrestores.pxc.percona.com + version: v1 + specDescriptors: [ ] + statusDescriptors: [ ] + resources: + - version: v1 + kind: Deployment + name: '' + - version: v1 + kind: Service + name: '' + - version: v1 + kind: ReplicaSet + name: '' + - version: v1 + kind: Pod + name: '' + - version: v1 + kind: Secret + name: '' + - version: v1 + kind: ConfigMap + name: '' + required: [ ] + # https://olm.operatorframework.io/docs/best-practices/common/ + # Note: The minKubeVersion must correspond to the lowest supported OCP version + minKubeVersion: 1.27.0 + maturity: stable + # https://olm.operatorframework.io/docs/advanced-tasks/operator-scoping-with-operatorgroups/ + installModes: + - supported: true + type: OwnNamespace + - supported: true + type: SingleNamespace + - supported: true + type: MultiNamespace + - supported: true + type: AllNamespaces + + install: + strategy: deployment + spec: + permissions: + deployments: \ No newline at end of file diff --git a/installers/olm/bundle.relatedImages.yaml b/installers/olm/bundle.relatedImages.yaml new file mode 100644 index 000000000..c463e3191 --- /dev/null +++ b/installers/olm/bundle.relatedImages.yaml @@ -0,0 +1,21 @@ +- name: pxc5.7 + image: registry.connect.redhat.com/percona/percona-xtradb-cluster-operator-containers@sha256: +- name: pxc5.7-backup + image: registry.connect.redhat.com/percona/percona-xtradb-cluster-operator-containers@sha256: +- name: pxc8.0 + image: registry.connect.redhat.com/percona/percona-xtradb-cluster-operator-containers@sha256: +- name: pxc8.0-backup + image: registry.connect.redhat.com/percona/percona-xtradb-cluster-operator-containers@sha256: +- name: operator + image: registry.connect.redhat.com/percona/percona-xtradb-cluster-operator@sha256: +- name: haproxy + image: registry.connect.redhat.com/percona/percona-xtradb-cluster-operator-containers@sha256: +- name: proxysql + image: registry.connect.redhat.com/percona/percona-xtradb-cluster-operator-containers@sha256: +- name: logcollector + image: registry.connect.redhat.com/percona/percona-xtradb-cluster-operator-containers@sha256: +- name: pmmclient + image: registry.connect.redhat.com/percona/percona-xtradb-cluster-operator-containers@sha256: + + + diff --git a/installers/olm/generate.sh b/installers/olm/generate.sh new file mode 100755 index 000000000..4ac3a84ee --- /dev/null +++ b/installers/olm/generate.sh @@ -0,0 +1,247 @@ +#!/usr/bin/env bash +set -eu + +DISTRIBUTION="$1" + +cd "${BASH_SOURCE[0]%/*}" + +bundle_directory="bundles/${DISTRIBUTION}" +project_directory="projects/${DISTRIBUTION}" +go_api_directory=$(cd ../../pkg/apis && pwd) + +# The 'operators.operatorframework.io.bundle.package.v1' package name for each +# bundle (updated for the 'certified' and 'marketplace' bundles). +package_name='percona-xtradb-cluster-operator' + +# The project name used by operator-sdk for initial bundle generation. +project_name='percona-xtradb-cluster-operator' + +# The prefix for the 'clusterserviceversion.yaml' file. +# Per OLM guidance, the filename for the clusterserviceversion.yaml must be prefixed +# with the Operator's package name for the 'redhat' and 'marketplace' bundles. +# https://github.com/redhat-openshift-ecosystem/certification-releases/blob/main/4.9/ga/troubleshooting.md#get-supported-versions +file_name='percona-xtradb-cluster-operator' + +if [ ${MODE} == "cluster" ]; then + suffix="-cw" + mode="Cluster" + rulesLevel="ClusterPermissions" + +elif [ ${MODE} == "namespace" ]; then + suffix="" + mode="" + rulesLevel="permissions" +else + echo "Please add MODE variable. It could be either namespace or cluster" + exit 1 +fi + +update_yaml_images() { + local yaml_file="$1" + + if [ ! -f "$yaml_file" ]; then + echo "Error: File '$yaml_file' does not exist." + return 1 + fi + + local temp_file=$(mktemp) + + sed -E 's/(("image":|containerImage:|image:)[ ]*"?)([^"]+)("?)/\1docker.io\/\3\4/g' "$yaml_file" > "$temp_file" + mv "$temp_file" "$yaml_file" + + echo "File '$yaml_file' updated successfully." +} + +kubectl kustomize "../../config/${DISTRIBUTION}" >operator_yamls.yaml + +export role="${mode}Role" + +yq eval '. | select(.kind == "CustomResourceDefinition")' operator_yamls.yaml >operator_crds.yaml +yq eval '. | select(.kind == "Deployment")' operator_yamls.yaml >operator_deployments.yaml +yq eval '. | select(.kind == "ServiceAccount")' operator_yamls.yaml >operator_accounts.yaml +yq eval '. | select(.kind == env(role))' operator_yamls.yaml >operator_roles${suffix}.yaml + +## Recreate the Operator SDK project. + +[ ! -d "${project_directory}" ] || rm -r "${project_directory}" +install -d "${project_directory}" +( + cd "${project_directory}" + operator-sdk init --fetch-deps='false' --project-name=${project_name} + + # Generate CRD descriptions from Go markers. + # https://sdk.operatorframework.io/docs/building-operators/golang/references/markers/ + yq eval '[. | {"group": .spec.group, "kind": .spec.names.kind, "version": .spec.versions[].name}]' ../../operator_crds.yaml >crd_gvks.yaml + + yq eval --inplace '.multigroup = true | .resources = load("crd_gvks.yaml" | fromyaml) | .' ./PROJECT + + ln -s "${go_api_directory}" . + operator-sdk generate kustomize manifests --interactive='false' --verbose +) + +# Recreate the OLM bundle. +[ ! -d "${bundle_directory}" ] || rm -r "${bundle_directory}" +install -d \ + "${bundle_directory}/manifests" \ + "${bundle_directory}/metadata" + +# Render bundle annotations and strip comments. +# Per Red Hat we should not include the org.opencontainers annotations in the +# 'redhat' & 'marketplace' annotations.yaml file, so only add them for 'community'. +# - https://coreos.slack.com/team/UP1LZCC1Y + +export package="${package_name}" +export package_channel="${PACKAGE_CHANNEL}${suffix}" +export openshift_supported_versions="${OPENSHIFT_VERSIONS}" + +yq eval '.annotations["operators.operatorframework.io.bundle.channels.v1"] = env(package_channel) | + .annotations["operators.operatorframework.io.bundle.channel.default.v1"] = env(package_channel) | + .annotations["com.redhat.openshift.versions"] = env(openshift_supported_versions)' \ + bundle.annotations.yaml >"${bundle_directory}/metadata/annotations.yaml" + +if [ ${DISTRIBUTION} == 'community' ]; then + # community-operators + yq eval --inplace ' + .annotations["operators.operatorframework.io.bundle.package.v1"] = "percona-xtradb-cluster-operator" | + .annotations["org.opencontainers.image.authors"] = "info@percona.com" | + .annotations["org.opencontainers.image.url"] = "https://percona.com" | + .annotations["org.opencontainers.image.vendor"] = "Percona"' \ + "${bundle_directory}/metadata/annotations.yaml" + +# certified-operators +elif [ ${DISTRIBUTION} == 'redhat' ]; then + yq eval --inplace ' + .annotations["operators.operatorframework.io.bundle.package.v1"] = "percona-xtradb-cluster-operator-certified" ' \ + "${bundle_directory}/metadata/annotations.yaml" + +# redhat-marketplace +elif [ ${DISTRIBUTION} == 'marketplace' ]; then + yq eval --inplace ' + .annotations["operators.operatorframework.io.bundle.package.v1"] = "percona-xtradb-cluster-operator-certified-rhmp" ' \ + "${bundle_directory}/metadata/annotations.yaml" +fi + +# Copy annotations into Dockerfile LABELs. +# TODO fix tab for labels. + +labels=$(yq eval -r '.annotations | to_entries | map(" " + .key + "=" + (.value | tojson)) | join("\n")' \ + "${bundle_directory}/metadata/annotations.yaml") + +labels="${labels} + + com.redhat.delivery.backport=true + + com.redhat.delivery.operator.bundle=true" + +ANNOTATIONS="${labels}" envsubst "${bundle_directory}/Dockerfile" + +awk '{gsub(/^[ \t]+/, " "); print}' "${bundle_directory}/Dockerfile" > "${bundle_directory}/Dockerfile.new" && mv "${bundle_directory}/Dockerfile.new" "${bundle_directory}/Dockerfile" + +# Include CRDs as manifests. +crd_names=$(yq eval -o=tsv '.metadata.name' operator_crds.yaml) + +gawk -v names="${crd_names}" -v bundle_directory="${bundle_directory}" ' +BEGIN { + split(names, name_array, " "); + idx=1; +} +/apiVersion: apiextensions.k8s.io\/v1/ { + if (idx in name_array) { + current_file = bundle_directory "/manifests/" name_array[idx] ".crd.yaml"; + idx++; + } else { + current_file = bundle_directory "/unnamed_" idx ".yaml"; + idx++; + } +} +{ + if (current_file != "") { + print > current_file; + } +} +' ../../deploy/crd.yaml + +abort() { + echo >&2 "$@" + exit 1 +} +dump() { yq --color-output; } + +# The first command render yaml correctly and the second extract data. + +yq eval -i '[.]' operator_deployments.yaml && yq eval 'length == 1' operator_deployments.yaml --exit-status >/dev/null || abort "too many deployments accounts!" $'\n'"$(yq eval . operator_deployments.yaml)" + +yq eval -i '[.]' operator_accounts.yaml && yq eval 'length == 1' operator_accounts.yaml --exit-status >/dev/null || abort "too many service accounts!" $'\n'"$(yq eval . operator_accounts.yaml)" + +yq eval -i '[.]' operator_roles${suffix}.yaml && yq eval 'length == 1' operator_roles${suffix}.yaml --exit-status >/dev/null || abort "too many roles!" $'\n'"$(yq eval . operator_roles${suffix}.yaml)" + +# Render bundle CSV and strip comments. +csv_stem=$(yq -r '.projectName' "${project_directory}/PROJECT") + +cr_example=$(yq eval -o=json ../../deploy/cr.yaml) +backup_example=$(yq eval -o=json ../../deploy/backup/backup.yaml) +restore_example=$(yq eval -o=json ../../deploy/backup/restore.yaml) +full_example=$(jq -n "[${cr_example}, ${backup_example}, ${restore_example}]") + +export examples="${full_example}" +export deployment=$(yq eval operator_deployments.yaml) +export account=$(yq eval '.[] | .metadata.name' operator_accounts.yaml) +export rules=$(yq eval '.[] | .rules' operator_roles${suffix}.yaml) +export version="${VERSION}${suffix}" +export minKubeVer="${MIN_KUBE_VERSION}" +export stem="${csv_stem}" +export timestamp=$(date -u +"%Y-%m-%dT%H:%M:%S.%3Z") +export name="${csv_stem}.v${VERSION}${suffix}" +export name_certified="${csv_stem}-certified.v${VERSION}${suffix}" +export name_certified_rhmp="${csv_stem}-certified-rhmp.v${VERSION}${suffix}" +export skip_range="<${VERSION}" +export containerImage="$(yq eval '.[0].spec.template.spec.containers[0].image' operator_deployments.yaml)" +export relatedImages=$(yq eval bundle.relatedImages.yaml) +export rulesLevel=${rulesLevel} +yq eval ' + .metadata.annotations["alm-examples"] = strenv(examples) | + .metadata.annotations["containerImage"] = env(containerImage) | + .metadata.annotations["olm.skipRange"] = env(skip_range) | + .metadata.annotations["createdAt"] = env(timestamp) | + .metadata.name = env(name) | + .spec.version = env(version) | + .spec.install.spec[strenv(rulesLevel)] = [{ "serviceAccountName": env(account), "rules": env(rules) }] | + .spec.install.spec.deployments = [( env(deployment) | .[] |{ "name": .metadata.name, "spec": .spec} )] | + .spec.minKubeVersion = env(minKubeVer)' bundle.csv.yaml >"${bundle_directory}/manifests/${file_name}.clusterserviceversion.yaml" + +if [ ${DISTRIBUTION} == "community" ]; then + update_yaml_images "bundles/$DISTRIBUTION/manifests/${file_name}.clusterserviceversion.yaml" + +elif [ ${DISTRIBUTION} == "redhat" ]; then + + yq eval --inplace ' + .spec.relatedImages = env(relatedImages) | + .metadata.annotations.certified = "true" | + .metadata.annotations["containerImage"] = "registry.connect.redhat.com/percona/percona-xtradb-cluster-operator@sha256:" | + .metadata.name = strenv(name_certified)' \ + "${bundle_directory}/manifests/${file_name}.clusterserviceversion.yaml" + +elif [ ${DISTRIBUTION} == "marketplace" ]; then + # Annotations needed when targeting Red Hat Marketplace + export package_url="https://marketplace.redhat.com/en-us/operators/${file_name}" + yq --inplace ' + .metadata.name = env(name_certified_rhmp) | + .metadata.annotations["containerImage"] = "registry.connect.redhat.com/percona/percona-xtradb-cluster-operator@sha256:" | + .metadata.annotations["marketplace.openshift.io/remote-workflow"] = + "https://marketplace.redhat.com/en-us/operators/percona-xtradb-cluster-operator-certified-rhmp/pricing?utm_source=openshift_console" | + .metadata.annotations["marketplace.openshift.io/support-workflow"] = + "https://marketplace.redhat.com/en-us/operators/percona-xtradb-cluster-operator-certified-rhmp/support?utm_source=openshift_console" | + .spec.relatedImages = env(relatedImages)' \ + "${bundle_directory}/manifests/${file_name}.clusterserviceversion.yaml" +fi + +sed -i '' '/crVersion/!b +/crVersion/n +/crVersion/a\ + initImage: $initImage +' "bundles/$DISTRIBUTION/manifests/${file_name}.clusterserviceversion.yaml" + +# delete blank lines. +sed -i '' '/^$/d' "${bundle_directory}/manifests/${file_name}.clusterserviceversion.yaml" + +if >/dev/null command -v tree; then tree -C "${bundle_directory}"; fi \ No newline at end of file