Skip to content

Commit

Permalink
chore: change svc template to pointer
Browse files Browse the repository at this point in the history
Signed-off-by: Rory Z <[email protected]>
  • Loading branch information
Rory-Z committed Aug 17, 2023
1 parent e7baafd commit ef84e86
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
12 changes: 6 additions & 6 deletions apis/apps/v2beta1/emqx_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,18 @@ type EMQXSpec struct {
//+kubebuilder:default={type:Recreate,initialDelaySeconds:10,evacuationStrategy:{waitTakeover:10,connEvictRate:1000,sessEvictRate:1000}}
UpdateStrategy UpdateStrategy `json:"updateStrategy,omitempty"`

DashboardServiceTemplate corev1.Service `json:"dashboardServiceTemplate,omitempty"`
// ListenersServiceTemplate is the object that describes the EMQX listener service that will be created
// If the EMQX replicant node exist, this service will selector the EMQX replicant node
// Else this service will selector EMQX core node
ListenersServiceTemplate corev1.Service `json:"listenersServiceTemplate,omitempty"`

// CoreTemplate is the object that describes the EMQX core node that will be created
CoreTemplate EMQXCoreTemplate `json:"coreTemplate,omitempty"`
// ReplicantTemplate is the object that describes the EMQX replicant node that will be created
ReplicantTemplate *EMQXReplicantTemplate `json:"replicantTemplate,omitempty"`

// DashboardServiceTemplate is the object that describes the EMQX dashboard service that will be created
// This service always selector the EMQX core node
DashboardServiceTemplate *corev1.Service `json:"dashboardServiceTemplate,omitempty"`
// ListenersServiceTemplate is the object that describes the EMQX listener service that will be created
// If the EMQX replicant node exist, this service will selector the EMQX replicant node
// Else this service will selector EMQX core node
ListenersServiceTemplate *corev1.Service `json:"listenersServiceTemplate,omitempty"`
}

type BootstrapAPIKey struct {
Expand Down
12 changes: 10 additions & 2 deletions apis/apps/v2beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions controllers/apps/v2beta1/add_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func generateDashboardService(instance *appsv2beta1.EMQX, configStr string) *cor
}

svc := instance.Spec.DashboardServiceTemplate.DeepCopy()
if svc == nil {
svc = &corev1.Service{}
}
svc.Spec.Ports = appsv2beta1.MergeServicePorts(
svc.Spec.Ports,
[]corev1.ServicePort{
Expand Down Expand Up @@ -139,6 +142,10 @@ func generateListenerService(instance *appsv2beta1.EMQX, configStr string) *core
}

svc := instance.Spec.ListenersServiceTemplate.DeepCopy()
if svc == nil {
svc = &corev1.Service{}
}

svc.Spec.Ports = appsv2beta1.MergeServicePorts(
svc.Spec.Ports,
ports,
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/v2beta1/add_svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestGenerateDashboardService(t *testing.T) {
Labels: appsv2beta1.DefaultCoreLabels(emqx),
},
},
DashboardServiceTemplate: corev1.Service{
DashboardServiceTemplate: &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "emqx-dashboard",
Labels: map[string]string{
Expand Down
4 changes: 2 additions & 2 deletions docs/en_US/reference/v2beta1-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ _Appears in:_
| `config` _[Config](#config)_ | EMQX config |
| `clusterDomain` _string_ | |
| `updateStrategy` _[UpdateStrategy](#updatestrategy)_ | UpdateStrategy is the object that describes the EMQX blue-green update strategy |
| `dashboardServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | |
| `listenersServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | ListenersServiceTemplate is the object that describes the EMQX listener service that will be created If the EMQX replicant node exist, this service will selector the EMQX replicant node Else this service will selector EMQX core node |
| `coreTemplate` _[EMQXCoreTemplate](#emqxcoretemplate)_ | CoreTemplate is the object that describes the EMQX core node that will be created |
| `replicantTemplate` _[EMQXReplicantTemplate](#emqxreplicanttemplate)_ | ReplicantTemplate is the object that describes the EMQX replicant node that will be created |
| `dashboardServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | DashboardServiceTemplate is the object that describes the EMQX dashboard service that will be created This service always selector the EMQX core node |
| `listenersServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | ListenersServiceTemplate is the object that describes the EMQX listener service that will be created If the EMQX replicant node exist, this service will selector the EMQX replicant node Else this service will selector EMQX core node |


#### EMQXStatus
Expand Down
4 changes: 2 additions & 2 deletions docs/zh_CN/reference/v2beta1-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ _Appears in:_
| `config` _[Config](#config)_ | EMQX config |
| `clusterDomain` _string_ | |
| `updateStrategy` _[UpdateStrategy](#updatestrategy)_ | UpdateStrategy is the object that describes the EMQX blue-green update strategy |
| `dashboardServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | |
| `listenersServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | ListenersServiceTemplate is the object that describes the EMQX listener service that will be created If the EMQX replicant node exist, this service will selector the EMQX replicant node Else this service will selector EMQX core node |
| `coreTemplate` _[EMQXCoreTemplate](#emqxcoretemplate)_ | CoreTemplate is the object that describes the EMQX core node that will be created |
| `replicantTemplate` _[EMQXReplicantTemplate](#emqxreplicanttemplate)_ | ReplicantTemplate is the object that describes the EMQX replicant node that will be created |
| `dashboardServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | DashboardServiceTemplate is the object that describes the EMQX dashboard service that will be created This service always selector the EMQX core node |
| `listenersServiceTemplate` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#service-v1-core)_ | ListenersServiceTemplate is the object that describes the EMQX listener service that will be created If the EMQX replicant node exist, this service will selector the EMQX replicant node Else this service will selector EMQX core node |


#### EMQXStatus
Expand Down

0 comments on commit ef84e86

Please sign in to comment.