Skip to content

Commit

Permalink
Create stable channel and 1.0.0 release (#44)
Browse files Browse the repository at this point in the history
* Create stable channel and 1.0.0 release

Create a new channel called stable which will host the 1.0.0
release of Smart Gateway Operator.

* Set Smart Gateway container image from env var

Setting the container image for the Smart Gateway from an environment variable allows
for setting a specific version of the Smart Gateway to come up, allowing versions to
be tied to the Operator container image itself, and thus a CSV version.

Looking at other Operators, any dependent images seem to get set via environment variable
on the Operator, and then used for instantiating the desired set of images for that CSV.

If the SMARTGATEWAY_IMAGE environment variable is not set, then the default is to use
the latest image from quay.io/infrawatch/smart-gateway.

* Don't reference beta1 in semver

* Only release on tagged versions
  • Loading branch information
leifmadsen authored Mar 13, 2020
1 parent 3f80771 commit 2d39f3f
Show file tree
Hide file tree
Showing 24 changed files with 677 additions and 98 deletions.
6 changes: 4 additions & 2 deletions .osdk-scorecard.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
scorecard:
# Setting a global scorecard option
version: v1alpha2
output: text
bundle: deploy/olm-catalog/smart-gateway-operator/1.0.0/metadata
plugins:
- basic:
cr-manifest:
- "deploy/crds/smartgateway.infra.watch_v2alpha1_smartgateway.metrics_cr.yaml"
csv-path: "deploy/olm-catalog/smart-gateway-operator/1.0.0/smart-gateway-operator.v1.0.0.clusterserviceversion.yaml"
- olm:
cr-manifest:
- "deploy/crds/smartgateway.infra.watch_v2alpha1_smartgateway.metrics_cr.yaml"
csv-path: "deploy/olm-catalog/smart-gateway-operator/0.2.0/smart-gateway-operator.v0.2.0.clusterserviceversion.yaml"
csv-path: "deploy/olm-catalog/smart-gateway-operator/1.0.0/smart-gateway-operator.v1.0.0.clusterserviceversion.yaml"
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ script:
- operator-courier verify --ui_validate_io deploy/olm-catalog/smart-gateway-operator
- ansible-lint roles/smartgateway/
after_success:
- export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH;
else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)
- echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH"
- "./build/travis/after_success.sh"
- if [ "$TRAVIS_TAG" == "" ]; then echo "Not a tagged release, skipping after_success.sh"; else ./build/travis/after_success.sh; fi
165 changes: 147 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,174 @@ development is available at https://github.com/code-ready/crc.
A procedure for testing in CodeReady Containers will be available soon.

* buildah
* 1.12.0
* 1.14.0
* kubernetes
* v1.14.0
* v1.16.2
* crc
* crc version: 1.3.0+918756b
* crc version: 1.6.0+8ef676f
* oc
* openshift-clients-4.2.0-201910041700
* operator-sdk
* v0.12.0 (!0.13.0 which causes regressions via `gen-csv` command)
* v0.15.2 (!0.13.0 which causes regressions via `gen-csv` command)

### Set up crc and buildah
### Set up CRC and buildah

<todo>
Setup CRC and then login with the `kubeadmin` user.

```
$ crc setup
$ crc start --memory=32768
$ crc console --credentials
```

Install `buildah` via `dnf`.

```
sudo dnf install buildah -y
```

### Login to CRC registry

```
REGISTRY=$(oc registry info)
TOKEN=$(oc whoami -t)
INTERNAL_REGISTRY=$(oc registry info --internal=true)
buildah login --tls-verify=false -u openshift -p "${TOKEN}" "${REGISTRY}"
```

### Build the operator

<todo>
```
buildah bud -f build/Dockerfile -t "${REGISTRY}/default/smart-gateway-operator:latest" .
buildah push --tls-verify=false "${REGISTRY}/default/smart-gateway-operator:latest"
```

### Deploy with the newly built operator

<todo>
Install required RBAC rules and service account.

### FIXME - Unit testing
```
oc apply \
-f deploy/role_binding.yaml \
-f deploy/role.yaml \
-f deploy/service_account.yaml \
-f deploy/operator_group.yaml
```

With molecule (Currently broken)
Pick a version from `deploy/olm-catalog/smart-gateway-operator/` and run the
following commands. Adjust version to what you want to test. We'll be using
`v1.0.0` as our example version.

