koku-metrics-operator

command module
v0.9.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2021 License: AGPL-3.0 Imports: 13 Imported by: 0

README

koku-metrics-operator

Docker Repository on Quay Unit Tests

About

Operator to obtain OCP usage data and upload it to koku. The operator utilizes Golang to collect usage data from an OCP cluster installation.

You must have access to an OpenShift v.4.5+ cluster.

To submit an issue please visit https://issues.redhat.com/projects/COST/

Development

More specific documentation for local development can be found here.

This project was generated using Operator SDK. For a more in depth understanding of the structure of this repo, see the user guide that was used to generate it.

This project requires Go 1.13 or greater if you plan on running the operator locally. To get started developing against koku-metrics-operator first clone a local copy of the git repository.

git clone https://github.com/project-koku/koku-metrics-operator.git

Run the following command to prevent changes to config/manager/kustomization.yaml from being committed to the repo:

git update-index --assume-unchanged config/manager/kustomization.yaml

Now install and configure pre-commit. You can choose your installation steps for pre-commit by using the pre-commit installation instructions. Configure pre-commit for the local repository with the following command:

pre-commit install

Next, install the Operator SDK CLI using the following documentation. The operator is currently being built with the v0.19 release of the operator-sdk.

To build the manager binary you can execute the following make command:

make manager

To build the docker image you can execute the following make command:

make docker-build

Linting can be performed with the following make commands:

make fmt
make lint

Testing

Execute test by running the following make command:

make test

Deploying the Operator

First, create the koku-metrics-operator project. This is where we are going to deploy our Operator.

Before running the operator, the CRD must be registered with the Kubernetes apiserver:

make install

Once this is done, there are two ways to run the operator:

  • As Go program outside a cluster
  • As a Deployment inside a Kubernetes cluster

Configuring your test environment

Projects are scaffolded with unit tests that utilize the envtest library, which requires certain Kubernetes server binaries be present locally. Installation instructions can be found [here][env-test-setup].

1. Run locally outside the cluster

To run the operator locally execute the following command:

$ make run ENABLE_WEBHOOKS=false
2. Run as a Deployment inside the cluster
Build and push the image

Before building the operator image, ensure the generated Dockerfile references the base image you want. You can change the default "runner" image gcr.io/distroless/static:nonroot by replacing its tag with another, for example alpine:latest, and removing the USER: nonroot:nonroot directive.

To build and push the operator image, use the following make commands. Make sure to modify the IMG arg in the example below to reference a container repository that you have access to. You can obtain an account for storing containers at repository sites such quay.io or hub.docker.com. This example uses quay.

Build the image:

$ export USERNAME=<quay-username>

$ make docker-build IMG=quay.io/$USERNAME/koku-metrics-operator:v0.0.1

Push the image to a repository and make sure to set the repository to public:

$ make docker-push IMG=quay.io/$USERNAME/koku-metrics-operator:v0.0.1

Note: The name and tag of the image (IMG=<some-registry>/<project-name>:tag) in both the commands can also be set in the Makefile. Modify the line which has IMG ?= controller:latest to set your desired default image name.

Branches of the repository are built automaticaly here.

Deploy the operator
$ cd config/default/ && kustomize edit set namespace "koku-metrics-operator" && cd ../..

Run the following to deploy the operator. This will also install the RBAC manifests from config/rbac.

$ make deploy IMG=quay.io/$USERNAME/koku-metrics-operator:v0.0.1

You can optionally build, push, and deploy the image all at the same time by running:

$ make build-and-deploy IMG=quay.io/$USERNAME/koku-metrics-operator:v0.0.1

You can also optionally substitute the USER arg for the IMG arg above for the build & deploy commands. Run make help to see all of the options.

NOTE If you have enabled webhooks in your deployments, you will need to have cert-manager already installed in the cluster or make deploy will fail when creating the cert-manager resources.

If your current branch has been pushed to the origin repository then you can deploy your current branch with the following command.

$ make deploy-branch

Verify that the koku-metrics-operator is up and running:

$ oc get deployment

Create a KokuMetricsConfig CR

Create the CR with the default token authentication:

$ make deploy-cr

Create the CR with basic authentication specifying a username and password:

$ make deploy-cr USER=$YOUR_USERNAME PASS=$YOUR_PASSWORD AUTH=basic

Review the logs for the Koku Metrics operator.

Cleanup
$ oc delete -f config/samples/koku-metrics-cfg_v1beta1_kokumetricsconfig.yaml
$ oc delete deployments,service -l control-plane=controller-manager
$ oc delete role,rolebinding --all

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
api
v1beta1
Package v1beta1 contains API Schema definitions for the koku-metrics-cfg v1beta1 API group +kubebuilder:object:generate=true +groupName=koku-metrics-cfg.openshift.io
Package v1beta1 contains API Schema definitions for the koku-metrics-cfg v1beta1 API group +kubebuilder:object:generate=true +groupName=koku-metrics-cfg.openshift.io

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL