openshift / vertical-pod-autoscaler-operator

An Operator for running the Vertical Pod Autoscaler on OpenShift
Apache License 2.0
27 stars 30 forks source link

Vertical Pod Autoscaler Operator

The vertical-pod-autoscaler-operator manages deployments and configurations of the OpenShift Vertical Pod Autoscaler's three controllers. The three controllers are:

OpenShift VPA is documented in the OpenShift product documentation.

Custom Resource Definitions

The operator manages the following custom resource:

Deployment

Prerequisites

Setup / Deployment

Manual Deployment

You can run the operator locally outside of the cluster for development purposes. This is useful for testing changes to the operator code without having to build and deploy a new image to the cluster.

Run the operator locally

make run

You can also deploy the operator ot an OpenShift cluster using static manifests. This requires the operator image to be built and pushed to a registry accessible by the cluster.

Build and push the operator image

make docker-build docker-push OPERATOR_IMG=<some-registry>/vertical-pod-autoscaler-operator:tag

Deploy the operator

make deploy OPERATOR_IMG=<some-registry>/vertical-pod-autoscaler-operator:tag

[!NOTE] This image ought to be published in the personal registry you specified. And it is required to have access to pull the image from the working environment. Make sure you have the proper permission to the registry if the above commands don’t work.

Bundle Deployment

The operator can be deployed using OLM with make deploy-bundle. This will create a bundle deployment to your cluster. You must first build and push your own custom operator image and bundle images to a registry accessible by the cluster.

Build and push the bundle image

make bundle bundle-build bundle-push BUNDLE_IMG=<some-registry>/vertical-pod-autoscaler-operator-bundle:tag

[!NOTE] make bundle - Generates the bundle manifests and metadata for the operator. This will create a bundle/ directory in the root of the repository.

Now you can deploy the operator using the bundle image:

make deploy-bundle \
BUNDLE_IMG=<some-registry>/vertical-pod-autoscaler-operator-bundle:tag \
OPERATOR_IMG=<some-registry>/vertical-pod-autoscaler-operator:tag

[!TIP] Note the environment variables for the deploy-bundle target:

  • BUNDLE_IMG - The bundle image to be deployed.
  • OPERATOR_IMG - The operator image to be deployed.
  • OPERAND_IMG - Optionally, you can specify this environment variable to deploy the operand image.

Uninstall bundle

make undeploy-bundle

Catalog Source Deployment

The operator can also be deployed using OLM with make deploy-catalog. This will create a CatalogSource with the operator included, as well as deploy a Subscription which automatically installs the operator.

For convenience, you can use the full-olm-deploy target to build and push the operator image, bundle, build, and push the bundle image, and build, push, and deploy the Catalog image:

make full-olm-deploy \
IMAGE_TAG_BASE=<some-registry>vertical-pod-autoscaler-operator \
OPERATOR_VERSION=0.0.0-version

[!TIP] Instead of defining the [OPERATOR|BUNDLE|CATALOG]_IMGs directly, you can use the IMAGE_TAG_BASE and OPERATOR_VERSION variables to define the image tags for all three images. This will create:

  • OPERATOR_IMG: <some-registry>/vertical-pod-autoscaler-operator:0.0.0-version
  • BUNDLE_IMG: <some-registry>/vertical-pod-autoscaler-operator-bundle:0.0.0-version
  • CATALOG_IMG: <some-registry>/vertical-pod-autoscaler-operator-catalog:0.0.0-version

Uninstall catalog

make undeploy-catalog

Lints and Checks

Run make check to perform all checks that do not require a cluster.

Here are the individual checks:

Testing

make test runs the unit tests for the operator.

make test-scorecard will run Operator SDK's scorecard tests. This requires a Kubernetes or OpenShift cluster to be available and configured in your environment. The tests will be run against the cluster.

make test-e2e will run the e2e tests for the operator. These tests assume the presence of a cluster not already running the operator, and that the KUBECONFIG environment variable points to a configuration granting admin rights on said cluster. It assumes the operator is already deployed. If not, the following commands can run the e2e steps in one command:

make e2e-local - Manually deploys the operator to the cluster, and runs the e2e tests. Requires:

make e2e-olm-local - Manually deploys the operator to the cluster using OLM, and runs the e2e tests.

make e2e-olm-local \
IMAGE_TAG_BASE=<some-registry>vertical-pod-autoscaler-operator \
OPERATOR_VERSION=0.0.0-version \
KUBECONFIG=<path-to-kubeconfig>

All tests should clean up after themselves.

[!TIP] The e2e tests clones the upstream VPA repository to a temporary directory and runs upstream tests against the cluster. Optionally, you can specify an environment variable AUTOSCALER_TMP to specify an existing directory to use. If specified, the e2e script will checkout the correct branch, and pull. This saves network bandwidth and time from cloning the repository each time.