From 87ea01085f9569e1c769ef306298ca6fe3924cef Mon Sep 17 00:00:00 2001 From: Olivier Berger Date: Wed, 9 Oct 2019 11:10:10 +0200 Subject: [PATCH 1/3] Provide a way to set env vars for selfmedicate.sh Setting env var value for selfmedicate in the YAML config file so it can be passed to the provisionner First variable will be PRELOADED_IMAGES --- Vagrantfile | 7 ++++++- antidote-config.yml | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 088d868..db8b063 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -27,6 +27,11 @@ if defined? antidote_config['vm_config']['provider'] then ENV['VAGRANT_DEFAULT_PROVIDER'] = antidote_config['vm_config']['provider'] end +# Allow customization of the option passed to the selfmedicate.sh provisionning script +if defined? antidote_config['selfmedicate_prefs']['PRELOADED_IMAGES'] then + ENV['SELFMEDICATE_PRELOADED_IMAGES'] = antidote_config['selfmedicate_prefs']['PRELOADED_IMAGES'].join(' ') +end + ## Configure VAGRANT Variables trimmed_version = antidote_config['version'].to_s.tr('.','') antidote_config['hostname'] = "antidote-#{trimmed_version}" @@ -108,7 +113,7 @@ Vagrant.configure("2") do |config| # Running initial selfmedicate script as the Vagrant user. $script = "/bin/bash --login $HOME/selfmedicate.sh start" - config.vm.provision "custom", type: "shell", privileged: false, inline: $script + config.vm.provision "custom", type: "shell", privileged: false, inline: $script, env: {"PRELOADED_IMAGES" => ENV['SELFMEDICATE_PRELOADED_IMAGES']} # Start antidote on reload $script = "/bin/bash --login $HOME/selfmedicate.sh resume" diff --git a/antidote-config.yml b/antidote-config.yml index 718c846..4c937a3 100644 --- a/antidote-config.yml +++ b/antidote-config.yml @@ -11,3 +11,12 @@ vm_config: memory: 8192 cores: 2 provider: virtualbox + +# Providing a value for options supported by the +# selfmedicate.sh script, relevant in the Vagrant context. For the +# moment PRELOADED_IMAGES +# For instance: +# +#selfmedicate_prefs: +# PRELOADED_IMAGES: ["utility", "vqfx-snap1"] + From 355461aaab21be70e861654567c7470bd60a75b1 Mon Sep 17 00:00:00 2001 From: Olivier Berger Date: Sun, 3 Nov 2019 15:04:28 +0100 Subject: [PATCH 2/3] Allow customizing k8s version for kubectl download Aligns download of kubectl on k8s with same K8SVERSION env variable than for selfmedicate.sh --- Vagrantfile | 7 +++++-- antidote-config.yml | 2 +- vagrant-provision.sh | 11 ++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index db8b063..c3f1b75 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -31,6 +31,9 @@ end if defined? antidote_config['selfmedicate_prefs']['PRELOADED_IMAGES'] then ENV['SELFMEDICATE_PRELOADED_IMAGES'] = antidote_config['selfmedicate_prefs']['PRELOADED_IMAGES'].join(' ') end +if defined? antidote_config['selfmedicate_prefs']['KUBERNETES_VERSION'] then + ENV['KUBERNETES_VERSION'] = antidote_config['selfmedicate_prefs']['KUBERNETES_VERSION'] +end ## Configure VAGRANT Variables trimmed_version = antidote_config['version'].to_s.tr('.','') @@ -109,11 +112,11 @@ Vagrant.configure("2") do |config| # Provisioning antidote vagrant vm # This will install docker, kubectl and minikube - config.vm.provision "default", type: "shell", path: "vagrant-provision.sh", env: {CHANGE_MINIKUBE_NONE_USER: true} + config.vm.provision "default", type: "shell", path: "vagrant-provision.sh", env: {CHANGE_MINIKUBE_NONE_USER: true, "K8SVERSION" => ENV['KUBERNETES_VERSION']} # Running initial selfmedicate script as the Vagrant user. $script = "/bin/bash --login $HOME/selfmedicate.sh start" - config.vm.provision "custom", type: "shell", privileged: false, inline: $script, env: {"PRELOADED_IMAGES" => ENV['SELFMEDICATE_PRELOADED_IMAGES']} + config.vm.provision "custom", type: "shell", privileged: false, inline: $script, env: {"PRELOADED_IMAGES" => ENV['SELFMEDICATE_PRELOADED_IMAGES'], "K8SVERSION" => ENV['KUBERNETES_VERSION']} # Start antidote on reload $script = "/bin/bash --login $HOME/selfmedicate.sh resume" diff --git a/antidote-config.yml b/antidote-config.yml index 4c937a3..119fbd2 100644 --- a/antidote-config.yml +++ b/antidote-config.yml @@ -19,4 +19,4 @@ vm_config: # #selfmedicate_prefs: # PRELOADED_IMAGES: ["utility", "vqfx-snap1"] - +# KUBERNETES_VERSION: "v1.14.8" diff --git a/vagrant-provision.sh b/vagrant-provision.sh index 9d0853a..6580122 100644 --- a/vagrant-provision.sh +++ b/vagrant-provision.sh @@ -94,9 +94,14 @@ setup_docker() { } install_kubectl() { - # Download the latest version of kubectl - echo "Installing Kubectl" - curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl &>/dev/null + if [[ $K8SVERSION = v* ]]; then + echo "Installing Kubectl version $K8SVERSION" + curl -LO https://storage.googleapis.com/kubernetes-release/release/$K8SVERSION/bin/linux/amd64/kubectl &>/dev/null + else + # Download the latest version of kubectl + echo "Installing Kubectl" + curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl &>/dev/null + fi # Make the kubectl binary executable chmod +x ./kubectl # Move the binary into the PATH From b30c50245a1e94feac4a2446aad4a833e546a8d6 Mon Sep 17 00:00:00 2001 From: Olivier Berger Date: Mon, 4 Nov 2019 13:51:19 +0100 Subject: [PATCH 3/3] Better handle case when undefined --- Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index c3f1b75..5479799 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -31,7 +31,7 @@ end if defined? antidote_config['selfmedicate_prefs']['PRELOADED_IMAGES'] then ENV['SELFMEDICATE_PRELOADED_IMAGES'] = antidote_config['selfmedicate_prefs']['PRELOADED_IMAGES'].join(' ') end -if defined? antidote_config['selfmedicate_prefs']['KUBERNETES_VERSION'] then +if antidote_config['selfmedicate_prefs']['KUBERNETES_VERSION'] then ENV['KUBERNETES_VERSION'] = antidote_config['selfmedicate_prefs']['KUBERNETES_VERSION'] end