-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4383 from planetscale/ss-minikube
helm: minikube example
- Loading branch information
Showing
8 changed files
with
349 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
topology: | ||
cells: | ||
- name: "zone1" | ||
etcd: | ||
replicas: 1 | ||
vtctld: | ||
replicas: 1 | ||
vtgate: | ||
replicas: 1 | ||
mysqlProtocol: | ||
enabled: true | ||
authType: "none" | ||
keyspaces: | ||
- name: "messagedb" | ||
schema: |- | ||
CREATE TABLE messages ( | ||
page BIGINT(20) UNSIGNED, | ||
time_created_ns BIGINT(20) UNSIGNED, | ||
message VARCHAR(10000), | ||
PRIMARY KEY (page, time_created_ns) | ||
) ENGINE=InnoDB | ||
vschema: |- | ||
{ | ||
"sharded": true, | ||
"vindexes": { | ||
"hash": { | ||
"type": "hash" | ||
} | ||
}, | ||
"tables": { | ||
"messages": { | ||
"column_vindexes": [ | ||
{ | ||
"column": "page", | ||
"name": "hash" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
shards: | ||
- name: "0" | ||
tablets: | ||
- type: "replica" | ||
vttablet: | ||
replicas: 2 | ||
|
||
etcd: | ||
replicas: 1 | ||
resources: | ||
|
||
vtctld: | ||
serviceType: "NodePort" | ||
resources: | ||
|
||
vtgate: | ||
serviceType: "NodePort" | ||
resources: | ||
|
||
vttablet: | ||
resources: | ||
mysqlResources: | ||
|
||
pmm: | ||
enabled: false | ||
client: | ||
resources: | ||
server: | ||
resources: | ||
|
||
orchestrator: | ||
enabled: false | ||
resources: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
################################### | ||
# keyspace initializations | ||
################################### | ||
|
||
{{- define "keyspace" -}} | ||
{{- $cell := index . 0 -}} | ||
{{- $keyspace := index . 1 -}} | ||
{{- $defaultVtctlclient := index . 2 -}} | ||
{{- $namespace := index . 3 -}} | ||
|
||
# sanitize inputs for labels | ||
{{- $keyspaceClean := include "clean-label" $keyspace.name -}} | ||
|
||
{{- with $cell.vtctld -}} | ||
|
||
# define image to use | ||
{{- $vitessTag := .vitessTag | default $defaultVtctlclient.vitessTag -}} | ||
|
||
{{- if $keyspace.schema }} | ||
--- | ||
################################### | ||
# ApplySchema Job | ||
################################### | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: {{ $keyspaceClean }}-apply-schema | ||
spec: | ||
backoffLimit: 1 | ||
template: | ||
spec: | ||
restartPolicy: OnFailure | ||
containers: | ||
- name: apply-schema | ||
image: "vitess/vtctlclient:{{$vitessTag}}" | ||
volumeMounts: | ||
{{ include "user-secret-volumeMounts" $defaultVtctlclient.secrets | indent 10 }} | ||
|
||
command: ["bash"] | ||
args: | ||
- "-c" | ||
- | | ||
set -ex | ||
|
||
VTCTLD_SVC=vtctld.{{ $namespace }}:15999 | ||
SECONDS=0 | ||
TIMEOUT_SECONDS=600 | ||
VTCTL_EXTRA_FLAGS=({{ include "format-flags-inline" $defaultVtctlclient.extraFlags }}) | ||
|
||
# poll every 5 seconds to see if vtctld is ready | ||
until vtctlclient ${VTCTL_EXTRA_FLAGS[@]} -server $VTCTLD_SVC ListAllTablets {{ $cell.name }} > /dev/null 2>&1; do | ||
if (( $SECONDS > $TIMEOUT_SECONDS )); then | ||
echo "timed out waiting for vtctlclient to be ready" | ||
exit 1 | ||
fi | ||
sleep 5 | ||
done | ||
|
||
while true; do | ||
if (( $SECONDS > $TIMEOUT_SECONDS )); then | ||
echo "timed out waiting for master" | ||
exit 1 | ||
fi | ||
|
||
# wait for all shards to have a master | ||
{{- range $shard := $keyspace.shards }} | ||
master_alias=$(vtctlclient ${VTLCTL_EXTRA_FLAGS[@]} -server $VTCTLD_SVC GetShard {{ $keyspace.name }}/{{ $shard.name }} | jq '.master_alias.uid') | ||
if [ "$master_alias" == "null" -o "$master_alias" == "" ]; then | ||
echo "no master for '{{ $keyspace.name }}/{{ $shard.name }}' yet, continuing to wait" | ||
sleep 5 | ||
continue | ||
fi | ||
{{- end }} | ||
|
||
break | ||
done | ||
|
||
vtctlclient ${VTCTL_EXTRA_FLAGS[@]} -server $VTCTLD_SVC ApplySchema -sql "$(cat <<END_OF_COMMAND | ||
{{ $keyspace.schema | indent 14}} | ||
END_OF_COMMAND | ||
)" {{ $keyspace.name }} | ||
volumes: | ||
{{ include "user-secret-volumes" (.secrets | default $defaultVtctlclient.secrets) | indent 8 }} | ||
{{ end }} | ||
{{- if $keyspace.vschema }} | ||
--- | ||
################################### | ||
# ApplyVSchema job | ||
################################### | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: {{ $keyspaceClean }}-apply-vschema | ||
spec: | ||
backoffLimit: 1 | ||
template: | ||
spec: | ||
restartPolicy: OnFailure | ||
containers: | ||
- name: apply-vschema | ||
image: "vitess/vtctlclient:{{$vitessTag}}" | ||
volumeMounts: | ||
{{ include "user-secret-volumeMounts" $defaultVtctlclient.secrets | indent 10 }} | ||
command: ["bash"] | ||
args: | ||
- "-c" | ||
- | | ||
set -ex | ||
VTCTLD_SVC=vtctld.{{ $namespace }}:15999 | ||
SECONDS=0 | ||
TIMEOUT_SECONDS=600 | ||
VTCTL_EXTRA_FLAGS=({{ include "format-flags-inline" $defaultVtctlclient.extraFlags }}) | ||
# poll every 5 seconds to see if keyspace is created | ||
until vtctlclient ${VTCTL_EXTRA_FLAGS[@]} -server $VTCTLD_SVC GetKeyspace {{ $keyspace.name }} > /dev/null 2>&1; do | ||
if (( $SECONDS > $TIMEOUT_SECONDS )); then | ||
echo "timed out waiting for keyspace {{ $keyspace.name }} to be ready" | ||
exit 1 | ||
fi | ||
sleep 5 | ||
done | ||
vtctlclient ${VTCTL_EXTRA_FLAGS[@]} -server $VTCTLD_SVC ApplyVSchema -vschema "$(cat <<END_OF_COMMAND | ||
{{ $keyspace.vschema | indent 14 }} | ||
END_OF_COMMAND | ||
)" {{ $keyspace.name }} | ||
volumes: | ||
{{ include "user-secret-volumes" (.secrets | default $defaultVtctlclient.secrets) | indent 8 }} | ||
{{- end -}} | ||
{{- end -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
################################### | ||
# shard initializations | ||
################################### | ||
|
||
{{ define "shard" -}} | ||
{{- $cell := index . 0 -}} | ||
{{- $keyspace := index . 1 -}} | ||
{{- $shard := index . 2 -}} | ||
{{- $defaultVtctlclient := index . 3 -}} | ||
{{- $namespace := index . 4 -}} | ||
{{- $totalTabletCount := index . 5 -}} | ||
|
||
# sanitize inputs for labels | ||
{{- $cellClean := include "clean-label" $cell.name -}} | ||
{{- $keyspaceClean := include "clean-label" $keyspace.name -}} | ||
{{- $shardClean := include "clean-label" $shard.name -}} | ||
{{- $shardName := printf "%s-%s-%s" $cellClean $keyspaceClean $shardClean | lower -}} | ||
|
||
{{- with $cell.vtctld }} | ||
# define image to use | ||
{{- $vitessTag := .vitessTag | default $defaultVtctlclient.vitessTag }} | ||
--- | ||
################################### | ||
# InitShardMaster Job | ||
################################### | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: {{ $shardName }}-init-shard-master | ||
spec: | ||
backoffLimit: 1 | ||
template: | ||
spec: | ||
restartPolicy: OnFailure | ||
containers: | ||
- name: init-shard-master | ||
image: "vitess/vtctlclient:{{$vitessTag}}" | ||
volumeMounts: | ||
{{ include "user-secret-volumeMounts" $defaultVtctlclient.secrets | indent 10 }} | ||
|
||
command: ["bash"] | ||
args: | ||
- "-c" | ||
- | | ||
set -ex | ||
|
||
VTCTLD_SVC=vtctld.{{ $namespace }}:15999 | ||
SECONDS=0 | ||
TIMEOUT_SECONDS=600 | ||
VTCTL_EXTRA_FLAGS=({{ include "format-flags-inline" $defaultVtctlclient.extraFlags }}) | ||
|
||
# poll every 5 seconds to see if vtctld is ready | ||
until vtctlclient ${VTCTL_EXTRA_FLAGS[@]} -server $VTCTLD_SVC ListAllTablets {{ $cell.name }} > /dev/null 2>&1; do | ||
if (( $SECONDS > $TIMEOUT_SECONDS )); then | ||
echo "timed out waiting for vtctlclient to be ready" | ||
exit 1 | ||
fi | ||
sleep 5 | ||
done | ||
|
||
until [ $TABLETS_READY ]; do | ||
# get all the tablets in the current cell | ||
cellTablets="$(vtctlclient ${VTCTL_EXTRA_FLAGS[@]} -server $VTCTLD_SVC ListAllTablets {{ $cell.name }})" | ||
|
||
# filter to only the tablets in our current shard | ||
shardTablets=$( echo "$cellTablets" | awk 'substr( $5,1,{{ len $shardName }} ) == "{{ $shardName }}" {print $0}') | ||
|
||
# check for a master tablet from the ListAllTablets call | ||
masterTablet=$( echo "$shardTablets" | awk '$4 == "master" {print $1}') | ||
if [ $masterTablet ]; then | ||
echo "'$masterTablet' is already the master tablet, exiting without running InitShardMaster" | ||
exit | ||
fi | ||
|
||
# check for a master tablet from the GetShard call | ||
master_alias=$(vtctlclient ${VTLCTL_EXTRA_FLAGS[@]} -server $VTCTLD_SVC GetShard {{ $keyspace.name }}/{{ $shard.name }} | jq '.master_alias.uid') | ||
if [ "$master_alias" != "null" -a "$master_alias" != "" ]; then | ||
echo "'$master_alias' is already the master tablet, exiting without running InitShardMaster" | ||
exit | ||
fi | ||
|
||
# count the number of newlines for the given shard to get the tablet count | ||
tabletCount=$( echo "$shardTablets" | wc | awk '{print $1}') | ||
|
||
# check to see if the tablet count equals the expected tablet count | ||
if [ $tabletCount == {{ $totalTabletCount }} ]; then | ||
TABLETS_READY=true | ||
else | ||
if (( $SECONDS > $TIMEOUT_SECONDS )); then | ||
echo "timed out waiting for tablets to be ready" | ||
exit 1 | ||
fi | ||
|
||
# wait 5 seconds for vttablets to continue getting ready | ||
sleep 5 | ||
fi | ||
|
||
done | ||
|
||
# find the tablet id for the "-replica-0" stateful set for a given cell, keyspace and shard | ||
tablet_id=$( echo "$shardTablets" | awk 'substr( $5,1,{{ add (len $shardName) 10 }} ) == "{{ $shardName }}-replica-0" {print $1}') | ||
|
||
# initialize the shard master | ||
until vtctlclient ${VTCTL_EXTRA_FLAGS[@]} -server $VTCTLD_SVC InitShardMaster -force {{ $keyspace.name }}/{{ $shard.name }} $tablet_id; do | ||
if (( $SECONDS > $TIMEOUT_SECONDS )); then | ||
echo "timed out waiting for InitShardMaster to succeed" | ||
exit 1 | ||
fi | ||
sleep 5 | ||
done | ||
volumes: | ||
{{ include "user-secret-volumes" (.secrets | default $defaultVtctlclient.secrets) | indent 8 }} | ||
|
||
|
||
{{- end -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.