Skip to content

Commit

Permalink
[PLAT-10592] Helm chart changes for tserver/master global service
Browse files Browse the repository at this point in the history
Summary:
Added namespaced service support for tserver/master.
- When the service `scope` is inferred as `Namespaced` we will only create one service in the namespace instead of having a per-AZ service.
- The Namespaced service resource is created with `helm.sh/resource-policy: keep` so that helm uninstall does not remove it on uninstall. The service delete should to be explicitly handled with `kubectl delete`.
- In case the owner AZ is deleted, the service should be annotated with a helm release with this annotation: `meta.helm.sh/release-name`.
- The service does not have a zone label.

Helm changes:
- `defaultServiceScope` controls the default value of scope if not provided in the service definition itself.
- Scope can be defined per service also, the service definitions support a `scope` parameter.

Helm values:

```
## Default service scope to use if not defined in service endpoint definition.
## Can be "Namespaced"/"AZ"
defaultServiceScope: "AZ"

serviceEndpoints:
  - name: "yb-master-ui"
    type: LoadBalancer
    # Can be AZ/Namespaced
    scope: "AZ"
    annotations: {}
    clusterIP: ""
    ## Sets the Service's externalTrafficPolicy
    externalTrafficPolicy: ""
    app: "yb-master"
    loadBalancerIP: ""
    ports:
      http-ui: "7000"

  - name: "yb-tserver-service"
    type: LoadBalancer
    # Can be AZ/Namespaced
    scope: "AZ"
    annotations: {}
    clusterIP: ""
    ## Sets the Service's externalTrafficPolicy
    externalTrafficPolicy: ""
    app: "yb-tserver"
    loadBalancerIP: ""
    ports:
      tcp-yql-port: "9042"
      tcp-yedis-port: "6379"
      tcp-ysql-port: "5433"
```

Test Plan: Verified Namespaced service comes up uniquely across AZs with correct annotation and labels.

Reviewers: anijhawan, bgandhi

Reviewed By: anijhawan, bgandhi

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D34771
kv83821-yb committed Sep 11, 2024
1 parent 5e6e0ee commit 19be56f
Showing 4 changed files with 189 additions and 47 deletions.
59 changes: 59 additions & 0 deletions stable/yugabyte/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -56,6 +56,65 @@ release: {{ .root.Release.Name | quote }}
{{- end }}
{{- end }}

{{/*
Generate service name.
*/}}
{{- define "yugabyte.servicename" }}
{{- if eq .scope "Namespaced" }}
{{- $prefix := (get (.root.Values.commonLabels | default dict) "app.kubernetes.io/part-of" | default "namespaced") | trunc 43 | trimSuffix "-" }}
{{- if $prefix }}
{{- printf "%s-%s" $prefix .endpoint.name }}
{{- else }}
{{- .endpoint.name }}
{{- end }}
{{- else }}
{{- .root.Values.oldNamingStyle | ternary .endpoint.name (printf "%s-%s" (include "yugabyte.fullname" $.root) .endpoint.name) }}
{{- end }}
{{- end }}

{{/*
Get service scope
*/}}
{{- define "yugabyte.servicescope" }}
{{- if .endpoint.scope }}
{{- .endpoint.scope }}
{{- else }}
{{- .defaultScope }}
{{- end }}
{{- end }}

{{/*
Generate namespaced service selector.
*/}}
{{- define "yugabyte.namespacedserviceselector" }}
app.kubernetes.io/name: "{{ .label }}"
{{- $partof := (get (.root.Values.commonLabels | default dict) "app.kubernetes.io/part-of" | default "")}}
{{- if $partof }}
app.kubernetes.io/part-of: "{{ $partof }}"
{{- end }}
{{- end }}

