Skip to content

Commit

Permalink
[WIP] Use operator-sdk for bundling
Browse files Browse the repository at this point in the history
Fixes #73
  • Loading branch information
andrewazores committed Feb 20, 2020
1 parent a64f146 commit 9198324
Show file tree
Hide file tree
Showing 20 changed files with 1,713 additions and 262 deletions.
57 changes: 41 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
IMAGE_TAG ?= quay.io/rh-jmc-team/container-jfr-operator:0.3.0
CRDS := containerjfr flightrecorder
IMAGE_STREAM ?= quay.io/rh-jmc-team/container-jfr-operator
IMAGE_VERSION ?= 0.4.0
IMAGE_TAG ?= $(IMAGE_STREAM):$(IMAGE_VERSION)
BUNDLE_STREAM ?= $(IMAGE_STREAM)-bundle
BUILDER ?= podman
CSV_VERSION ?= 0.4.0

.DEFAULT_GOAL := bundle

Expand All @@ -14,17 +18,42 @@ k8s:
crds:
operator-sdk generate crds

.PHONY: csv
csv:
# from-version should be programatically determined
operator-sdk generate csv \
--from-version 0.3.3 \
--csv-config ./deploy/olm-catalog/csv-config.yaml \
--csv-version $(CSV_VERSION) \
--csv-channel alpha \
--default-channel \
--update-crds \
--operator-name container-jfr-operator-bundle

.PHONY: image
image: generate
operator-sdk build --image-builder podman $(IMAGE_TAG)
operator-sdk build --image-builder $(BUILDER) $(IMAGE_TAG)

.PHONY: bundle
bundle: image copy-crds
operator-courier verify --ui_validate_io bundle

.PHONY: copy-crds
copy-crds:
$(foreach res, $(CRDS), cp -f deploy/crds/rhjmc.redhat.com_$(res)s_crd.yaml bundle/$(res)s.rhjmc.redhat.com.crd.yaml;)
bundle: csv image
@echo "TODO: create application bundle"
# operator-sdk bundle create \
# --generate-only \
# --image-builder $(BUILDER) \
# --directory ./deploy/olm-catalog/container-jfr-operator-bundle/$(CSV_VERSION) \
# --default-channel alpha \
# --channels alpha \
# --package container-jfr-operator-bundle

.PHONY: validate
validate: verify-csv
operator-sdk bundle validate \
--image-builder $(BUILDER) \
$(IMAGE_TAG)

.PHONY: verify-csv
verify-csv:
operator-courier verify deploy/olm-catalog/container-jfr-operator-bundle

.PHONY: test
test: undeploy scorecard
Expand All @@ -37,10 +66,6 @@ scorecard: generate
clean: clean-bundle
rm -rf build/_output

.PHONY: clean-bundle
clean-bundle:
rm -f bundle/*.crd.yaml




Expand All @@ -50,11 +75,11 @@ clean-bundle:

.PHONY: catalog
catalog: remove_catalog
oc create -f bundle/openshift/operator-source.yaml
oc create -f deploy/olm-catalog/openshift/operator-source.yaml

.PHONY: remove_catalog
remove_catalog:
- oc delete -f bundle/openshift/operator-source.yaml
- oc delete -f deploy/olm-catalog/openshift/operator-source.yaml

.PHONY: deploy
deploy: undeploy
Expand Down Expand Up @@ -82,7 +107,7 @@ undeploy: undeploy_sample_app undeploy_sample_app2
- oc delete serviceaccount container-jfr-operator
- oc delete crd flightrecorders.rhjmc.redhat.com
- oc delete crd containerjfrs.rhjmc.redhat.com
- oc delete -f bundle/openshift/operator-source.yaml
- oc delete -f deploy/olm-catalog/openshift/operator-source.yaml

.PHONY: sample_app
sample_app:
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ at the URL provided by

# Building
## Requirements
- `go`
- `go` v1.13
- [operator-sdk](https://github.com/operator-framework/operator-sdk) v0.15.2
- `podman`

Expand All @@ -21,24 +21,24 @@ at the URL provided by
setting the environment variable `IMAGE_TAG`.

To (re)build the Operator bundle for packaging in catalogs (ex. OperatorHub),
use operator-courier, ex.
`operator-courier push bundle rh-jmc-team container-jfr-operator-bundle $VERSION $TOKEN`
, where `$VERSION` is the version string matching that within the bundle
definition YAMLs, and `$TOKEN` has been replaced by your personal quay.io
`make bundle`. This will create an Operator bundle image containing the
required YAML manifest files and metadata for publishing the bundle.
To publish the bundle image to the Quay application image registry, use ex.
`./bin/bundle-upload $BUNDLE_STREAM $CSV_VERSION $QUAY_TOKEN`
, where `$BUNDLE_STREAM` is the image stream tag of the bundled image
(for example, `quay.io/rh-jmc-team/container-jfr-operator-bundle`),
`$CSV_VERSION` is the version string matching that within the bundle
definition YAMLs (ex. `0.1.0`), and `$QUAY_TOKEN` is your personal quay.io
access token.

To make this bundle available within the OpenShift Console's Operator Catalog,
add the custom Operator Source via `oc apply -f bundle/openshift/operator-source.yaml`

# Setup / Deployment

## UI-Guided Deployment

The operator can be deployed using the Operator Marketplace in the graphical
OpenShift console by first adding a custom operator source. A YAML definition
of such a custom source is at `bundle/openshift/operator-source.yaml`, which
of such a custom source is at `deploy/olm-catalog/openshift/operator-source.yaml`, which
can be added to your cluster by
`oc create -f bundle/openshift/operator-source.yaml` or simply `make catalog`.
`oc create -f deploy/olm-catalog/openshift/operator-source.yaml` or simply `make catalog`.
This method allows the latest released version of the operator to be installed
into the cluster with the same method and in the same form that end users would
receive it.
Expand Down
26 changes: 26 additions & 0 deletions bin/bundle-upload
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -x
set -e

BUNDLE_STREAM="$1"
CSV_VERSION="$2"
QUAY_TOKEN="$3"

NAMESPACE=${BUNDLE_STREAM#"quay.io/"}

TAG="$BUNDLE_STREAM:$CSV_VERSION"

OUTD=`mktemp --directory --suffix=container-jfr-operator-bundle`
OUTF="container-jfr-operator-bundle.v$CSV_VERSION"
pushd ./deploy/olm-catalog
tar czf "$OUTD/$OUTF.tar.gz" ./container-jfr-operator-bundle
popd

set +e
set +x

BLOB=$(base64 -w 0 "$OUTD/$OUTF.tar.gz")
curl -XPOST -H "Authorization: $QUAY_TOKEN" -H "Content-Type: application/json" \
"https://quay.io/cnr/api/v1/packages/$NAMESPACE?force=true" \
-d '{ "blob": "'"${BLOB}"'", "release": "'"${CSV_VERSION}"'", "media_type": "helm" }'
4 changes: 0 additions & 4 deletions bundle/container-jfr-operator-bundle.package.yaml

This file was deleted.

Loading

0 comments on commit 9198324

Please sign in to comment.