From fba95c3bf5ca294e58c8be6f9799b05cf676a688 Mon Sep 17 00:00:00 2001 From: Alexander Babai Date: Thu, 3 May 2018 22:11:51 +0300 Subject: [PATCH] [incubator/cassandra] Standardize labels (#5111) * [incubator/cassandra] standardize labels * use "cassandra.name" as app label instead of "cassandra.fullname" * match pods by two labels, release and app * [incubator/cassandra] update notes * [incubator/cassandra] bump version to 0.2.7 * [incubator/cassandra] bump version to 0.3.0 * bump the minor version --- incubator/cassandra/Chart.yaml | 2 +- incubator/cassandra/templates/NOTES.txt | 8 ++--- incubator/cassandra/templates/_helpers.tpl | 23 +++++++++++--- .../templates/cassandra-statefulset.yaml | 30 ++++++++++--------- 4 files changed, 40 insertions(+), 23 deletions(-) diff --git a/incubator/cassandra/Chart.yaml b/incubator/cassandra/Chart.yaml index 1f83595bb231..7c0552061502 100644 --- a/incubator/cassandra/Chart.yaml +++ b/incubator/cassandra/Chart.yaml @@ -1,5 +1,5 @@ name: cassandra -version: 0.2.6 +version: 0.3.0 appVersion: 3 description: Apache Cassandra is a free and open-source distributed database management system designed to handle large amounts of data across many commodity servers, providing diff --git a/incubator/cassandra/templates/NOTES.txt b/incubator/cassandra/templates/NOTES.txt index 0c9becb542c3..98dddcad955a 100644 --- a/incubator/cassandra/templates/NOTES.txt +++ b/incubator/cassandra/templates/NOTES.txt @@ -2,7 +2,7 @@ Cassandra CQL can be accessed via port {{ .Values.config.ports.cql }} on the fol Cassandra Thrift can be accessed via port {{ .Values.config.ports.thrift }} on the following DNS name from within your cluster: If you want to connect to the remote instance with your local Cassandra CQL cli. To forward the API port to localhost:9042 run the following: -- kubectl port-forward --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l app={{ template "cassandra.fullname" . }} -o jsonpath='{ .items[0].metadata.name }') 9042:{{ .Values.config.ports.cql }} +- kubectl port-forward --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l app={{ template "cassandra.name" . }},release={{ .Release.Name }} -o jsonpath='{ .items[0].metadata.name }') 9042:{{ .Values.config.ports.cql }} If you want to connect to the Cassandra CQL run the following: {{- if contains "NodePort" .Values.service.type }} @@ -16,12 +16,12 @@ If you want to connect to the Cassandra CQL run the following: - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "cassandra.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - echo cqlsh $SERVICE_IP {{- else if contains "ClusterIP" .Values.service.type }} -- kubectl port-forward --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "cassandra.fullname" . }}" -o jsonpath="{.items[0].metadata.name}") 9042:{{ .Values.config.ports.cql }} +- kubectl port-forward --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "cassandra.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") 9042:{{ .Values.config.ports.cql }} echo cqlsh 127.0.0.1 9042 {{- end }} You can also see the cluster status by run the following: -- kubectl exec -it --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l app={{ template "cassandra.fullname" . }} -o jsonpath='{.items[0].metadata.name}') nodetool status +- kubectl exec -it --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l app={{ template "cassandra.name" . }},release={{ .Release.Name }} -o jsonpath='{.items[0].metadata.name}') nodetool status To tail the logs for the Cassandra pod run the following: -- kubectl logs -f --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l app={{ template "cassandra.fullname" . }} -o jsonpath='{ .items[0].metadata.name }') +- kubectl logs -f --namespace {{ .Release.Namespace }} $(kubectl get pods --namespace {{ .Release.Namespace }} -l app={{ template "cassandra.name" . }},release={{ .Release.Name }} -o jsonpath='{ .items[0].metadata.name }') diff --git a/incubator/cassandra/templates/_helpers.tpl b/incubator/cassandra/templates/_helpers.tpl index 986f658521a8..ec8dd16cbd1f 100644 --- a/incubator/cassandra/templates/_helpers.tpl +++ b/incubator/cassandra/templates/_helpers.tpl @@ -3,15 +3,30 @@ Expand the name of the chart. */}} {{- define "cassandra.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} {{- end -}} {{/* Create a default fully qualified app name. -We truncate at 21 chars because Kubernetes name fields are limited to 24 (by the DNS naming spec) -and Statefulset will append -xx at the end of name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. */}} {{- define "cassandra.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} {{- $name := default .Chart.Name .Values.nameOverride -}} -{{- printf "%s-%s" .Release.Name $name | trunc 63 -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "cassandra.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} {{- end -}} diff --git a/incubator/cassandra/templates/cassandra-statefulset.yaml b/incubator/cassandra/templates/cassandra-statefulset.yaml index c5a9307feed8..7ac46ee5c29c 100644 --- a/incubator/cassandra/templates/cassandra-statefulset.yaml +++ b/incubator/cassandra/templates/cassandra-statefulset.yaml @@ -3,10 +3,10 @@ kind: Service metadata: name: {{ template "cassandra.fullname" . }} labels: - app: {{ template "cassandra.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: {{ template "cassandra.name" . }} + chart: {{ template "cassandra.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} spec: clusterIP: None type: {{ .Values.service.type }} @@ -32,17 +32,18 @@ spec: targetPort: {{ .Values.config.ports.agent }} {{- end }} selector: - app: {{ template "cassandra.fullname" . }} + app: {{ template "cassandra.name" . }} + release: {{ .Release.Name }} --- apiVersion: apps/v1beta1 kind: StatefulSet metadata: name: {{ template "cassandra.fullname" . }} labels: - app: {{ template "cassandra.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: {{ template "cassandra.name" . }} + chart: {{ template "cassandra.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} spec: serviceName: {{ template "cassandra.fullname" . }} replicas: {{ .Values.config.cluster_size }} @@ -52,7 +53,8 @@ spec: template: metadata: labels: - app: {{ template "cassandra.fullname" . }} + app: {{ template "cassandra.name" . }} + release: {{ .Release.Name }} {{- if .Values.podLabels }} {{ toYaml .Values.podLabels | indent 8 }} {{- end }} @@ -139,10 +141,10 @@ spec: - metadata: name: data labels: - app: {{ template "cassandra.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + app: {{ template "cassandra.name" . }} + chart: {{ template "cassandra.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} spec: accessModes: - {{ .Values.persistence.accessMode | quote }}