Operator DevelopmentβοΈ
This page is intended for developers with the aim to share details on how to set up the local environment and start coding in Go language for EPAM Delivery Platform.
PrerequisitesβοΈ
- Git is installed;
- One of our repositories where you would like to contribute is cloned locally;
- Docker is installed;
- Kubectl is set up;
- Local Kubernetes cluster (Kind is recommended) is installed;
- Helm is installed;
- Any IDE (GoLand is used here as an example) is installed;
- GoLang stable version is installed.
Note
Make sure GOPATH and GOROOT environment variables are added in PATH.
Environment SetupβοΈ
Set up your environment by following the steps below.
Set Up Your IDEβοΈ
We recommend using GoLand and enabling the Kubernetes plugin. Before installing plugins, make sure to save your work because IDE may require restarting.
Set Up Your OperatorβοΈ
To set up the cloned operator, follow the three steps below:
-
Configure Go Build Option. Open folder in GoLand, click the button and select the
Go Build
option: -
Fill in the variables in Configuration tab:
- In the
Files
field, indicate the path to the main.go file;
- In the
Working directory
field, indicate the path to the operator;
- In the
Environment field
, specify the namespace to watch by settingWATCH_NAMESPACE
variable. It should equaldefault
but it can be any other if required by the cluster specifications.
- In the
Environment field
, also specify the platform type by settingPLATFORM_TYPE
. It should equal eitherkubernetes
oropenshift
.
- In the
-
Check cluster connectivity and variables. Local development implies working within local Kubernetes clusters. Kind (Kubernetes in Docker) is recommended so set this or another environment first before running code.
Pre-commit ActivitiesβοΈ
Before making commit and sending pull request, take care of precautionary measures to avoid crashing some other parts of the code.
Testing and LintingβοΈ
Testing and linting must be used before every single commit with no exceptions. The instructions for the commands below are written here.
It is mandatory to run test and lint to make sure the code passes the tests and meets acceptance criteria. Most operators are covered by tests so just run them by issuing the commands "make test" and "make lint":
make test
The command "make test" should give the output similar to the following:
make lint
The command "make lint" should give the output similar to the following:
Observe Auto-Generated Docs, API and ManifestsβοΈ
The commands below are especially essential when making changes to API. The code is unsatisfactory if these commands fail.
-
Generate documentation in the .MD file format so the developer can read it:
make api-docs
The command "make api-docs" should give the output similar to the following:
-
There are also manifests within the operator that generate zz_generated.deepcopy.go file in /api/v1 directory. This file is necessary for the platform to work but it's time-consuming to fill it by yourself so there is a mechanism that does it automatically. Update it using the following command and check if it looks properly:
make generate
The command "make generate" should give the output similar to the following:
-
Refresh custom resource definitions for Kubernetes, thus allowing the cluster to know what resources it deals with.
make manifests
The command "make manifests" should give the output similar to the following:
At the end of the procedure, you can push your code confidently to your branch and create a pull request.
That's it, you're all set! Good luck in coding!