require 'sct/command_interface' module Sct class ClusterCommand IS_PUBLIC_COMMAND = true SYNTAX = 'sct cluster up | sct cluster down | sct cluster update-config' SUMMARY = 'Starts/stops or updates the config of the minikube cluster' EXAMPLE = 'sct cluster up | sct cluster down | sct cluster update-config' EXAMPLE_DESCRIPTION = 'Starts/stops or updates the config of the minikube cluster' DESCRIPTION = "Sct cluster allows you to start, stop or update the config of the Spend Cloud minikube cluster" OPTIONS = [] def execute(args, options) return puts "SCT has not been initialized. Run 'sct init' first.".red unless Sct::Config.exists if Sct::Config::WINDOWS minikube = "minikube.exe" else minikube = "minikube" end case args[0] when "up" system("#{minikube} start") system("#{minikube} ssh -- 'sudo su -c \"echo 10048576 > /proc/sys/fs/inotify/max_user_watches\"'") system("sct cluster update-config") system("kubectl config use-context minikube") system("kubectl delete pod -n kube-system $(kubectl get pods -n kube-system | grep registry-creds | awk '{print $1}')") system("sudo sct hostfile") puts "\nāœ”ļø You can now visit your environment at šŸ‘‰ https://spend-cloud.spend.cloud.local šŸ‘Œ" when "down" system("#{minikube} stop") when "update-config" return puts "Skipping minikube config ( only needed for windows )".yellow unless Sct::Config.operatingSystem == Sct::Config::WINDOWS windows_home_path = Sct::Config.getTrueHomePath kube_file_path = windows_home_path+"/.kube/config" if !File.exists?(kube_file_path) return puts "#{kube_file_path} doesn't exist".red end system("sed -e 's~\\\\~/~g' -e 's~C:~/mnt/c~g' < #{kube_file_path} > ~/.kube/minikube-config") return puts "Windows minikube config copied to ~/.kube/minikube-config".green else puts "Unknown or missing argument. Please run 'sct cluster up','sct cluster down' or 'sct cluster update-config'".red end end implements CommandInterface end end