Skip to content

Latest commit

 

History

History
232 lines (171 loc) · 7.23 KB

development.md

File metadata and controls

232 lines (171 loc) · 7.23 KB

Development Guide

Table of contents

Prerequisites

  • operator-sdk version v1.2.0
  • docker version 17.03+
  • git
  • go version 1.20
  • kubernetes version v1.22.1+
  • kubectl version v1.22.0+
  • Access to a Kubernetes v1.21.0+ cluster.
  • A user with administrative privileges in the Kubernetes cluster.
  • Make sure that the DOCKER_ORG and DOCKER_REGISTRY environment variables are set to the same value as your username on the container registry, and the container registry you are using.
export DOCKER_ORG=docker_hub_username
export DOCKER_REGISTRY=quay.io

Clone repository

git clone https://github.com/3scale/apicast-operator
cd apicast-operator

Building APIcast operator image

Build operator image

make docker-build-only IMG=$DOCKER_REGISTRY/$DOCKER_ORG/apicast-operator:myversiontag

Run APIcast Operator

Run APIcast Operator Locally

Run the operator locally with the default Kubernetes config file present at $HOME/.kube/config

Run operator from command line, it will not be deployed as pod.

  • Register the APIcast operator CRD in the Kubernetes API Server
// As a cluster admin
make install
  • Create a new Kubernetes namespace (optional)
export NAMESPACE=operator-test
kubectl create namespace ${NAMESPACE}

Do not forget to change the current Kubernetes context to the newly
created namespace or create a new context for it and set the new one as the
active context
  • Install the dependencies
make download
  • Run operator
make run

Deploy custom APIcast Operator using OLM

  • Build and upload custom operator image
make docker-build-only IMG=$DOCKER_REGISTRY/$DOCKER_ORG/apicast-operator:myversiontag
make operator-image-push IMG=$DOCKER_REGISTRY/$DOCKER_ORG/apicast-operator:myversiontag
  • Build and upload custom operator bundle image. Changes to avoid conflicts will be made by the makefile.
make bundle-custom-build IMG=$DOCKER_REGISTRY/$DOCKER_ORG/apicast-operator:myversiontag BUNDLE_IMG=$DOCKER_REGISTRY/$DOCKER_ORG/apicast-operator-bundles:myversiontag
make bundle-image-push BUNDLE_IMG=$DOCKER_REGISTRY/$DOCKER_ORG/apicast-operator-bundles:myversiontag
  • Deploy the operator in your currently configured and active cluster in $HOME/.kube/config:
make bundle-run BUNDLE_IMG=$DOCKER_REGISTRY/$DOCKER_ORG/apicast-operator-bundles:myversiontag

Note: The catalogsource will be installed in the openshift-marketplace namespace issue. By default, cluster scoped subscription will be created in the namespace openshift-marketplace. Feel free to delete the operator (from the UI OperatorHub -> Installed Operators) and install it namespace or cluster scoped.

It will take a few minutes for the operator to become visible under the OperatorHub section of the OpenShift console Catalog. It can be easily found by filtering the provider type to Custom.

Run tests

Run all tests

make test

Run unit tests

make test-unit

Run end-to-end tests

make kind-create-cluster
make test-integration

Bundle management

Generate an operator bundle image

make bundle-build BUNDLE_IMG=$DOCKER_REGISTRY/$DOCKER_ORG/myrepo:myversiontag

Push an operator bundle into an external container repository

make bundle-image-push BUNDLE_IMG=$DOCKER_REGISTRY/$DOCKER_ORG/myrepo:myversiontag

Validate an operator bundle image

NOTE: if validating an image, the image must exist in a remote registry, not just locally.

make bundle-validate-image BUNDLE_IMG=$DOCKER_REGISTRY/$DOCKER_ORG/myrepo:myversiontag

Licenses management

It is a requirement that a file describing all the licenses used in the product is included, so that users can examine it.

  • Check licenses when dependencies change.
make licenses-check
  • Update licenses.xml file.
make licenses.xml

Manually adding a new license

When licenses check does not parse correctly licensing information, it will complain. In that case, you need to add manually license information.

There are two options: a)specify dependency license (recommended) or b)add exception for that dependency.

  • Specify dependency license:
license_finder dependencies add YOURLIBRARY --decisions-file=doc/dependency_decisions.yml LICENSE --project-path "PROJECT URL"

For instance

license_finder dependencies add k8s.io/klog --decisions-file=doc/dependency_decisions.yml "Apache 2.0" --project-path "https://github.com/kubernetes/klog"
  • Adding exception for a dependency:
license_finder approval add YOURLIBRARY --decisions-file=doc/dependency_decisions.yml --why "LICENSE_TYPE LINK_TO_LICENSE"

For instance

license_finder approval add github.com/golang/glog --decisions-file=doc/dependency_decisions.yml --why "Apache 2.0 License https://github.com/golang/glog/blob/master/LICENSE"

Adding new watched secrets

After adding a new secret to the APIcast CRD make sure to also update the following files if you want the apicast-operator to watch the new secret:

  1. apis/apps/v1alpha1/apicast_types.go
    • Add a new GetXYZSecretRef() function that returns the secret ref
  2. apis/apps/v1alpha1/apicast_types.go
    • Update the GetApicastSecretRefs() to call the new GetXYZSecretRef() function from step 1
  3. controllers/apps/apicast_logic_reconciler.go
    • Add the new secret to the getSecretUIDs() function
  4. pkg/apicast/apicast.go
    • Add the new secret to the getWatchedSecretAnnotations() function
  5. pkg/apicast/apicast.go
    • Add the new secret to the switch in the hasSecretHashChanged() function
  6. pkg/apicast/apicast_option_provider.go
    • Add a new const called XYZSecretResverAnnotation that can be referenced throughout the code