diff --git a/distribution.create_cluster.sh b/distribution.create_cluster.sh index c1bc805c2e85133f86813e5ac8309a57bf004bf8..e5bc2e7f7a3afd542f0514b6a8a6b5b236635207 100644 --- a/distribution.create_cluster.sh +++ b/distribution.create_cluster.sh @@ -1,5 +1,8 @@ #!/bin/bash +SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") +source "${SCRIPT_DIR}/helpers/helm_helpers.sh" + k3d cluster create distribution \ --agents 2 \ --servers 1 \ @@ -15,21 +18,32 @@ k3d cluster create distribution \ --kubeconfig-update-default=true \ --kubeconfig-switch-context=true +# install calico calico_dir="/tmp/calico" git clone https://git.420joos.dev/kubernetes-cluster/networking/calico.git "${calico_dir}" calico_repo_name="projectcalico" -helm repo add ${calico_repo_name} https://docs.tigera.io/calico/charts -helm upgrade calico ${calico_repo_name}/tigera-operator \ - --install \ - --version "${CALICO_VERSION:-v3.29.2}" \ - --namespace tigera-operator \ - --create-namespace \ - --values "${calico_dir}/values.yaml" \ - --wait \ - --set "installation.calicoNetwork.ipPools[0].cidr=${CLUSTER_CIDR}" +add_helm_repo ${calico_repo_name} https://docs.tigera.io/calico/charts +install_helm_chart calico \ + ${calico_repo_name} \ + tigera-operator \ + "${CALICO_VERSION:-v3.29.2}" \ + tigera-operator \ + 300 \ + "${calico_dir}/values.yaml" \ + "--set installation.calicoNetwork.ipPools[0].cidr=${CLUSTER_CIDR}" +# helm repo add ${calico_repo_name} https://docs.tigera.io/calico/charts +# helm repo update +# helm upgrade calico ${calico_repo_name}/tigera-operator \ +# --install \ +# --version "${CALICO_VERSION:-v3.29.2}" \ +# --namespace tigera-operator \ +# --create-namespace \ +# --values "${calico_dir}/values.yaml" \ +# --wait \ +# --set "installation.calicoNetwork.ipPools[0].cidr=${CLUSTER_CIDR}" helm repo remove ${calico_repo_name} rm -rf "${calico_dir}" -# TODO: setup cluster for usage (agent & maybe calico) +# install gitlab agent diff --git a/helpers/helm_helpers.sh b/helpers/helm_helpers.sh new file mode 100644 index 0000000000000000000000000000000000000000..7deba58e496934b62af712e20e98fa596c86dd33 --- /dev/null +++ b/helpers/helm_helpers.sh @@ -0,0 +1,61 @@ +add_helm_repo() { + repo_name=$1 + repo_url=$2 + + helm repo add ${repo_name} ${repo_url} + helm repo update +} + +remove_helm_repo() { + repo_name=$1 + + helm repo remove ${repo_name} +} + +install_helm_chart() { + deployment_name=$1 + repo_name=$2 + chart_name=$3 + chart_version=$4 + namespace=$5 + timeout=$6 + values_files=$7 + upgrade_args=$8 + + values_arg="" + for values_file in $values_files; do + values_arg="${values_arg} --values ${values_file}" + done + helm upgrade ${deployment_name} ${repo_name}/${chart_name} \ + --install \ + --version ${chart_version} \ + --namespace ${namespace} \ + --create-namespace \ + --timeout ${timeout} \ + --wait \ + ${values_arg} \ + ${upgrade_args} +} + +install_gitlab_agent() { + repo_name="gitlab" + chart_version=$1 + git_repo_url=$2 + values_filenames=$3 + image_tag=$4 + token=$5 + + git_repo_dir="/tmp/gitlab-agent" + values_files="" + for filename in $values_filenames; do + values_files="${values_files} ${git_repo_dir}/${filename}" + done + + upgrade_args="--set image.tag=${image_tag} --set config.token=${token}" + + git clone "${git_repo_url}" "${git_repo_dir}" + + add_helm_repo ${repo_name} https://charts.gitlab.io + install_helm_chart distribution-agent ${repo_name} ${chart_name} ${chart_version} gitlab-agents 300 "${values_files}" "${upgrade_args}" + remove_helm_repo ${repo_name} +}