This Memcached operator code coverage is an example on how to generate code coverage or profile report on an operator, the memcache-operator was taken as base for this example.
- go version v1.13+.
- docker version 17.03+
- kubectl v1.14.1+
- operator-sdk
- ginkgo
- KiND v0.7.0+
Runtime Code profile for Kubernetes Operators
go mod tidy
export IMAGE=<your image name>
(ie: "quay.io/example-inc/memcached-operator-profile:v0.0.1")make build-profile
to build the instrumented operator.make demo
to run the entired demo which will run the following targetmake create-cluster
to create a KiND clustermake install-profile
to install memcached instrumented operatormake uninstall-profile
to uninstall memcached instrumented operator.make delete-cluster
to delete the KiND cluster.make merge-profile
to merge all profiles.make generate-profile
to generate the profile htlm and get the profile percentage.
Run the following command
$ go mod tidy
Build the Memcached operator image and push it to a public registry, such as quay.io:
$ export IMAGE=quay.io/example-inc/memcached-operator-profile:v0.0.1
$ make build-profile
$ docker push $IMAGE # Optional, only if you use Kube cluster instead of KiND.
Run make create-cluster
to create a new KiND cluster and upload the image.
Run make install-profile
to install the operator. Check that the operator is running in the cluster, also check that the example Memcached service was deployed.
Following the expected result.
$ kubectl get all -n memcached
NAME READY STATUS RESTARTS AGE
pod/example-memcached-7c4df9b7b4-lzd6j 1/1 Running 0 64s
pod/example-memcached-7c4df9b7b4-wbtkz 1/1 Running 0 64s
pod/example-memcached-7c4df9b7b4-wt6jb 1/1 Running 0 64s
pod/memcached-operator-56f54d84bf-zrtfv 1/1 Running 0 69s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/example-memcached ClusterIP 10.108.124.47 <none> 11211/TCP 63s
service/memcached-operator-metrics ClusterIP 10.108.67.82 <none> 8383/TCP,8686/TCP 66s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/example-memcached 3/3 3 3 65s
deployment.apps/memcached-operator 1/1 1 1 70s
NAME DESIRED CURRENT READY AGE
replicaset.apps/example-memcached-7c4df9b7b4 3 3 3 65s
replicaset.apps/memcached-operator-56f54d84bf 1 1 1 70s
To uninstall all that was performed in the above step run make uninstall-profile
.
Use the following command to check the operator logs.
kubectl logs deployment.apps/memcached-operator -n memcached
Run make test-e2e-profile
to run the e2e tests with different options.
For details information on how to implement the profile, read Concept Overview