Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
caruccio committed Mar 18, 2024
1 parent e752a3e commit ca9b57e
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 42 deletions.
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ ENV TERM="xterm-256color" \
KREW_REPOS="kvaps@https://github.com/kvaps/krew-index" \
KREW_VERSION="v0.4.2" \
KUBECONFIG="${CLUSTER_DIR}/.kube/config" \
KUBECTL_VERSIONS="v1.21.14 v1.22.17 v1.23.17 v1.24.14 v1.25.10 v1.26.9 v1.27.6" \
KUBELOGIN_VERSION="v0.0.32" \
OC_VERSION="4.11.0-0.okd-2022-12-02-145640" \
OSH="/etc/oh-my-bash" \
Expand Down Expand Up @@ -101,6 +100,13 @@ RUN cd /usr/local/bin && \
curl -skL https://run.linkerd.io/install | INSTALLROOT=/usr/local bash && \
curl -skL https://github.com/openshift/okd/releases/download/${OC_VERSION}/openshift-client-linux-${OC_VERSION}.tar.gz \
| tar xzvf - oc && \
KUBECTL_VERSIONS=$( \
curl -s https://api.github.com/repos/kubernetes/kubernetes/releases?per_page=100 \
| jq -r '.[] | .tag_name' \
| grep '^v[0-9]\.[0-9][0-9]\?\.[0-9][0-9]\?$' \
| sort -Vr \
| awk -F . '!a[$1 FS $2]++' \
| sort -V) && \
for KUBECTL_VERSION in $KUBECTL_VERSIONS; do \
curl -skL https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl > \
kubectl_${KUBECTL_VERSION}; \
Expand Down
3 changes: 3 additions & 0 deletions root/etc/profile.d/getup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ function get_tf_config()
{
local sh_var_name=$1
local tf_var_name=$2
local default=$3

if [ -v $sh_var_name ]; then
echo ${!sh_var_name}
Expand All @@ -247,6 +248,8 @@ function get_tf_config()
array)
hcl2json "$TF_VARS_FILE" | jq -Mrc ".${tf_var_name}|join(\"\n\")"
esac

echo $default
}

ask()
Expand Down
15 changes: 8 additions & 7 deletions root/usr/local/bin/kubespray-apply
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ set -eu

source /etc/profile.d/getup.sh

