Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,8 @@ kind-logs-*/

# Other
gke_gcloud_auth_plugin_cache

projects/
installers/olm/operator_*.yaml
installers/olm/bundles
installers/olm/bundles/tools
177 changes: 177 additions & 0 deletions installers/olm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# ==============================================================================
# Percona Server for MySQL Operator - OLM Bundle Generation
# ==============================================================================

# Default target
.DEFAULT_GOAL := help
.SUFFIXES:
SHELL := /bin/bash

# ==============================================================================
# Configuration Variables
# ==============================================================================

# Project configuration
NAME ?= percona-server-mysql-operator
IMAGE_TAG_OWNER ?= perconalab
IMAGE_TAG_BASE ?= $(IMAGE_TAG_OWNER)/$(NAME)
MODE ?= cluster

# Version detection
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)

# Bundle configuration
OPENSHIFT_VERSIONS ?= v4.16-v4.19
PACKAGE_CHANNEL ?= stable
MIN_KUBE_VERSION ?= ""
DOCKER_DEFAULT_PLATFORM ?= linux/amd64

# Paths
REPO_ROOT := $(shell git rev-parse --show-toplevel)
KUSTOMIZE := $(REPO_ROOT)/bin/kustomize

# Tool versions
OPERATOR_SDK_VERSION := v1.41.1

# Bundle image configuration
BUNDLE_IMG ?= $(IMAGE_TAG_BASE):community-bundle-$(VERSION)

# System detection for tool downloads
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
OS_KERNEL := $(shell echo "$(UNAME_S)" | tr '[:upper:]' '[:lower:]')
OS_MACHINE := $(UNAME_M)

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

# Export variables for generate.sh
export VERSION OPENSHIFT_VERSIONS PACKAGE_CHANNEL MIN_KUBE_VERSION DOCKER_DEFAULT_PLATFORM MODE

# ==============================================================================
# Bundle Targets
# ==============================================================================

DISTROS := community redhat marketplace

.PHONY: bundles
bundles: ## Build all OLM bundles (community, redhat, marketplace)
bundles: check-prereqs $(DISTROS:%=bundles/%)

.PHONY: $(DISTROS:%=bundles/%)
$(DISTROS:%=bundles/%): bundles/%: tools/operator-sdk
@echo "$(GREEN)Building $* bundle...$(RESET)"
./generate.sh $*
./tools/operator-sdk bundle validate $@ --select-optional='suite=operatorframework'
$(if $(filter community,$*),./tools/operator-sdk bundle validate $@ --select-optional='name=community' --optional-values='index-path=$@/Dockerfile')
@echo "$(GREEN)✓ Bundle stored in installers/olm/bundles/$*$(RESET)"

# ==============================================================================
# Docker Build & Push Targets
# ==============================================================================

.PHONY: build
build: ## Build community bundle Docker image
build:
@echo "$(GREEN)Building bundle Docker image...$(RESET)"
docker build -f bundles/community/Dockerfile -t $(BUNDLE_IMG) --platform=linux/amd64 bundles/community
@echo "$(GREEN)✓ Bundle image built: $(BUNDLE_IMG)$(RESET)"

.PHONY: push
push: ## Push bundle Docker image to registry
@echo "$(GREEN)Pushing bundle image to registry...$(RESET)"
docker push $(BUNDLE_IMG)
@echo "$(GREEN)✓ Bundle image pushed: $(BUNDLE_IMG)$(RESET)"

# ==============================================================================
# Utility Targets
# ==============================================================================

.PHONY: check-prereqs
check-prereqs: check-version check-git check-tools

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

.PHONY: check-git
check-git:
@if ! git rev-parse --git-dir > /dev/null 2>&1; then \
echo "Error: Not in a git repository"; \
exit 1; \
fi

.PHONY: check-tools
check-tools:
@for cmd in gawk gcsplit yq; do \
if ! command -v $$cmd >/dev/null 2>&1; then \
echo "Error: $$cmd is required but not installed"; \
exit 1; \
fi; \
done

.PHONY: install-olm
install-olm: ## Install OLM in Kubernetes cluster
install-olm: tools/operator-sdk
./tools/operator-sdk olm install

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

.PHONY: help
help: ## Show this help message
@awk 'BEGIN {FS = ": ## "; printf "\n$(GREEN)Usage:$(RESET)\n make [target]\n\n$(GREEN)Targets:$(RESET)\n"} /^[a-zA-Z_-]+: ## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)

# ==============================================================================
# Tool Management
# ==============================================================================

.PHONY: tools
tools: ## Download required tools
tools: tools/operator-sdk

# Download operator-sdk
tools/operator-sdk:
@echo "Downloading operator-sdk $(OPERATOR_SDK_VERSION)..."
@install -d tools
@curl -fSL --fail -o '$@' \
'https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(OS_KERNEL)_$(OS_MACHINE)' \
|| { rm -f '$@'; echo "Failed to download operator-sdk"; exit 1; }
@chmod +x '$@'
@echo "✓ operator-sdk installed"

# ==============================================================================
# Development Targets
# ==============================================================================

.PHONY: validate
validate: ## Validate existing bundles without rebuilding
@for distro in $(DISTROS); do \
if [ -d "bundles/$$distro" ]; then \
echo "Validating $$distro bundle..."; \
./tools/operator-sdk bundle validate "bundles/$$distro" --select-optional='suite=operatorframework' || exit 1; \
fi; \
done
@echo "$(GREEN)✓ All bundles validated$(RESET)"

.PHONY: list-versions
list-versions: ## Show current version information
@echo "Current configuration:"
@echo " VERSION: $(VERSION)"
@echo " IMAGE: $(IMAGE)"
@echo " MODE: $(MODE)"
@echo " OPENSHIFT_VERSIONS: $(OPENSHIFT_VERSIONS)"
@echo " MIN_KUBE_VERSION: $(MIN_KUBE_VERSION)"

# ==============================================================================
# Kustomize
# ==============================================================================

$(KUSTOMIZE):
$(MAKE) -C $(REPO_ROOT) kustomize
22 changes: 22 additions & 0 deletions installers/olm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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.0.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.16-v4.20"
# Set namespace or cluster (to generate bundles for cluster-wide)
export 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. Update spec.description in bundle.csv.yaml with features added in this release.
4. Run bundle generation:
```bash
# Generate all bundles community redhat and marketplace:
make bundles
# Generate only specific bundle:
make bundles/community
```
15 changes: 15 additions & 0 deletions installers/olm/bundle.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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

# LABELS is replaced with bundle.annotations.yaml
${LABELS}

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-mysql-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
Loading
Loading