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

Branch awareness v2 #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
46 changes: 33 additions & 13 deletions .ci/update_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,36 @@ function version_gt() {
test "$(echo -e "$1\n$2" | sort -V | head -n 1)" != "$1"
}


if [[ $# -ne 1 ]]; then
echo "No arguments supplied. Please provide the release version" 1>&2
echo "Terminating the script execution." 1>&2
exit 1
fi

release_version="$1"

current_stable=2.3

# We have multiple parallel release trains.
# Each train is described by its <major>.<minor> number
# We use this release train name as the parent directory for the corresponding helm charts
a=( ${release_version//./ } )
yb_release="${a[0]}.${a[1]}"

# If the yb_release is the latest (currently 2.3), use the keyword 'stable' instead
if [[ "${yb_release}" == "${current_stable}" ]]; then
yb_release='stable'
fi

# If our yb_release dir doesn't exist, copy it from the template at .template
if [[ ! -d "${yb_release}" ]]; then
echo "First release for ${yb_release}!"
echo "Creating new release directory"
cp -r .template "${yb_release}"
fi

# appVersion mentioned in Charts.yaml
current_version="$(grep -r "^appVersion" "stable/yugabyte/Chart.yaml" | awk '{ print $2 }')"
current_version="$(grep -r "^appVersion" "${yb_release}/yugabyte/Chart.yaml" | awk '{ print $2 }')"
if ! version_gt "${release_version}" "${current_version%-b*}" ; then
echo "Release version is either older or equal to the current version: '${release_version}' <= '${current_version%-b*}'" 1>&2
exit 1
Expand All @@ -35,14 +55,14 @@ else
fi

# Following parameters will be updated in the below-mentioned files:
# 1. ./stable/yugabyte/Chart.yaml - version, appVersion
# 2. ./stable/yugabyte/values.yaml - tag
# 3. ./stable/yugaware/Chart.yaml - version, appVersion
# 4. ./stable/yugaware/values.yaml - tag
# 5. ./stable/yugabyte/app-readme.md - *.*.*.*-b*

files_to_update_version=("stable/yugabyte/Chart.yaml" "stable/yugaware/Chart.yaml")
files_to_update_tag=("stable/yugabyte/values.yaml" "stable/yugaware/values.yaml")
# 1. ./${yb_release}/yugabyte/Chart.yaml - version, appVersion
# 2. ./${yb_release}/yugabyte/values.yaml - tag
# 3. ./${yb_release}/yugaware/Chart.yaml - version, appVersion
# 4. ./${yb_release}/yugaware/values.yaml - tag
# 5. ./${yb_release}/yugabyte/app-readme.md - *.*.*.*-b*

files_to_update_version=("${yb_release}/yugabyte/Chart.yaml" "${yb_release}/yugaware/Chart.yaml")
files_to_update_tag=("${yb_release}/yugabyte/values.yaml" "${yb_release}/yugaware/values.yaml")
chart_release_version="$(echo "${release_version}" | grep -o '[0-9]\+.[0-9]\+.[0-9]\+')"

# Update appVersion and version in Chart.yaml
Expand All @@ -58,6 +78,6 @@ for file in "${files_to_update_tag[@]}"; do
sed -i "s/^ tag: .*/ tag: ${docker_image_tag}/g" "${file}"
done

# Update version number in stable/yugabyte/app-readme.md
echo "Updating file: 'stable/yugabyte/app-readme.md' with version: '${docker_image_tag}'"
sed -i "s/[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+-b[0-9]\+/${docker_image_tag}/g" "stable/yugabyte/app-readme.md"
# Update version number in ${yb_release}/yugabyte/app-readme.md
echo "Updating file: '${yb_release}/yugabyte/app-readme.md' with version: '${docker_image_tag}'"
sed -i "s/[0-9]\+.[0-9]\+.[0-9]\+.[0-9]\+-b[0-9]\+/${docker_image_tag}/g" "${yb_release}/yugabyte/app-readme.md"
3 changes: 1 addition & 2 deletions .github/workflows/update-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ jobs:
run: |
git status
git diff
git add ./stable/yugabyte/Chart.yaml ./stable/yugaware/Chart.yaml \
./stable/yugabyte/values.yaml ./stable/yugaware/values.yaml ./stable/yugabyte/app-readme.md
git add .
git commit -m "Update the version to ${{steps.extract-version.outputs.yb_version}}"
git push origin ${{ github.ref }}
- name: "Show git status in case of failure"
Expand Down
14 changes: 14 additions & 0 deletions .template/yugabyte/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
name: yugabyte
version: 0.0.0
appVersion: 0.0.0.0-b0
home: https://www.yugabyte.com
description: YugabyteDB is the high-performance distributed SQL database for building global, internet-scale apps.
icon: https://avatars0.githubusercontent.com/u/17074854?s=200&v=4
sources:
- https://github.com/yugabyte/yugabyte-db
maintainers:
- name: Ram Sri
email: [email protected]
- name: Arnav Agarwal
email: [email protected]
1 change: 1 addition & 0 deletions .template/yugabyte/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
YugabyteDB can be deployed in various Kubernetes configurations (including single zone, multi-zone and multi-cluster) using this Helm Chart. Detailed documentation is available in [YugabyteDB Docs for Kubernetes Deployments](https://docs.yugabyte.com/latest/deploy/kubernetes/).
1 change: 1 addition & 0 deletions .template/yugabyte/app-readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This chart bootstraps an RF3 Yugabyte DB version 2.3.1.0-b15 cluster using the Helm Package Manager.
14 changes: 14 additions & 0 deletions .template/yugabyte/expose-all-shared.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
serviceEndpoints:
- name: "yb-master-service"
type: LoadBalancer
app: "yb-master"
ports:
ui: "7000"

- name: "yb-tserver-service"
type: LoadBalancer
app: "yb-tserver"
ports:
yql-port: "9042"
yedis-port: "6379"
ysql-port: "5433"
24 changes: 24 additions & 0 deletions .template/yugabyte/expose-all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
serviceEndpoints:
- name: "yb-master-ui"
type: LoadBalancer
app: "yb-master"
ports:
ui: "7000"

- name: "yql-service"
type: LoadBalancer
app: "yb-tserver"
ports:
yql-port: "9042"

- name: "yedis-service"
type: LoadBalancer
app: "yb-tserver"
ports:
yedis-port: "6379"

- name: "ysql-service"
type: LoadBalancer
app: "yb-tserver"
ports:
ysql-port: "5433"
82 changes: 82 additions & 0 deletions .template/yugabyte/generate_kubeconfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/python
# Copyright (c) YugaByte, Inc.

# This script would generate a kubeconfig for the given servie account
# by fetching the cluster information and also add the service account
# token for the authentication purpose.

import argparse
from subprocess import check_output
import json
import base64
import tempfile


def run_command(command_args, namespace=None, as_json=True):
command = ['kubectl']
if namespace:
command.extend(['--namespace', namespace])
command.extend(command_args)
if as_json:
command.extend(['-o', 'json'])
return json.loads(check_output(command))
else:
return check_output(command).decode('utf8')


parser = argparse.ArgumentParser(description='Generate KubeConfig with Token')
parser.add_argument('-s', '--service_account', help='Service Account name', required=True)
parser.add_argument('-n', '--namespace', help='Kubernetes namespace', default='kube-system')
parser.add_argument('-c', '--context', help='kubectl context')
args = vars(parser.parse_args())

# if the context is not provided we use the current-context
context = args['context']
if context is None:
context = run_command(['config', 'current-context'],
args['namespace'], as_json=False)

cluster_attrs = run_command(['config', 'get-contexts', context.strip(),
'--no-headers'], args['namespace'], as_json=False)

cluster_name = cluster_attrs.strip().split()[2]
endpoint = run_command(['config', 'view', '-o',
'jsonpath="{.clusters[?(@.name =="' +
cluster_name + '")].cluster.server}"'],
args['namespace'], as_json=False)
service_account_info = run_command(['get', 'sa', args['service_account']],
args['namespace'])
sa_secret = service_account_info['secrets'][0]['name']
secret_data = run_command(['get', 'secret', sa_secret], args['namespace'])
context_name = '{}-{}'.format(args['service_account'], cluster_name)
kube_config = '/tmp/{}.conf'.format(args['service_account'])

with tempfile.NamedTemporaryFile() as ca_crt_file:
ca_crt = base64.b64decode(secret_data['data']['ca.crt'])
ca_crt_file.write(ca_crt)
ca_crt_file.flush()
# create kubeconfig entry
set_cluster_cmd = ['config', 'set-cluster', cluster_name,
'--kubeconfig={}'.format(kube_config),
'--server={}'.format(endpoint.strip('"')),
'--embed-certs=true',
'--certificate-authority={}'.format(ca_crt_file.name)]
run_command(set_cluster_cmd, as_json=False)

user_token = base64.b64decode(secret_data['data']['token']).decode('utf-8')
set_credentials_cmd = ['config', 'set-credentials', context_name,
'--token={}'.format(user_token),
'--kubeconfig={}'.format(kube_config)]
run_command(set_credentials_cmd, as_json=False)

set_context_cmd = ['config', 'set-context', context_name,
'--cluster={}'.format(cluster_name),
'--user={}'.format(context_name),
'--kubeconfig={}'.format(kube_config)]
run_command(set_context_cmd, as_json=False)

use_context_cmd = ['config', 'use-context', context_name,
'--kubeconfig={}'.format(kube_config)]
run_command(use_context_cmd, as_json=False)

print("Generated the kubeconfig file: {}".format(kube_config))
64 changes: 64 additions & 0 deletions .template/yugabyte/questions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
questions:
- variable: persistence.enabled
default: "false"
description: "Enable persistent volume for YugabyteDB"
type: boolean
required: true
label: Yugabyte Persistent Volume Enabled
show_subquestion_if: true
group: "YugabyteDB Settings"
subquestions:
- variable: persistence.size
default: "40Gi"
description: "YugabyteDB Persistent Volume Size"
type: string
label: YugabyteDB Volume Size
- variable: persistence.storageClass
default: ""
description: "If undefined or null, uses the default StorageClass. Default to null"
type: storageclass
label: Default StorageClass for YugabyteDB
- variable: replicas.tserver
default: "3"
description: "Number of replicas for default replication"
type: string
required: true
label: Replication Factor
- variable: resource.tserver.requests.cpu
default: "8"
description: "Tserver vcpu allocation for YugabyteDB"
type: string
required: true
label: vcpu allocation for tserver
- variable: resource.tserver.requests.memory
default: "15Gi"
description: "Tserver RAM allocation for YugabyteDB"
type: string
required: true
label: RAM allocation for tserver
- variable: disable.ysql
default: "false"
description: "Disable YSQL API"
type: boolean
required: true
label: Disable YSQL API
- variable: serviceEndpoints.name
default: "ysql-service"
description: "Loadbalancer for YSQL API"
type: boolean
required: true
label: Create YSQL API Loadbalancer
- variable: gflags.tserver.use_cassandra_authentication
default: "true"
description: "Enable CQL API"
type: boolean
required: true
label: Enable CQL API
- variable: serviceEndpoints.name
default: "yql-service"
description: "Loadbalancer for CQL API"
type: boolean
required: true
label: Create CQL API Loadbalancer


25 changes: 25 additions & 0 deletions .template/yugabyte/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
1. Get YugabyteDB Pods by running this command:
kubectl --namespace {{ .Release.Namespace }} get pods

2. Get list of YugabyteDB services that are running:
kubectl --namespace {{ .Release.Namespace }} get services

3. Get information about the load balancer services:
kubectl get svc --namespace {{ .Release.Namespace }}

4. Connect to one of the tablet server:
kubectl exec --namespace {{ .Release.Namespace }} -it yb-tserver-0 bash

5. Run YSQL shell from inside of a tablet server:
kubectl exec --namespace {{ .Release.Namespace }} -it yb-tserver-0 -- /home/yugabyte/bin/ysqlsh -h yb-tserver-0.yb-tservers.{{ .Release.Namespace }}

6. Cleanup YugabyteDB Pods
For helm 2:
helm delete {{ .Release.Name }} --purge
For helm 3:
helm delete {{ .Release.Name }} -n {{ .Release.Namespace }}
NOTE: You need to manually delete the persistent volume
{{- $root := . -}}
{{- range .Values.Services }}
kubectl delete pvc --namespace {{ $root.Release.Namespace }} -l app={{.label}}
{{- end }}
69 changes: 69 additions & 0 deletions .template/yugabyte/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "yugabyte.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app 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 "yugabyte.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Derive the memory hard limit for each POD based on the memory limit.
Since the memory is represented in <x>GBi, we use this function to convert that into bytes.
Multiplied by 870 since 0.85 * 1024 ~ 870 (floating calculations not supported)
*/}}
{{- define "yugabyte.memory_hard_limit" -}}
{{- printf "%d" .limits.memory | regexFind "\\d+" | mul 1024 | mul 1024 | mul 870 }}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "yugabyte.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Get YugaByte fs data directories
*/}}
{{- define "yugabyte.fs_data_dirs" -}}
{{range $index := until (int (.count))}}{{if ne $index 0}},{{end}}/mnt/disk{{ $index }}{{end}}
{{- end -}}

{{/*
Get YugaByte master addresses
*/}}
{{- define "yugabyte.master_addresses" -}}
{{- $master_replicas := .Values.replicas.master | int -}}
{{- $domain_name := .Values.domainName -}}
{{- range .Values.Services }}
{{- if eq .name "yb-masters" }}
{{range $index := until $master_replicas }}{{if ne $index 0}},{{end}}yb-master-{{ $index }}.yb-masters.$(NAMESPACE).svc.{{ $domain_name }}:7100{{end}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Compute the maximum number of unavailable pods based on the number of master replicas
*/}}
{{- define "yugabyte.max_unavailable_for_quorum" -}}
{{- $master_replicas := .Values.replicas.master | int | mul 100 -}}
{{- $master_replicas := 100 | div (100 | sub (2 | div ($master_replicas | add 100))) -}}
{{- printf "%d" $master_replicas -}}
{{- end -}}
Loading