if [ $# -gt 0 ]; then
user="$1"
else
user=$(awk '/\s*#?\s*ssh_user\s*=\s".*".*/ { patsplit($3, a, /[^"]+/); print a[1] }' $TF_VARS_FILE | tail -n1) 2>/dev/null
if [[ "$1" =~ (-h|--help) ]] ; then
echo "Usage: $0 [ansible-playbook parameters...]"
exit 1
fi

user=${user:-centos}
user=$(get_tf_config SSH_USER ssh_user centos)
kube_version=$(ansible-inventory -i $INVENTORY_FILE --list | jq -r '._meta.hostvars[._meta.hostvars|keys[0]].kube_version')

playbook=$KUBESPRAY_DIR/cluster.yml

if [ ${0##*/} == "kubespray-upgrade" ]; then
playbook=$KUBESPRAY_DIR/upgrade-cluster.yml
playbook=$KUBESPRAY_DIR/upgrade-cluster.yml
fi

ask_execute_command ansible-playbook -i $INVENTORY_FILE --become --user $user $playbook
echo Kubernetes Version: $kube_version
ask_execute_command ansible-playbook -i $INVENTORY_FILE --become --user $user $@ $playbook
14 changes: 9 additions & 5 deletions root/usr/local/bin/kubespray-apply-tags
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ export ROOT_DIR=$(readlink -nf $(dirname $0))

source /etc/profile.d/getup.sh

if [ $# -gt 0 ]; then
user="$1"
else
user=$(awk '/\s*#?\s*ssh_user\s*=\s".*".*/ { patsplit($3, a, /[^"]+/); print a[1] }' $TF_VARS_FILE | tail -n1) 2>/dev/null
if [[ "$1" =~ (-h|--help) ]] ; then
echo "Usage: $0 [ansible-playbook parameters...]"
exit 1
fi

user=$(get_tf_config SSH_USER ssh_user centos)

kube_version=$(ansible-inventory -i $INVENTORY_FILE --list | jq -r '._meta.hostvars[._meta.hostvars|keys[0]].kube_version')

out=/tmp/.dialog
exec 3>$out
eval dialog \
Expand All @@ -27,4 +30,5 @@ if [ -z "$tags" ]; then
exit 0
fi

ask_execute_command ansible-playbook -i $INVENTORY_FILE --become --user $user $KUBESPRAY_DIR/cluster.yml --tags $tags
echo Kubernetes Version: $kube_version
ask_execute_command ansible-playbook -i $INVENTORY_FILE --become --user $user --tags $tags $@ $KUBESPRAY_DIR/cluster.yml
25 changes: 11 additions & 14 deletions root/usr/local/bin/kubespray-copy
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ set -eu

source /etc/profile.d/getup.sh

user=$(get_tf_config SSH_USER ssh_user)

if [ -z "$user" ]; then
user=centos
fi
user=$(get_tf_config SSH_USER ssh_user centos)

hosts=all
remote_src=false

if [ $# -lt 2 ] || [[ "$1" =~ (-h|--help) ]]; then
echo "Usage:"
echo
echo " Upload: $0 local-file hosts:remote-file [copy module extra parameters...]"
echo " Download: $0 host:remote-file local-file [copy module extra parameters...]"
echo
echo "See available flags in https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html"
exit 1
fi

src=$1
dest=$2
shift 2
Expand All @@ -22,13 +28,6 @@ dest_host=${dest%%:*}
src=${src#*:}
dest=${dest#*:}

if [ -n "$src_host" -a -n "$dest_host" ] || [ -z "$src_host$dest_host" ]; then
echo "Usage:"
echo " Upload: $0 local-file hosts:remote-file"
echo " Download: $0 host:remote-file local-file"
exit 1
fi

if [ -n "$src_host" ]; then
# downloading
hosts=$src_host
Expand All @@ -38,6 +37,4 @@ elif [ -n "$dest_host" ]; then
hosts=$dest_host
fi

echo "See available flags in https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html" >&2

execute_command ansible $hosts -i $INVENTORY_FILE --become --user $user -m copy -a "src=$src dest=$dest remote_src=$remote_src $*"
8 changes: 5 additions & 3 deletions root/usr/local/bin/kubespray-exec
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ set -eu

source /etc/profile.d/getup.sh

user=$(grep 'ssh_user\s*=\s*.*' $CLUSTER_DIR/terraform.tfvars | awk '{print $NF}' | tr -d '"')
if [ -z "$user" ]; then
user=centos
if [[ "$1" =~ (-h|--help|^$) ]] ; then
echo "Usage: $0 command [parameters...]"
exit 1
fi

user=$(get_tf_config SSH_USER ssh_user centos)

set -x

ansible all -i $INVENTORY_FILE --become --user $user -m shell -a "$*"
21 changes: 11 additions & 10 deletions templates/kubespray/main.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module "cluster" {
source = "github.com/getupcloud/terraform-cluster-kubespray?ref=v3.4.0"
source = "github.com/getupcloud/terraform-cluster-kubespray?ref=v4.0.0-beta1"

# cluster basics
customer_name = var.customer_name
cluster_name = var.cluster_name
cluster_sla = var.cluster_sla
cluster_provider = var.cluster_provider
use_kubeconfig = var.use_kubeconfig
pre_create = var.pre_create
post_create = var.post_create
modules = local.modules_result
dump_debug = var.dump_debug
customer_name = var.customer_name
cluster_name = var.cluster_name
cluster_sla = var.cluster_sla
cluster_provider = var.cluster_provider
kubernetes_version = var.kubernetes_version
use_kubeconfig = var.use_kubeconfig
pre_create = var.pre_create
post_create = var.post_create
modules = local.modules_result
dump_debug = var.dump_debug

# monitoring and operations
cronitor_enabled = var.cronitor_enabled
Expand Down
4 changes: 2 additions & 2 deletions templates/kubespray/variables-provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ variable "api_endpoint" {
variable "kubernetes_version" {
description = "Kubernetes rersion"
type = string
default = "1.24"
default = "v1.25.6"
}

variable "region" {
Expand All @@ -28,7 +28,7 @@ variable "deploy_components" {
variable "kubespray_git_ref" {
description = "Kubespray ref name"
type = string
default = "remotes/origin/release-2.17"
default = "remotes/origin/release-2.22"
}

variable "kubespray_dir" {
Expand Down

0 comments on commit ca9b57e

Please sign in to comment.