Skip to content

Commit 7f62a02

Browse files
authored
Merge pull request #1160 from keynslug/feat/EMQX-14821/v2
feat: promote EMQX CRD to v2
2 parents f1c9063 + f0e147d commit 7f62a02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+8888
-1556
lines changed

CONTRIBUTING.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Contributing
2+
3+
You are welcome to submit any bugs, issues and feature requests on this repository.
4+
5+
6+
## Commit Message Guidelines
7+
8+
We have very precise rules over how our git commit messages can be formatted. This leads to **more readable messages** that are easy to follow when looking through the **project history**.
9+
10+
### Commit Message Format
11+
12+
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special format that includes a **type**, a **scope** and a **subject**:
13+
14+
```
15+
<type>(<scope>): <subject>
16+
<BLANK LINE>
17+
<body>
18+
<BLANK LINE>
19+
<footer>
20+
```
21+
22+
The **header** with **type** is mandatory. The **scope** of the header is optional. This repository has no predefined scopes. A custom scope can be used for clarity if desired.
23+
24+
Any line of the commit message cannot be longer 100 characters! This allows the message to be easier to read on GitHub as well as in various git tools.
25+
26+
The footer should contain a [closing reference to an issue](https://help.github.com/articles/closing-issues-via-commit-messages/) if any.
27+
28+
Example 1:
29+
30+
```
31+
feat: add Fuji release compose files
32+
```
33+
34+
```
35+
fix(script): correct run script to use the right ports
36+
37+
Previously device services used wrong port numbers. This commit fixes the port numbers to use the latest port numbers.
38+
39+
Closes: #123, #245, #992
40+
```
41+
42+
### Revert
43+
44+
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
45+
46+
### Type
47+
48+
Must be one of the following:
49+
50+
- **feat**: New feature for the user, not a new feature for build script
51+
- **fix**: Bug fix for the user, not a fix to a build script
52+
- **docs**: Documentation only changes
53+
- **style**: Formatting, missing semi colons, etc; no production code change
54+
- **refactor**: Refactoring production code, eg. renaming a variable
55+
- **chore**: Updating grunt tasks etc; no production code change
56+
- **perf**: A code change that improves performance
57+
- **test**: Adding missing tests, refactoring tests; no production code change
58+
- **build**: Changes that affect the CI/CD pipeline or build system or external dependencies (example scopes: travis, jenkins, makefile)
59+
- **ci**: Changes provided by DevOps for CI purposes.
60+
- **revert**: Reverts a previous commit.
61+
62+
### Scope
63+
64+
There are no predefined scopes for this repository. A custom scope can be provided for clarity.
65+
66+
### Subject
67+
68+
The subject contains a succinct description of the change:
69+
70+
- use the imperative, present tense: "change" not "changed" nor "changes"
71+
- don't capitalize the first letter
72+
- no dot (.) at the end
73+
74+
### Body
75+
76+
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes". The body should include the motivation for the change and contrast this with previous behavior.
77+
78+
### Footer
79+
80+
The footer should contain any information about **Breaking Changes** and is also the place to reference GitHub issues that this commit **Closes**.
81+
82+
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.22 AS builder
2+
FROM golang:1.24 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ help: ## Display this help.
4545

4646
.PHONY: manifests
4747
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
48-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
48+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4949

5050
.PHONY: generate
5151
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -181,9 +181,9 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
181181

182182
## Tool Versions
183183
KUSTOMIZE_VERSION ?= v5.5.0
184-
CONTROLLER_TOOLS_VERSION ?= v0.17.3
184+
CONTROLLER_TOOLS_VERSION ?= v0.18.0
185185
ENVTEST_VERSION ?= release-0.19
186-
GOLANGCI_LINT_VERSION ?= v1.61.0
186+
GOLANGCI_LINT_VERSION ?= v1.64.8
187187

188188
.PHONY: kustomize
189189
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.

PROJECT

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ resources:
1515
domain: emqx.io
1616
group: apps
1717
kind: EMQX
18-
path: github.com/emqx/emqx-operator/api/v2beta1
19-
version: v2beta1
18+
path: github.com/emqx/emqx-operator/api/v2
19+
version: v2
2020
- api:
2121
crdVersion: v1
2222
namespaced: true

README.md

Lines changed: 79 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,81 @@
11
# emqx-operator
2-
// TODO(user): Add simple overview of use/purpose
2+
3+
EMQX Operator is a [Kubernetes](https://kubernetes.io/) operator for managing [EMQX](https://emqx.com/) clusters.
34

45
## Description
5-
// TODO(user): An in-depth paragraph about your project and overview of use
66

7-
## Getting Started
7+
The operator conceptually consists of the following parts:
8+
- EMQX CRD: Definition for a resource that resembles the EMQX cluster in the Kubernetes API.
9+
- Rebalance CRD: Definition for a resource that orchestrates rebalancing of EMQX clusters.
10+
- Controller manager: Kubernetes controller that manages various Kubernetes resources according to EMQX CRs specifications.
11+
12+
This operator supports:
13+
* Management of EMQX clusters in both regular and core-replicant deployment modes.
14+
* Management of [EMQX DS](https://docs.emqx.com/en/emqx/latest/durability/durability_introduction.html#sessions-and-durable-storage) replication, including automatic rebalancing.
15+
* Rebalancing of MQTT sessions and connections across EMQX cluster nodes.
16+
17+
## Compatibility
18+
19+
This operator is compatible with the following EMQX releases:
20+
- EMQX 5.9
21+
- EMQX 5.10
22+
- EMQX 6.x
23+
24+
## Installation
25+
26+
Here's the simplest way to install the operator.
27+
```sh
28+
kubectl apply --server-side=true -f https://github.com/emqx/emqx-operator/releases/download/v2.3.0/install.yaml
29+
kubectl wait --for=condition=Ready pods -l "control-plane=controller-manager" --namespace emqx-operator-system
30+
```
31+
32+
This will install both the CRDs, the controller manager and relevant resources into the cluster. The controller manager will be deployed in the `emqx-operator-system` namespace.
33+
34+
## Upgrading
35+
36+
### From 2.2.x
37+
38+
To upgrade from 2.2.x to 2.3.0, you need to patch the existing CRDs first to explicitly remove the conversion webhook.
39+
```sh
40+
kubectl patch crd emqxes.apps.emqx.io --type=json -p='[{"op":"replace", "path":"/spec/conversion", "value":{"strategy":"None"}}]'
41+
kubectl patch crd rebalances.apps.emqx.io --type=json -p='[{"op":"replace", "path":"/spec/conversion", "value":{"strategy":"None"}}]'
42+
```
43+
44+
After patching the CRDs, delete the existing controller manager deployment.
45+
```sh
46+
kubectl delete --ignore-not-found clusterrole emqx-operator-manager-role
47+
kubectl delete --ignore-not-found clusterrolebinding emqx-operator-manager-rolebinding
48+
kubectl delete --ignore-not-found mutatingwebhookconfiguration emqx-operator-mutating-webhook-configuration
49+
kubectl delete --ignore-not-found validatingwebhookconfiguration emqx-operator-validating-webhook-configuration
50+
kubectl delete --ignore-not-found namespace emqx-operator-system
51+
```
52+
53+
Optionally, delete legacy CRDs.
54+
```sh
55+
kubectl delete --ignore-not-found crd emqxbrokers.apps.emqx.io emqxenterprises.apps.emqx.io emqxplugins.apps.emqx.io
56+
```
57+
58+
After that, you can upgrade the operator by following usual installation steps.
59+
60+
## Troubleshooting
61+
62+
Operator exposes limited number of events to the Kubernetes API.
63+
```sh
64+
kubectl get events --sort-by=.lastTimestamp
65+
```
66+
67+
Alternatively, if EMQX resources fail to reach `Ready` status condition, consult the controller manager logs for more details.
68+
```sh
69+
kubectl logs -l "control-plane=controller-manager" --tail=-1 --namespace emqx-operator-system
70+
```
71+
72+
## Development
873

974
### Prerequisites
1075
- go version v1.22.0+
1176
- docker version 17.03+.
12-
- kubectl version v1.11.3+.
13-
- Access to a Kubernetes v1.11.3+ cluster.
77+
- kubectl version v1.24+.
78+
- Access to a Kubernetes v1.24+ cluster.
1479

1580
### To Deploy on the cluster
1681
**Build and push your image to the location specified by `OPERATOR_IMAGE`:**
@@ -24,77 +89,41 @@ And it is required to have access to pull the image from the working environment
2489
Make sure you have the proper permission to the registry if the above commands don’t work.
2590

2691
**Install the CRDs into the cluster:**
27-
2892
```sh
2993
make install
3094
```
3195

3296
**Deploy the Manager to the cluster with the image specified by `OPERATOR_IMAGE`:**
33-
3497
```sh
3598
make deploy OPERATOR_IMAGE=<some-registry>/emqx-operator:tag
3699
```
37100

38101
> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
39102
privileges or be logged in as admin.
40103

41-
**Create instances of your solution**
42-
You can apply the samples (examples) from the config/sample:
43-
44-
```sh
45-
kubectl apply -k config/samples/
46-
```
47-
48-
>**NOTE**: Ensure that the samples has default values to test it out.
49-
50104
### To Uninstall
51-
**Delete the instances (CRs) from the cluster:**
52-
53-
```sh
54-
kubectl delete -k config/samples/
55-
```
56-
57-
**Delete the APIs(CRDs) from the cluster:**
58-
105+
**Delete the CRDs from the cluster:**
59106
```sh
60107
make uninstall
61108
```
62109

63-
**UnDeploy the controller from the cluster:**
64-
110+
**Undeploy the controller:**
65111
```sh
66112
make undeploy
67113
```
68114

69-
## Project Distribution
70-
71-
Following are the steps to build the installer and distribute this project to users.
72-
73-
1. Build the installer for the image built and published in the registry:
74-
75-
```sh
76-
make build-installer OPERATOR_IMAGE=<some-registry>/emqx-operator:tag
77-
```
78-
79-
NOTE: The makefile target mentioned above generates an 'install.yaml'
80-
file in the dist directory. This file contains all the resources built
81-
with Kustomize, which are necessary to install this project without
82-
its dependencies.
83-
84-
2. Using the installer
115+
## Contributing
85116

86-
Users can just run kubectl apply -f <URL for YAML BUNDLE> to install the project, i.e.:
117+
Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.
87118

119+
Automatically generated files are kept in the repository for reference. Do not forget to update them when you make changes to the project.
88120
```sh
89-
kubectl apply -f https://raw.githubusercontent.com/<org>/emqx-operator/<tag or branch>/dist/install.yaml
121+
make generate manifests
122+
git add config/crd/bases/
123+
git add api/**/zz_generated.deepcopy.go
90124
```
91125

92-
## Contributing
93-
// TODO(user): Add detailed information on how you would like others to contribute to this project
94-
95-
**NOTE:** Run `make help` for more information on all potential `make` targets
96-
97-
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
126+
More information can be found in the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
98127

99128
## License
100129

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,23 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v2beta1
17+
package v2
1818

1919
import corev1 "k8s.io/api/core/v1"
2020

2121
const DefaultContainerName string = "emqx"
2222

23-
const DefaultBootstrapAPIKey string = "emqx-operator-controller"
24-
2523
const (
2624
// labels
27-
LabelsInstanceKey string = "apps.emqx.io/instance" // my-emqx
28-
LabelsManagedByKey string = "apps.emqx.io/managed-by" // emqx-operator
29-
LabelsDBRoleKey string = "apps.emqx.io/db-role" // core, replicant
30-
LabelsPodTemplateHashKey string = "apps.emqx.io/pod-template-hash"
25+
LabelInstance string = "apps.emqx.io/instance" // my-emqx
26+
LabelManagedBy string = "apps.emqx.io/managed-by" // emqx-operator
27+
LabelDBRole string = "apps.emqx.io/db-role" // core, replicant
28+
LabelPodTemplateHash string = "apps.emqx.io/pod-template-hash"
3129
)
3230

3331
const (
3432
// annotations
35-
AnnotationsLastEMQXConfigKey string = "apps.emqx.io/last-emqx-configuration"
33+
AnnotationLastEMQXConfig string = "apps.emqx.io/last-emqx-configuration"
3634
)
3735

3836
const (
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v2beta1
17+
package v2
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v2beta1
17+
package v2
1818

1919
import (
2020
corev1 "k8s.io/api/core/v1"
@@ -316,6 +316,10 @@ type ServiceTemplate struct {
316316
Spec corev1.ServiceSpec `json:"spec,omitempty"`
317317
}
318318

319+
func (spec *EMQXSpec) HasReplicants() bool {
320+
return spec.ReplicantTemplate != nil && spec.ReplicantTemplate.Spec.Replicas != nil && *spec.ReplicantTemplate.Spec.Replicas > 0
321+
}
322+
319323
func (s *ServiceTemplate) IsEnabled() bool {
320324
return s.Enabled != nil && *s.Enabled
321325
}

0 commit comments

Comments
 (0)