|
| 1 | +# Contribution Guide |
| 2 | + |
| 3 | +1. [Prerequisites](#prerequisites) |
| 4 | +2. [Build](#build) |
| 5 | +3. [Check](#check) |
| 6 | +4. [Testing](#testing) |
| 7 | +5. [Pull-request](#pull-request) |
| 8 | +6. [License](#license) |
| 9 | + |
| 10 | +Thank you for your time and effort to help us improve samba-operator. |
| 11 | +Here are a few steps to get started, with reference to some useful |
| 12 | +resources. |
| 13 | + |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +Development effort takes place using Linux environment and requires at |
| 18 | +minimum: |
| 19 | + |
| 20 | +1. [Go 1.18](https://golang.org/dl/) installed |
| 21 | +2. [GitHub](https://github.com/) account |
| 22 | +3. Development tools: git, make, and podman or docker |
| 23 | +4. Testing: [minikube](https://minikube.sigs.k8s.io) |
| 24 | +5. [Quay](https://quay.io/) account (optional) |
| 25 | + |
| 26 | +Development collaboration takes place via github's samba-in-kubernetes |
| 27 | +([SINK](https://github.com/samba-in-kubernetes/)) pages and facilities. |
| 28 | + |
| 29 | +The top-level [Makefile](../Makefile) is the entry point for various |
| 30 | +build commands. Few utilities are required during the build process, |
| 31 | +either for bootstrapping the project, building it or checking the |
| 32 | +validity of the source code itself. If not present in your `$PATH`, |
| 33 | +those tools may be installed locally to the project (under the |
| 34 | +local `.bin` directory) using: |
| 35 | + |
| 36 | +```sh |
| 37 | + $ make build-tools |
| 38 | + ... |
| 39 | + $ ls .bin/ |
| 40 | +``` |
| 41 | + |
| 42 | +## Build |
| 43 | + |
| 44 | +The following section describes how to build and test samba-operator. |
| 45 | +A more detailed description of this process may be found in the |
| 46 | +[developer-notes](./developer-notes.md) document. |
| 47 | + |
| 48 | +Building the samba-operator is a straightforward action with |
| 49 | +`make build`. Upon successful build, the output binary is written to |
| 50 | +`bin/manager`: |
| 51 | + |
| 52 | +```sh |
| 53 | + $ make build |
| 54 | + ... |
| 55 | + $ ls bin/ |
| 56 | + manager |
| 57 | +``` |
| 58 | + |
| 59 | +Note that the manager binary alone is not typically executed in a |
| 60 | +Kubernetes cluster. For that we generally build a container image. To |
| 61 | +build an OCI container image including the manager binary, run: |
| 62 | + |
| 63 | +```sh |
| 64 | + $ make image-build |
| 65 | +``` |
| 66 | + |
| 67 | +The name of this image is controlled by the `IMG` and `TAG` variables |
| 68 | +and may be customized to fit your needs. A developer may override those |
| 69 | +as well as some other default Makefile settings via the `devel.mk` file |
| 70 | +at the project's root directory: |
| 71 | + |
| 72 | +```sh |
| 73 | + $ cp devel.mk.sample devel.mk |
| 74 | + $ vim devel.mk |
| 75 | +``` |
| 76 | + |
| 77 | +## Check |
| 78 | + |
| 79 | +Before submitting any pull request, a developer must ensure that |
| 80 | +his code satisfies the following minimum requirements: |
| 81 | + |
| 82 | +1. Go code conforms to the project's standards. |
| 83 | +2. YAML files conform to the project's standards. |
| 84 | +3. Unit-tests pass without errors. |
| 85 | + |
| 86 | +Use the following commands to check and test your code: |
| 87 | + |
| 88 | +```sh |
| 89 | + $ make check |
| 90 | + $ make test |
| 91 | +``` |
| 92 | + |
| 93 | +If any of those make rules fail they should first be fixed before any |
| 94 | +other developer will review your patches. Please note that those steps |
| 95 | +are integrated into the project's CI workflow, and therefore must pass |
| 96 | +successfully. |
| 97 | + |
| 98 | +## Testing |
| 99 | + |
| 100 | +Ideally, before submitting any pull request, a developer should test |
| 101 | +any code changes locally. Local clusters are simpler to debug and, if |
| 102 | +one has not had code merged to the project before, it does not require |
| 103 | +approval from the project maintainers. A prerequisite to running the |
| 104 | +samba-operator test suite is a running Kubernetes cluster. Typically |
| 105 | +this will be [minikube](https://minikube.sigs.k8s.io) but other |
| 106 | +Kubernetes implementations can suffice. |
| 107 | + |
| 108 | +An example using minikube with a private container image follows: |
| 109 | + |
| 110 | +```sh |
| 111 | + $ export IMG=quay.io/my-quay-username/samba-operator:latest |
| 112 | + $ echo IMG=${IMG} >> devel.mk |
| 113 | + $ make image-build |
| 114 | + $ make container-push |
| 115 | + ... |
| 116 | + $ minikube start \ |
| 117 | + --driver=kvm2 \ |
| 118 | + --bootstrapper kubeadm \ |
| 119 | + --disk-size 32g \ |
| 120 | + --memory 8192 \ |
| 121 | + --cpus 2 \ |
| 122 | + --insecure-registry "10.0.0.0/24" \ |
| 123 | + --nodes=3 -\ |
| 124 | + --extra-disks=2 \ |
| 125 | + --feature-gates=EphemeralContainers=true |
| 126 | + ... |
| 127 | + $ # Ensure cluster has basic functionality: |
| 128 | + $ kubectl get nodes |
| 129 | + $ kubectl get pods -A |
| 130 | + ... |
| 131 | + $ # Deploy your image: |
| 132 | + $ make deploy |
| 133 | + $ kubectl get pods -n samba-operator-system |
| 134 | + ... |
| 135 | + $ # Start an AD DC inside k8s to support domain logins in test suite |
| 136 | + $ ./tests/test-deploy-ad-server.sh |
| 137 | + $ # Run the test-suite |
| 138 | + $ ./tests/test.sh |
| 139 | + ... |
| 140 | + $ # in case of failure: |
| 141 | + $ ./tests/post-test-info.sh |
| 142 | + ... |
| 143 | + $ make undeploy |
| 144 | +``` |
| 145 | + |
| 146 | +## Pull-request |
| 147 | +Finally, you may submit your changes via samba-operator github |
| 148 | +[pull-request](https://github.com/samba-in-kubernetes/samba-operator/pulls). |
| 149 | +Before submitting a pull request, make sure that you provided a valid |
| 150 | +git commit message, which allows other developers to easily review your |
| 151 | +code. In particular, ensure that each git commit include the |
| 152 | +followings: |
| 153 | + |
| 154 | +1. A short topic line (up to 72 characters) with the name of the |
| 155 | +sub-component this commit refers to. |
| 156 | + |
| 157 | +2. A commit-message body which explain why and how this change is |
| 158 | +needed, in a clear and informative manner. |
| 159 | + |
| 160 | +3. The author details, including a valid e-mail address and a |
| 161 | +*Signed-off-by* entry. |
| 162 | + |
| 163 | +Validate your commits with [gitlint](https://jorisroovers.com/gitlint/). |
| 164 | +Even better, you may use the following make rule: |
| 165 | +```sh |
| 166 | + $ make check-gitlint |
| 167 | +``` |
| 168 | + |
| 169 | +## License |
| 170 | + |
| 171 | +Samba-operator is an open-source project, developed under the |
| 172 | +[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0) license. We |
| 173 | +appreciate any contribution which helps us improve this code base. |
| 174 | + |
0 commit comments