lib/seira/setup.rb in seira-0.4.10 vs lib/seira/setup.rb in seira-0.5.0
- old
+ new
@@ -74,16 +74,36 @@
else
puts "Authenticating in order to set the auth for project #{cluster_name}. You will be directed to a google login page."
system("gcloud auth login")
end
+ # All cluster configs must specify a project and region. Region is required, even
+ # if cluster is zonal, for other things like databases.
system("gcloud config set project #{cluster_metadata['project']}")
- system("gcloud config set compute/zone #{cluster_metadata['zone'] || settings.default_zone}")
+ system("gcloud config set compute/region #{cluster_metadata['region']}")
+
+ # Regional and zonal clusters have slightly different behavior. We need
+ # to make sure that the zone is *not* set for regional cluster, or gcloud
+ # will complain. And zone *needs* to be set for zonal clusters.
+ if cluster_metadata['zone']
+ system("gcloud config set compute/zone #{cluster_metadata['zone']}")
+ else
+ system("gcloud config unset compute/zone")
+ end
+
puts "Your new gcloud setup for #{cluster_name}:"
system("gcloud config configurations describe #{cluster_name}")
- puts "Configuring kubectl for interactions with this project's kubernetes cluster"
- system("gcloud container clusters get-credentials #{cluster_name} --project #{cluster_metadata['project']}")
+ puts "Configuring kubectl for interactions with this project's kubernetes cluster with region #{cluster_metadata['region']} and zone #{cluster_metadata['zone']}"
+
+ # For regional clusters, we use the beta --region option. For zonal clusters, we pass --zone. Regional
+ # clusters are in the beta feature of gcloud.
+ if cluster_metadata['zone']
+ system("gcloud container clusters get-credentials #{cluster_name} --project #{cluster_metadata['project']} --zone #{cluster_metadata['zone']}")
+ else
+ system("gcloud beta container clusters get-credentials #{cluster_name} --project #{cluster_metadata['project']} --region #{cluster_metadata['region']}")
+ end
+
puts "Your kubectl is set up with:"
system("kubectl config current-context")
end
def ensure_software_installed