diff --git a/stable/yugabyte/templates/_helpers.tpl b/stable/yugabyte/templates/_helpers.tpl index 8cee2f439d..82f2d0bea9 100644 --- a/stable/yugabyte/templates/_helpers.tpl +++ b/stable/yugabyte/templates/_helpers.tpl @@ -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. */}} diff --git a/stable/yugabyte/templates/service-endpoints.yaml b/stable/yugabyte/templates/service-endpoints.yaml new file mode 100644 index 0000000000..4c1f79e85e --- /dev/null +++ b/stable/yugabyte/templates/service-endpoints.yaml @@ -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 }} \ No newline at end of file diff --git a/stable/yugabyte/templates/service.yaml b/stable/yugabyte/templates/service.yaml index e9781c9b68..5925d61436 100644 --- a/stable/yugabyte/templates/service.yaml +++ b/stable/yugabyte/templates/service.yaml @@ -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 diff --git a/stable/yugabyte/values.yaml b/stable/yugabyte/values.yaml index 64d7c47d90..29f6f92705 100644 --- a/stable/yugabyte/values.yaml +++ b/stable/yugabyte/values.yaml @@ -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