Skip to content

Commit

Permalink
Merge pull request #19 from controlplaneio-fluxcd/operatorhub
Browse files Browse the repository at this point in the history
Add OperatorHub manifests
  • Loading branch information
stefanprodan authored Jun 10, 2024
2 parents 25ba3ca + 5a8a2ed commit dba1c3a
Show file tree
Hide file tree
Showing 23 changed files with 1,190 additions and 21 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/e2e-olm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: e2e-olm

on:
workflow_dispatch:
inputs:
version:
description: 'Flux operator strict semver e.g. v0.3.0'
required: true

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Setup Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version-file: 'go.mod'
cache-dependency-path: |
**/go.sum
**/go.mod
- name: Setup Kubernetes
uses: helm/kind-action@0025e74a8c7512023d06dc019c617aa3cf561fde # v1.10.0
with:
version: v0.23.0
cluster_name: kind
- name: Setup QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Run OLM tests
run: |
make test-olm FLUX_OPERATOR_VERSION="${{ github.event.inputs.version }}"
37 changes: 36 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/controlplaneio-fluxcd/flux-operator:latest

# FLUX_OPERATOR_VERSION refers to the version of the operator to be tested
# under ./config/operatorhub/flux-operator/<version> directory.
FLUX_OPERATOR_VERSION ?= v0.1.0
# OLM_VERSION refers to the version of the Operator Lifecycle Manager to be used.
OLM_VERSION ?= 0.28.0

# FLUX_VERSION refers to the version of Flux to be vendored.
FLUX_VERSION = $(shell gh release view --repo fluxcd/flux2 --json tagName -q '.tagName')

Expand Down Expand Up @@ -56,7 +62,7 @@ tidy: ## Run go mod tidy.

.PHONY: test
test: tidy 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
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v -e /e2e -e /olm) -coverprofile cover.out

# 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.
Expand Down Expand Up @@ -145,6 +151,28 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: opm-index
opm-index:
./config/operatorhub/flux-operator/scripts/opm-index.sh ${FLUX_OPERATOR_VERSION}

.PHONY: test-olm
test-olm: operator-sdk opm-index
yq e -i ".spec.startingCSV=\"flux-operator.${FLUX_OPERATOR_VERSION}\"" \
./config/operatorhub/flux-operator/testdata/004-operator-subscription.yaml
yq e -i ".spec.image=\"ghcr.io/controlplaneio-fluxcd/openshift-flux-operator-index:${FLUX_OPERATOR_VERSION}\"" \
./config/operatorhub/flux-operator/testdata/003-catalog-source.yaml
export OLM_VERSION=${OLM_VERSION} && \
export FLUX_OPERATOR_VERSION=${FLUX_OPERATOR_VERSION} && \
go test ./test/olm/ -v -ginkgo.v

.PHONY: deploy-olm-data
deploy-olm-data:
kubectl apply -k ./config/operatorhub/flux-operator/testdata/

.PHONY: undeploy-olm-data
undeploy-olm-data:
kubectl delete -k ./config/operatorhub/flux-operator/testdata/

##@ Dependencies

## Location to install dependencies to
Expand All @@ -158,12 +186,19 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk

## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.1
CONTROLLER_TOOLS_VERSION ?= v0.15.0
ENVTEST_VERSION ?= release-0.18
GOLANGCI_LINT_VERSION ?= v1.57.2
OPERATOR_SDK_VERSION ?= v1.34.2

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

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand Down
22 changes: 22 additions & 0 deletions config/operatorhub/flux-operator/Dockerfile.opm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM alpine:3.20

ARG DOCKER_VERSION=26.1.3
ARG OPM_VERSION=4.15.16
# x86_64 or aarch64
ARG ARCH=x86_64

WORKDIR /opt
RUN wget https://download.docker.com/linux/static/stable/${ARCH}/docker-${DOCKER_VERSION}.tgz
RUN tar xf docker-${DOCKER_VERSION}.tgz

