Skip to content

Latest commit

 

History

History
190 lines (138 loc) · 6.21 KB

development.md

File metadata and controls

190 lines (138 loc) · 6.21 KB

Development

Table Of Contents

Running Locally

The operator can run locally on the developer's machine. It will monitor the cluster specified in a file indicated by the $KUBECONFIG environment variable:

make install                    # Install CRDs to the cluster
make run ENABLE_WEBHOOKS=false  # Start the operator locally

Webhooks

When running locally, the validating webhooks responsible for verifying the SSP Custom Resource (CR) are deactivated, placing the responsibility on the developer to ensure the usage of the accurate SSP CR.

The Custom Resource Definitions (CRDs) can be removed using:

make uninstall

KubeVirt CI

Alternatively developers can also deploy kubevirtci based clusters before building and deploying the operator.

For convenience the following Makefile targets are provided that automate this flow either directly through the kubevirtci project or indirectly using the main kubevirt project to launch an environment.

Deploy latest released version of KubeVirt:

make cluster-up   # Deploys the latest released version of KubeVirt
make cluster-sync # Builds and deploys the SSP operator from source
make cluster-down # Destroys the environment

Deploy KubeVirt from source:

make kubevirt-up   # Deploys KubeVirt from source
make kubevirt-sync # Builds and deploys the SSP operator from source
make kubevirt-down # Destroys the environment

Testing

Unit Tests

To run unit tests, use this command:

make unittest

Functional Tests

To run functional tests, use this command:

make functest

The following environment variables control how functional tests are run:

  • TEST_EXISTING_CR_NAME and TEST_EXISTING_CR_NAMESPACE - Can be used to set an existing SSP CR to be used during the tests. The CR will be modified, deleted and recreated during testing.
  • SKIP_UPDATE_SSP_TESTS - Skips tests that need to modify or delete the SSP CR. This is useful if the CR is owned by another operator.
  • SKIP_CLEANUP_AFTER_TESTS - Do not remove created resources when the tests are finished.
  • TIMEOUT_MINUTES and SHORT_TIMEOUT_MINUTES - Can be used to increase the timeouts used.

API Changes

When the API definition in api is changed, the generated code and CRDs need to be regenerated, and API submodule has to be updated.

Use these commands:

make vendor
make generate
make manifests

Development Hints

To dive into development for the ssp-operator project, an ideal resource to get started is the Kubebuilder Book. With its foundation on Kubebuilder v3, this book offers valuable insights and guidance for seamless development.

Controllers

Controllers that can be found in controllers:

  • ServiceReconciler - Adds and reconciles a Service that should exist independently of the SSP CR for Prometheus monitoring to work with SSP.
  • SspReconciler - Ensures that all required CRDs are available and reconciles the SSP CRD itself and its operands.
  • 'VmReconciler' - watches for VMs and creates a metric listing VMs with RBD volumes without krbd:rxbounce enabled.

The logic of ssp-operator is split into separate operands, which can be found under internal/operands. Each operand deals with a designated task, all operands are called during the reconciliation of SspReconciler.

SSP Operands

common-instancetypes

Installs the bundled common instance types found in data/common-instancetypes-bundle. A pull request (PR) for updating the bundle is automatically created when a new version of the common-instancetypes is released.

common-templates

Installs the bundled common templates found in data/common-templates-bundle. A pull request (PR) for updating the bundle is automatically created when a new version of the common-templates is released.

data-sources

Manages automatic updates of boot sources for templates in cooperation with Containerized Data Importer (CDI). Data sources to deploy are defined in the SSP CR.

metrics

Installs prometheus monitoring rules for ssp-operator metrics. The available metrics can be found in docs/metrics.md. The installed rules can be found in internal/operands/metrics/resources.go.

tekton-cleanup

Sets a deprecation annotation on old tekton resources created by a previous version of this operator.

template-validator

The main template-validator runs in at least one separate container than the ssp-operator. It is built with validator.Dockerfile.

This operand deploys the template-validator found in internal/template-validator and installs an admission webhook, so the template-validator can evaluate validations found in the vm.kubevirt.io/validations annotation of VirtualMachine resources.

See the old template-validator repository for more docs.

vm-console-proxy

Installs the VM console proxy found in data/vm-console-proxy-bundle. A pull request (PR) for updating the bundle is automatically created when a new version of the vm-console-proxy is released.

Golang CI Linter

A golangci-lint config and Makefile target are provided to keep the codebase aligned to certain best practices and styles.

The target installs golangci-lint if it is not already present. To run use the following command:

make lint

The target is also used when running unit tests locally.

Pre-commit Hooks

A pre-commit config is provided to help developers catch any simple mistakes prior to committing their changes.

To install and use the tool please run the following commands:

pip install --user pre-commit
pre-commit install
git commit -s