Skip to content

Instantly share code, notes, and snippets.

@timflannagan
Last active September 25, 2019 14:03
Show Gist options
  • Save timflannagan/6cef00d45279ebfa082c2c625a9cf597 to your computer and use it in GitHub Desktop.
Save timflannagan/6cef00d45279ebfa082c2c625a9cf597 to your computer and use it in GitHub Desktop.

Overview

This would add another Go package aimed at emulating the manual install/uninstall logic that's currently done in the hack/install.sh andhack/uninstall.sh scripts. When interacting with the deploy-metering binary, you have the choice of using the command flags available, or their respective environment variable. In the case where both the flag, and the environment variable are specified, the flag value takes precedence.

Building the binary

$ make bin/deploy-metering

Link to PRs:

  1. Deploy package: kube-reporting/metering-operator#921
  2. Deploy CLI: kube-reporting/metering-operator#934

Prerequisites

With the addition of the deploy-metering cli, we can assign a default (typically an empty value) value most of the configuration options. This means that the only required flag/environment variable that needs to be set (and this is also validated within the deploy package) is the namespace in which the metering stack is managed. Before deploying metering set the following:

$ export METERING_NAMESPACE="metering"

or

$ ./bin/deploy-metering install --namespace metering

It's important to note that when the MeteringConfig custom resource is unspecified, the package uses the manifests/deploy/$DEPLOY_PLATFORM/metering-ansible-operator/default.yaml as the default MeteringConfig resource, which will fail validation in the metering-ansible-operator due to a missing storage section.

doesn't include any storage options, so the install process will succeed, but fail during the metering-ansible-operator storage validation tasks.

General Configuration Options:

  • $METERING_NAMESPACE/--namespace: the namespace to deploy metering resources on.
  • $METERING_CR_FILE/--metering-cr: the relative (or absolute) path to a customized MeteringConfig custom resource.
  • $DEPLOY_MANIFESTS_DIR/--deploy-manifests-dir: the relative (or absolute) path to the manifests/deploy/ directory. Set this when working outside of the operator-metering cloned repository, or when the bin/deploy-metering binary has been moved to the user's /usr/local/bin directory.
  • $DEPLOY_PLATFORM/--deploy-platform: the platform in which metering is deploy on. The supported values include "upstream", "openshift", and "ocp-testing".

Install-Only Configuration Options:

  • $SKIP_METERING_OPERATOR_DEPLOYMENT/--skip-metering-operator-deployment: create only the $METERING_NAMESPACE namespace, the metering CRDs, and the MeteringConfig CR.
  • $METERING_OPERATOR_IMAGE_REPO/--repo: override the image repository used in the metering-ansible-operator container images.
  • $METERING_OPERATOR_IMAGE_TAG/--tag: override the image tag used in the metering-ansible-operator container images.

Note: You need to set both the image repository and tag to override any of the container images.

Uninstall-Only Configuration Options:

  • $METERING_DELETE_NAMESPACE/--delete-namespace: defaults to false
  • $METERING_DELETE_CRDS/--delete-crd: defaults to false
  • $METERING_DELETE_CRB/--delete-crb: defaults to false
  • $METERING_DELETE_PVCS/--delete-pvc: defaults to true
  • $METERING_DELETE_ALL/--delete-all: defaults to false. This sets all the internal states that rely on the value of the ENV vars listed above, to true.

Example of precedence

$ export METERING_NAMESPACE="metering"
$ ./bin/deploy-metering install --namespace test
INFO[09-17-2019 14:54:42] Setting the log level to info                 app=deploy
INFO[09-17-2019 14:54:42] Metering Deploy Namespace: test               app=deploy
...

Install Usage Examples

Note: You can either use the flags, or the environment variables when running any of the following examples. Also, specify a customized MeteringConfig custom resource before running any of these examples.

Vanilla install on Openshift/OCP:
$ export METERING_NAMESPACE="metering"
$ ./bin/deploy-metering install
Vanilla install on upstream:
$ export METERING_NAMESPACE="metering"
$ export DEPLOY_PLATFORM="upstream"
$ ./bin/deploy-metering install
Skip installing the metering operator:
$ export METERING_NAMESPACE="metering"
$ export SKIP_METERING_OPERATOR_DEPLOYMENT="true"
$ ./bin/deploy-metering install
Override the default images install:
$ export METERING_NAMESPACE="metering"
$ export METERING_OPERATOR_IMAGE_REPO="quay.io/tflannag/origin-metering-ansible-operator"
$ export METERING_OPERATOR_IMAGE_TAG="latest"
$ ./bin/deploy-metering install
Specify manifest location explicitly install:
$ pwd
/home/tflannag/go/src/github.com/operator-framework/operator-metering
$ cd ../
$ pwd
/home/tflannag/go/src/github.com/operator-framework
$ export METERING_NAMESPACE="metering"
$ export DEPLOY_MANIFESTS_DIR="operator-metering/manifests/deploy"
$ ./operator-metering/bin/deploy-metering install

Uninstall Usage Examples

Note: set the $METERING_CR_FILE before running any of these examples.

Vanilla uninstall on Openshift/OCP:
$ export METERING_NAMESPACE="metering"
$ ./bin/deploy-metering uninstall
Vanilla uninstall for upstream:
$ export METERING_NAMESPACE="metering"
$ export DEPLOY_PLATFORM="upstream"
$ ./bin/deploy-metering uninstall
Delete cluster role/role binding during an uninstall:
$ export METERING_NAMESPACE="metering"
$ export METERING_DELETE_CRB="true"
$ ./bin/deploy-metering uninstall

Note: only the $METERING_NAMESPACE and the metering CRDs should be skipped. Also, the reporting-operator creates the cluster-monitoring-view cluster role, but due to owner ref, that's not cleaned up.

Delete cluster role/role binding and namespace during an uninstall:
$ export METERING_NAMESPACE="metering"
$ export METERING_DELETE_CRB="true"
$ ./bin/deploy-metering uninstall
Delete all traces of the metering stack during an uninstall:
$ export METERING_NAMESPACE="metering"
$ export METERING_DELETE_ALL="true"
$ ./bin/deploy-metering uninstall

Note: The entire metering stack should be deleted (except for the cluster-monitoring-view mentioned above).

QE Notes:

  1. Before the PRs listed above were merged, we needed to add the MeteringConfig resource to the metering clientset. It would be nice to test out different MeteringConfig resource configurations while installing, and verifying that all the specified fields match the yaml output in the case where some structures were misformatted during development.
  2. Also need to verify that the storage options are still working.
@timflannagan
Copy link
Author

@timflannagan1, I found an issue such that the deploy-metering will fail if off-site storage cred is not given, i.e. the correct screte is not created

Can you provide more detail like the MeteringConfig you used, and the logs/stack trace?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment