|
| 1 | +# Ghost Operator Development Guide |
| 2 | + |
| 3 | +## Getting Started |
| 4 | + |
| 5 | +This project is a regular [Kubernetes Operator](https://coreos.com/operators/) built using the Operator SDK. Refer to the Operator SDK documentation to understand the basic architecture of this operator. |
| 6 | + |
| 7 | +### Installing the Operator SDK command line tool |
| 8 | + |
| 9 | +Follow the installation guidelines from [Operator SDK GitHub page](https://github.com/operator-framework/operator-sdk) or run `make install-sdk`. |
| 10 | + |
| 11 | +### Developing |
| 12 | + |
| 13 | +The first step is to get a local Kubernetes instance up and running. You can use any tools as you want eg: [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/), [docker-for-desktop](https://docs.docker.com/docker-for-mac/install/) or [kind](https://github.com/kubernetes-sigs/kind#installation-and-usage). |
| 14 | + |
| 15 | +Most of development processes can be done with the `make` command. See available `make` command by executing |
| 16 | + |
| 17 | +``` |
| 18 | +make help |
| 19 | +``` |
| 20 | + |
| 21 | +Once local kubernetes has finished starting, apply the CustomResourceDefinitions: |
| 22 | + |
| 23 | +``` |
| 24 | +kubectl apply -f deploy/crds/ghost.fossil.or.id_ghostapps_crd.yaml |
| 25 | +``` |
| 26 | + |
| 27 | +Then you can get the Operator running: |
| 28 | + |
| 29 | +``` |
| 30 | +make run |
| 31 | +``` |
| 32 | + |
| 33 | +At this point, a GhostApp instance can be installed: |
| 34 | + |
| 35 | +``` |
| 36 | +kubectl apply -f deploy/example/ghost.fossil.or.id_v1alpha1_ghostapp_cr.yaml |
| 37 | +kubectl get ghostapp |
| 38 | +``` |
| 39 | + |
| 40 | +Example GhostApp status: |
| 41 | + |
| 42 | +``` |
| 43 | +NAME REPLICAS PHASE AGE |
| 44 | +example-ghostapp 1 Running 12s |
| 45 | +``` |
| 46 | + |
| 47 | +To remove the instance: |
| 48 | + |
| 49 | +``` |
| 50 | +kubectl delete -f deploy/example/ghost.fossil.or.id_v1alpha1_ghostapp_cr.yaml |
| 51 | +``` |
| 52 | + |
| 53 | +### Testing |
| 54 | + |
| 55 | +Tests should be simple unit tests and/or end-to-end tests. For small changes, unit tests should be sufficient, but every new feature should be accompanied with end-to-end tests as well. Tests can be executed with: |
| 56 | + |
| 57 | +``` |
| 58 | +make test |
| 59 | +``` |
| 60 | + |
| 61 | +The whole set of end-to-end tests can be executed via: |
| 62 | + |
| 63 | +``` |
| 64 | +make test-e2e |
| 65 | +``` |
| 66 | + |
| 67 | +> NOTE: the command above requires you to build the Docker image and push to container registry. You can see instruction to build Docker image bellow. |
| 68 | +
|
| 69 | +Instead that, you can also run end-to-end tests locally with: |
| 70 | + |
| 71 | +``` |
| 72 | +make test-e2e-local |
| 73 | +``` |
| 74 | + |
| 75 | +### Build |
| 76 | + |
| 77 | +To build Docker image of this operator can be executed with: |
| 78 | + |
| 79 | +``` |
| 80 | +make build |
| 81 | +``` |
| 82 | + |
| 83 | +> NOTE: by default, command above will build Docker image with tag `fossildev/ghost-operator:latest`. You can adjust the Docker image tag by overriding the variable `IMAGE_TAG`, like: |
| 84 | +
|
| 85 | +``` |
| 86 | +IMAGE_TAG=docker.io/yourusername/ghost-operator:latest make build |
| 87 | +``` |
| 88 | + |
| 89 | +Then you can push the Docker image as usually |
| 90 | + |
| 91 | +``` |
| 92 | +docker push docker.io/yourusername/ghost-operator:latest |
| 93 | +``` |
0 commit comments