{{/*
Checks if a service is required to be installed/upgraded
*/}}
{{- define "yugabyte.should_render_service" -}}
{{- if eq .scope "AZ" }}
{{- "true" }}
{{- else }}
{{- $namespacedService := (lookup "v1" "Service" .root.Release.Namespace .serviceName) }}
{{- if not $namespacedService }}
{{- "true" }}
{{- else }}
{{- $ownerRelease := (get $namespacedService.metadata.annotations "meta.helm.sh/release-name") | default "" }}
{{- if eq $ownerRelease .root.Release.Name }}
{{- "true" }}
{{- else }}
{{- "false" }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create secrets in DBNamespace from other namespaces by iterating over envSecrets.
*/}}
87 changes: 87 additions & 0 deletions stable/yugabyte/templates/service-endpoints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{{- $root := . -}}
---
# Services endpoints
{{- if $root.Values.enableLoadBalancer }}
{{- range .Values.Services }}
{{- $service := . -}}
{{- $appLabelArgs := dict "label" .label "root" $root -}}
{{- range $endpoint := $root.Values.serviceEndpoints }}
{{- $serviceScopeArgs := dict "endpoint" $endpoint "defaultScope" $root.Values.defaultServiceScope }}
{{- $scope := include "yugabyte.servicescope" $serviceScopeArgs }}
{{- if eq $service.label $endpoint.app }}
# Only render if new naming style or old naming style + AZ scope
{{- if or (not $root.Values.oldNamingStyle) (eq $scope "AZ") }}
{{- $servicenameargs := dict "root" $root "endpoint" $endpoint "scope" $scope }}
{{- $serviceName := include "yugabyte.servicename" ($servicenameargs) }}
{{- $serviceArgs := dict "endpoint" $endpoint "serviceName" $serviceName "root" $root "scope" $scope }}
{{- $service := include "yugabyte.should_render_service" ($serviceArgs) }}
# Render if:
# 1. Always if scope is AZ
# 2. Namespaced scope: Service does not exist
# 3. Namespaced scope: Service exists and is owned by this release
{{- if eq $service "true" }}
{{- if (or (ne $endpoint.name "yugabyted-ui-service") $root.Values.yugabytedUi.enabled) }}
apiVersion: v1
kind: Service
metadata:
name: {{ $serviceName | quote }}
namespace: "{{ $root.Release.Namespace }}"
annotations:
# Keep resource for namespaced services
{{- if eq $scope "Namespaced" }}
"helm.sh/resource-policy": keep
{{- end }}
{{- if $endpoint.annotations }}
{{ toYaml $endpoint.annotations | nindent 4 }}
{{- end }}
labels:
# scope is "Namespaced" or "AZ"
scope: {{ $scope }}
serviceName: {{ $endpoint.name }}
service-type: "endpoint"
{{- include "yugabyte.applabel" ($appLabelArgs) | indent 4 }}
{{- $labels := include "yugabyte.labels" $root | fromYaml }}
# For Namespaced service, remove zone and release name filter
{{- if eq $scope "Namespaced" }}
{{- $labels = omit $labels "yugabyte.io/zone" "release" }}
{{- end }}
{{- range $key,$value := $labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
{{- if eq $root.Release.Service "Tiller" }}
clusterIP:
{{- else }}
{{- if $endpoint.clusterIP }}
clusterIP: {{ $endpoint.clusterIP }}
{{- end }}
{{- end }}
type: {{ $endpoint.type }}
ports:
{{- range $label, $port := $endpoint.ports }}
- name: {{ $label | quote }}
port: {{ $port }}
{{- end }}
selector:
{{- if eq $endpoint.name "yugabyted-ui-service"}}
yugabytedUi: "true"
{{- else if eq $scope "Namespaced" }}
{{- include "yugabyte.namespacedserviceselector" ($appLabelArgs) | indent 4 }}
{{- else }}
{{- include "yugabyte.appselector" ($appLabelArgs) | indent 4 }}
{{- end }}
externalTrafficPolicy: {{ $endpoint.externalTrafficPolicy | default "Cluster" }}
{{- if $endpoint.loadBalancerIP }}
loadBalancerIP: {{ $endpoint.loadBalancerIP }}
{{- end }}
{{- if eq $endpoint.name "yugabyted-ui-service"}}
sessionAffinity: {{ $endpoint.sessionAffinity }}
{{- end }}
---
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
47 changes: 0 additions & 47 deletions stable/yugabyte/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -113,53 +113,6 @@ spec:
selector:
{{- include "yugabyte.appselector" ($appLabelArgs) | indent 4 }}

{{- if $root.Values.enableLoadBalancer }}
{{- range $endpoint := $root.Values.serviceEndpoints }}
{{- if eq $service.label $endpoint.app }}
{{- if (or (ne $endpoint.name "yugabyted-ui-service") $root.Values.yugabytedUi.enabled) }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ $root.Values.oldNamingStyle | ternary $endpoint.name (printf "%s-%s" (include "yugabyte.fullname" $root) $endpoint.name) | quote }}
annotations:
{{ toYaml $endpoint.annotations | indent 4 }}
labels:
{{- include "yugabyte.applabel" ($appLabelArgs) | indent 4 }}
{{- include "yugabyte.labels" $root | indent 4 }}
service-type: "endpoint"
spec:
{{- if eq $root.Release.Service "Tiller" }}
clusterIP:
{{- else }}
{{- if $endpoint.clusterIP }}
clusterIP: {{ $endpoint.clusterIP }}
{{- end }}
{{- end }}
ports:
{{- range $label, $port := $endpoint.ports }}
- name: {{ $label | quote }}
port: {{ $port }}
{{- end}}
selector:
{{- if eq $endpoint.name "yugabyted-ui-service"}}
yugabytedUi: "true"
{{- else }}
{{- include "yugabyte.appselector" ($appLabelArgs) | indent 4 }}
{{- end }}
type: {{ $endpoint.type }}
externalTrafficPolicy: {{ $endpoint.externalTrafficPolicy | default "Cluster" }}
{{- if $endpoint.loadBalancerIP }}
loadBalancerIP: {{ $endpoint.loadBalancerIP }}
{{- end }}
{{- if eq $endpoint.name "yugabyted-ui-service"}}
sessionAffinity: {{ $endpoint.sessionAffinity }}
{{- end }}
{{- end}}
{{- end}}
{{- end}}
{{- end}}

---
apiVersion: apps/v1
kind: StatefulSet
43 changes: 43 additions & 0 deletions stable/yugabyte/values.yaml
Original file line number Diff line number Diff line change
@@ -172,9 +172,48 @@ ybCleanup: {}

domainName: "cluster.local"

# ## Enable global service endpoints for tserver/master services across
# ## zones. Requires common label "app.kubernetes.io/part-of" on resources.
# globalServiceEndpoints:
# tserverGlobalService:
# enabled: false
# # Will use LoadBalancer only if 'enableLoadBalancer' is true.
# # Otherwise, ClusterIP service is created.
# type: LoadBalancer
# annotations: {}
# ## Sets the Service's externalTrafficPolicy
# externalTrafficPolicy: ""
# app: "yb-tserver"
# loadBalancerIP: ""
# name: "tserver-global-service"
# ports:
# tcp-yql-port: "9042"
# tcp-yedis-port: "6379"
# tcp-ysql-port: "5433"

# masterGlobalService:
# enabled: false
# # Will use LoadBalancer only if 'enableLoadBalancer' is true.
# # Otherwise, ClusterIP service is created.
# type: LoadBalancer
# annotations: {}
# ## Sets the Service's externalTrafficPolicy
# externalTrafficPolicy: ""
# app: "yb-master"
# loadBalancerIP: ""
# name: "master-global-service"
# ports:
# http-ui: "7000"

## Default service scope to use if not defined in service endpoint definition.
## Can be "Namespaced"/"AZ"
defaultServiceScope: "AZ"

serviceEndpoints:
- name: "yb-master-ui"
type: LoadBalancer
# Can be AZ/Namespaced
scope: "AZ"
annotations: {}
clusterIP: ""
## Sets the Service's externalTrafficPolicy
@@ -186,6 +225,8 @@ serviceEndpoints:

- name: "yb-tserver-service"
type: LoadBalancer
# Can be AZ/Namespaced
scope: "AZ"
annotations: {}
clusterIP: ""
## Sets the Service's externalTrafficPolicy
@@ -199,6 +240,8 @@ serviceEndpoints:

- name: "yugabyted-ui-service"
type: LoadBalancer
# Can be AZ/Namespaced
scope: "AZ"
annotations: {}
clusterIP: ""
## Sets the Service's externalTrafficPolicy

0 comments on commit 19be56f

Please sign in to comment.