RUN wget https://mirror.openshift.com/pub/openshift-v4/${ARCH}/clients/ocp/${OPM_VERSION}/opm-linux-${OPM_VERSION}.tar.gz
RUN tar xf opm-linux-${OPM_VERSION}.tar.gz

FROM ubuntu:24.04

WORKDIR /opt

COPY --from=0 /opt/docker/docker /usr/bin/
COPY --from=0 /opt/opm /opt/

ENTRYPOINT ["/opt/opm"]
21 changes: 21 additions & 0 deletions config/operatorhub/flux-operator/bundle.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM scratch

# Core bundle labels.
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=flux-operator
LABEL operators.operatorframework.io.bundle.channels.v1=stable
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.29.0
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=unknown

# Labels for testing.
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1
LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/

# Copy files to locations specified by labels.
COPY manifests /manifests/
COPY metadata /metadata/
COPY tests/scorecard /tests/scorecard/
7 changes: 7 additions & 0 deletions config/operatorhub/flux-operator/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
# Use `replaces-mode` or `semver-mode`. Once you switch to `semver-mode`, there is no easy way back.
updateGraph: semver-mode
addReviewers: true
reviewers:
- stefanprodan
- souleb
5 changes: 5 additions & 0 deletions config/operatorhub/flux-operator/flux-operator.package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
packageName: flux-operator
defaultChannel: stable
channels:
- name: stable
currentCSV: flux-operator.v0.3.0
42 changes: 42 additions & 0 deletions config/operatorhub/flux-operator/scripts/opm-index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail

#
# Prepare catalog for e2e testing
#

VERSION=$1
ARCH=""
DIR="config/operatorhub/flux-operator/"
case $(uname -m) in
x86_64) ARCH="x86_64" ;;
aarch64) ARCH="aarch64" ;;
arm64) ARCH="aarch64" ;;
*) echo "Unsupported architecture"
exit 1
;;
esac

if [ ! -d "${DIR}/${VERSION}" ]; then
echo "Version ${VERSION} does not exist"
exit 1
fi

# docker build and push individual bundles
docker build -t ghcr.io/controlplaneio-fluxcd/openshift-flux-operator-catalog:bundle-"${VERSION}" \
-f "${DIR}/bundle.Dockerfile" "${DIR}/${VERSION}"
docker push ghcr.io/controlplaneio-fluxcd/openshift-flux-operator-catalog:bundle-"${VERSION}"

docker build -t opm --build-arg ARCH=$ARCH -f "${DIR}/Dockerfile.opm" .

docker run --rm -it \
--privileged \
-v /var/lib/docker:/var/lib/docker \
-v /var/run/docker.sock:/var/run/docker.sock \
opm:latest index add \
--container-tool docker \
--bundles ghcr.io/controlplaneio-fluxcd/openshift-flux-operator-catalog:bundle-"${VERSION}" \
--tag ghcr.io/controlplaneio-fluxcd/openshift-flux-operator-index:${VERSION}

#push index
docker push ghcr.io/controlplaneio-fluxcd/openshift-flux-operator-index:${VERSION}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
name: flux-system
spec: {}
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: operators.coreos.com/v1alpha2
kind: OperatorGroup
metadata:
name: flux-system-group
namespace: flux-system

14 changes: 14 additions & 0 deletions config/operatorhub/flux-operator/testdata/003-catalog-source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: custom
namespace: flux-system
spec:
displayName: custom
description: custom
publisher: custom
sourceType: grpc
image: ghcr.io/controlplaneio-fluxcd/openshift-flux-operator-index:v0.3.0
updateStrategy:
registryPoll:
interval: 30m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: flux-subscription
namespace: flux-system
spec:
channel: stable
name: flux-operator
startingCSV: flux-operator.v0.3.0
source: custom
sourceNamespace: flux-system
7 changes: 7 additions & 0 deletions config/operatorhub/flux-operator/testdata/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:
- 001-flux-system-ns.yaml
- 002-flux-system-og.yaml
- 003-catalog-source.yaml
- 004-operator-subscription.yaml
Loading

0 comments on commit dba1c3a

Please sign in to comment.