Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make service port-name configurable in monitor #1521

Merged
merged 19 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions charts/tidb-cluster/templates/monitor-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ metadata:
{{- end }}
spec:
ports:
- name: grafana
- name: {{ .Values.monitor.grafana.service.portName }}
port: 3000
protocol: TCP
targetPort: 3000
Expand All @@ -40,7 +40,7 @@ metadata:
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
spec:
ports:
- name: reloader
- name: {{ .Values.monitor.reloader.service.portName }}
port: 9089
protocol: TCP
targetPort: 9089
Expand All @@ -63,7 +63,7 @@ metadata:
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
spec:
ports:
- name: prometheus
- name: {{ .Values.monitor.prometheus.service.portName }}
port: 9090
protocol: TCP
targetPort: 9090
Expand Down
3 changes: 3 additions & 0 deletions charts/tidb-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ monitor:
imagePullPolicy: IfNotPresent
service:
type: NodePort
portName: tcp-reloader
resources: {}
# limits:
# cpu: 50m
Expand Down Expand Up @@ -505,6 +506,7 @@ monitor:
# GF_SERVER_ROOT_URL: "%(protocol)s://%(domain)s/grafana/"
service:
type: NodePort
portName: http-grafana
prometheus:
image: prom/prometheus:v2.11.1
imagePullPolicy: IfNotPresent
Expand All @@ -518,6 +520,7 @@ monitor:
# memory: 4Gi
service:
type: NodePort
portName: http-prometheus
reserveDays: 12
# alertmanagerURL: ""
nodeSelector: {}
Expand Down
3 changes: 3 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,9 @@ spec:
description: 'LoadBalancerIP is the loadBalancerIP of service
Optional: Defaults to omitted'
type: string
portName:
description: PortName is the name of service port
type: string
type:
description: Type of the real kubernetes service
type: string
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/pingcap/v1alpha1/openapi_generated.go

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

6 changes: 4 additions & 2 deletions pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ type TidbClusterList struct {
// +k8s:openapi-gen=true
// TidbClusterSpec describes the attributes that a user creates on a tidb cluster
type TidbClusterSpec struct {

// PD cluster spec
PD PDSpec `json:"pd"`

Expand Down Expand Up @@ -393,7 +392,6 @@ type TiDBSlowLogTailerSpec struct {
// +k8s:openapi-gen=true
// ComponentSpec is the base spec of each component, the fields should always accessed by the Basic<Component>Spec() method to respect the cluster-level properties
type ComponentSpec struct {

// Image of the component, override baseImage and version if present
// Deprecated
// +k8s:openapi-gen=false
Expand Down Expand Up @@ -471,6 +469,10 @@ type ServiceSpec struct {
// ClusterIP is the clusterIP of service
// +optional
ClusterIP *string `json:"clusterIP,omitempty"`

// PortName is the name of service port
// +optional
PortName *string `json:"portName,omitempty"`
}

// +k8s:openapi-gen=true
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/pingcap/v1alpha1/zz_generated.deepcopy.go

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

34 changes: 31 additions & 3 deletions pkg/monitor/monitor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func getMonitorService(monitor *v1alpha1.TidbMonitor) []*core.Service {
Spec: core.ServiceSpec{
Ports: []core.ServicePort{
{
Name: "prometheus",
Name: "http-prometheus",
Port: 9090,
Protocol: core.ProtocolTCP,
TargetPort: intstr.FromInt(9090),
Expand All @@ -670,7 +670,7 @@ func getMonitorService(monitor *v1alpha1.TidbMonitor) []*core.Service {
Spec: core.ServiceSpec{
Ports: []core.ServicePort{
{
Name: "reloader",
Name: "tcp-reloader",
Port: 9089,
Protocol: core.ProtocolTCP,
TargetPort: intstr.FromInt(9089),
Expand All @@ -683,6 +683,25 @@ func getMonitorService(monitor *v1alpha1.TidbMonitor) []*core.Service {
},
},
}
if monitor.Spec.Prometheus.Service.PortName != nil {
for id, port := range prometheusService.Spec.Ports {
if port.Name == "http-prometheus" {
port.Name = *monitor.Spec.Prometheus.Service.PortName
prometheusService.Spec.Ports[id] = port
break
}
}
}
if monitor.Spec.Reloader.Service.PortName != nil {
for id, port := range reloaderService.Spec.Ports {
if port.Name == "tcp-reloader" {
port.Name = *monitor.Spec.Reloader.Service.PortName
reloaderService.Spec.Ports[id] = port
break
}
}
}

services = append(services, prometheusService, reloaderService)
if monitor.Spec.Grafana != nil {
grafanaService := &core.Service{
Expand All @@ -696,7 +715,7 @@ func getMonitorService(monitor *v1alpha1.TidbMonitor) []*core.Service {
Spec: core.ServiceSpec{
Ports: []core.ServicePort{
{
Name: "grafana",
Name: "http-grafana",
Port: 3000,
Protocol: core.ProtocolTCP,
TargetPort: intstr.FromInt(3000),
Expand All @@ -709,6 +728,15 @@ func getMonitorService(monitor *v1alpha1.TidbMonitor) []*core.Service {
},
},
}
if monitor.Spec.Grafana.Service.PortName != nil {
for id, port := range grafanaService.Spec.Ports {
if port.Name == "http-grafana" {
port.Name = *monitor.Spec.Grafana.Service.PortName
grafanaService.Spec.Ports[id] = port
break
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant, why not use the desired port name at the first place?

grafanaPortName := "http-grafana"
if monitor.Spec.Grafana.Service.PortName != nil {
  grafanaPortName := *monitor.Spec.Grafana.Service.PortName
}
...
Name:      grafanaPortName,
...

services = append(services, grafanaService)
}
return services
Expand Down