### Integration testing
```
CSV_VERSION=1.0.0
INTERNAL_REGISTRY=$(oc registry info --internal=true)
oc apply -f deploy/olm-catalog/smart-gateway-operator/${CSV_VERSION}/smartgateway.infra.watch_smartgateways_crd.yaml
oc create -f <(sed "\
s|image: .\+/smart-gateway-operator:.\+$|image: ${INTERNAL_REGISTRY}/default/smart-gateway-operator:latest|g;
s|namespace: placeholder|namespace: default|g"\
"deploy/olm-catalog/smart-gateway-operator/${CSV_VERSION}/smart-gateway-operator.v${CSV_VERSION}.clusterserviceversion.yaml")
```

Test the newly built operator with the Service Telemetry Framework (STF).
Validate that installation of the `ClusterServiceVersion` is progressing via
the `oc` CLI console.
```
oc get csv --watch
```
If you see `PHASE: Succeeded` then your CSV has been properly imported and
your Operator should be running locally. You can validate this by running `oc
get pods` and looking for the `smart-gateway-operator` and that it is
`Running`.

<todo>
You can bring up the logs of the Smart Gateway Operator by running `oc logs
<<pod_name>> -c operator`.

## Creating a Smart Gateway

<update>
To create a Smart Gateway, you'll need to connect it to a compatible AMQP 1.x
message bus. For demonstration purposes we're going to use the Red Hat AMQ
Interconnect Operator, create an AMQ Interconnect instance, then create a Smart
Gateway instance that connects to it.

### Create AMQ Interconnect Subscription

```
oc apply -f - <<EOF
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: amq7-interconnect-operator
namespace: default
spec:
channel: 1.2.0
installPlanApproval: Automatic
name: amq7-interconnect-operator
source: redhat-operators
sourceNamespace: openshift-marketplace
EOF
```

Start a new smart gateway by creating a CustomResource object
based on the example:
You can check the status of the AMQ Interconnect ClusterServiceVersion
installation with `oc get csv`. When complete you should see `PHASE:
Succeeded`.

```shell
oc create -f deploy/crds/smartgateway.infra.watch_v2alpha1_smartgateway.metrics_cr.yaml
### Create AMQ Interconnect Instance

```
oc apply -f - <<EOF
apiVersion: interconnectedcloud.github.io/v1alpha1
kind: Interconnect
metadata:
name: amq-interconnect
namespace: default
spec:
addresses:
- distribution: closest
prefix: closest
- distribution: multicast
prefix: multicast
- distribution: closest
prefix: unicast
- distribution: closest
prefix: exclusive
- distribution: multicast
prefix: broadcast
deploymentPlan:
livenessPort: 8888
placement: Any
resources: {}
role: interior
size: 2
edgeListeners:
- port: 45672
interRouterListeners:
- port: 55672
listeners:
- port: 5672
- authenticatePeer: true
expose: true
http: true
port: 8080
users: amq-interconnect-users
EOF
```

Validate that you see both AMQ Interconnect routers come up with `oc get pods`.

### Create Smart Gateway Instance

```
oc apply -f - <<EOF
apiVersion: smartgateway.infra.watch/v2alpha1
kind: SmartGateway
metadata:
name: cloud1-metrics
namespace: default
spec:
amqpUrl: amq-interconnect:5672/collectd/telemetry
debug: true
prefetch: 15000
serviceType: metrics
size: 1
EOF
```
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM quay.io/operator-framework/ansible-operator:v0.12.0
FROM quay.io/operator-framework/ansible-operator:v0.14.1

COPY roles/ ${HOME}/roles/
COPY watches.yaml ${HOME}/watches.yaml
4 changes: 4 additions & 0 deletions build/metadata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
CSV_VERSION=${CSV_VERSION:-1.0.0}
UNIXDATE=$(date +%s)
ORGANIZATION=${ORGANIZATION:-infrawatch}
23 changes: 23 additions & 0 deletions build/new_csv_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env sh

if [ -z "$CSV_VERSION" ]; then
echo -n "CSV version to create [e.g. 1.1.0]: "
read CSV_VERSION
fi

if [ -z "$FROM_VERSION" ]; then
echo -n "CSV version to upgrade from [e.g. 1.0.0]: "
read FROM_VERSION
fi

if [ -z "$CSV_CHANNEL" ]; then
echo -n "CSV channel to publish to [e.g. stable]: "
read CSV_CHANNEL
fi


operator-sdk generate csv --csv-version=${CSV_VERSION} \
--from-version=${FROM_VERSION} \
--operator-name smart-gateway-operator \
--update-crds \
--csv-channel="${CSV_CHANNEL}"
5 changes: 1 addition & 4 deletions build/push_app2quay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# contents of this file originally from https://redhat-connect.gitbook.io/certified-operator-guide/ocp-deployment/openshift-deployment

set -e

CSV_VERSION=${CSV_VERSION:-0.2.0}
UNIXDATE=$(date +%s)
ORGANIZATION=${ORGANIZATION:-infrawatch}
REL=$(dirname "$0"); source "${REL}/metadata.sh"

if [ -z "$USERNAME" ]; then
echo -n "Username: "
Expand Down
22 changes: 8 additions & 14 deletions build/travis/after_success.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@

# Fail on error
set -e

REL=$(dirname "$0")

# Add everything, get ready for commit. But only do it if we're on master or a
# named branch of the format <#>.<#>.X. If you want to deploy on different
# branches, you can change this.
if [[ "$BRANCH" =~ ^master$|^[0-9]+\.[0-9]+\.X$ ]]; then
echo "Branch is master, so push new application to Quay registry"
export PATH=$HOME/bin:$PATH
curl -L https://github.com/operator-framework/operator-sdk/releases/download/v0.15.2/operator-sdk-v0.15.2-x86_64-linux-gnu -o $HOME/bin/operator-sdk
chmod +x $HOME/bin/operator-sdk
${REL}/../update_csv.sh
${REL}/../push_app2quay.sh
else
echo "Not on master, so won't push new application artifacts"
fi
echo "Pushing new application to Quay registry"
export PATH=$HOME/bin:$PATH
curl -L https://github.com/operator-framework/operator-sdk/releases/download/v0.15.2/operator-sdk-v0.15.2-x86_64-linux-gnu -o "$HOME/bin/operator-sdk"
chmod +x "$HOME/bin/operator-sdk"

# Push new application version, but strip the first character which is expected to be 'v'
# Why not just create tags that don't have 'v'? Because the container image versions are expected to lead with a 'v'. Fun!
CSV_VERSION="${TRAVIS_TAG:1}" "${REL}/../push_app2quay.sh""
4 changes: 3 additions & 1 deletion build/update_csv.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env sh
operator-sdk generate csv --csv-version 0.2.0 --operator-name smart-gateway-operator --update-crds
set -e
REL=$(dirname "$0"); source "${REL}/metadata.sh"
operator-sdk generate csv --csv-version=${CSV_VERSION} --operator-name smart-gateway-operator --update-crds
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ spec:
type: integer
containerImagePath:
description: Path to the container image this Operator will deploy. Value is defined as the standard registry/image_name:tag
format. Defaults to 'quay.io/infrawatch/smart-gateway:latest'
format.
type: string
useTimestamp:
description: Use the source timestamp (time when data was collected) rather than let Prometheus write when the data was
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ spec:
name: smart-gateway-operator
links:
- name: Source Code
url: https://github.com/infrawatch/smart-gateway-operator.0.2.0
url: https://github.com/infrawatch/smart-gateway-operator
maintainers:
- email: [email protected]
name: Red Hat CloudOps DFG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM scratch

LABEL operators.operatorframework.io.bundle.mediatype.v1=plain
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=smart-gateway-operator
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
LABEL operators.operatorframework.io.bundle.channel.default.v1=alpha
LABEL operators.operatorframework.io.bundle.channels.v1=stable
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable

COPY /*.yaml /manifests/
COPY /metadata/annotations.yaml /metadata/annotations.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
annotations:
operators.operatorframework.io.bundle.channel.default.v1: alpha
operators.operatorframework.io.bundle.channels.v1: alpha
operators.operatorframework.io.bundle.channel.default.v1: stable
operators.operatorframework.io.bundle.channels.v1: stable
operators.operatorframework.io.bundle.manifests.v1: manifests/
operators.operatorframework.io.bundle.mediatype.v1: plain
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
operators.operatorframework.io.bundle.metadata.v1: metadata/
operators.operatorframework.io.bundle.package.v1: smart-gateway-operator
Loading

0 comments on commit 2d39f3f

Please sign in to comment.