vttablet-up.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. # Copyright 2015 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # This is an example script that creates a vttablet deployment.
  16. set -e
  17. script_root=`dirname "${BASH_SOURCE}"`
  18. source $script_root/env.sh
  19. # Create the pods for shard-0
  20. CELLS=${CELLS:-'test'}
  21. keyspace='test_keyspace'
  22. SHARDS=${SHARDS:-'0'}
  23. TABLETS_PER_SHARD=${TABLETS_PER_SHARD:-5}
  24. port=15002
  25. grpc_port=16002
  26. UID_BASE=${UID_BASE:-100}
  27. VTTABLET_TEMPLATE=${VTTABLET_TEMPLATE:-'vttablet-pod-template.yaml'}
  28. RDONLY_COUNT=${RDONLY_COUNT:-2}
  29. uid_base=$UID_BASE
  30. for shard in $(echo $SHARDS | tr "," " "); do
  31. cell_index=0
  32. for cell in `echo $CELLS | tr ',' ' '`; do
  33. echo "Creating $keyspace.shard-$shard pods in cell $CELL..."
  34. for uid_index in `seq 0 $(($TABLETS_PER_SHARD-1))`; do
  35. uid=$[$uid_base + $uid_index + $cell_index]
  36. printf -v alias '%s-%010d' $cell $uid
  37. printf -v tablet_subdir 'vt_%010d' $uid
  38. echo "Creating pod for tablet $alias..."
  39. # Add xx to beginning or end if there is a dash. K8s does not allow for
  40. # leading or trailing dashes for labels
  41. shard_label=`echo $shard | sed s'/[-]$/-xx/' | sed s'/^-/xx-/'`
  42. tablet_type=replica
  43. if [ $uid_index -gt $(($TABLETS_PER_SHARD-$RDONLY_COUNT-1)) ]; then
  44. tablet_type=rdonly
  45. fi
  46. # Expand template variables
  47. sed_script=""
  48. for var in alias cell uid keyspace shard shard_label port grpc_port tablet_subdir tablet_type backup_flags; do
  49. sed_script+="s,{{$var}},${!var},g;"
  50. done
  51. # Instantiate template and send to kubectl.
  52. cat $VTTABLET_TEMPLATE | sed -e "$sed_script" | $KUBECTL create -f -
  53. done
  54. let cell_index=cell_index+100000000
  55. done
  56. let uid_base=uid_base+100
  57. done