modules/mu/clouds/google/server_pool.rb in cloud-mu-3.1.3 vs modules/mu/clouds/google/server_pool.rb in cloud-mu-3.1.4

- old
+ new

@@ -62,14 +62,13 @@ size = nil if !@config['basis']['launch_config'].nil? size = @config['basis']['launch_config']['size'] @config['image_id'] = @config['basis']['launch_config']['image_id'] end - az = @config['availability_zone'] - if az.nil? - az = MU::Cloud::Google.listAZs(@config['region']).sample - end +# XXX this should create a non-regional instance group +# az = @config['availability_zone'] +# az ||= MU::Cloud::Google.listAZs(@config['region']).sample metadata = { # :items? "startup-script" => @userdata } if @config['metadata'] @@ -168,12 +167,11 @@ end # Locate an existing ServerPool or ServerPools and return an array containing matching Google resource descriptors for those that match. # @return [Hash<String,OpenStruct>]: The cloud provider's complete descriptions of matching ServerPools def self.find(**args) - args[:project] ||= args[:habitat] - args[:project] ||= MU::Cloud::Google.defaultProject(args[:credentials]) + args = MU::Cloud::Google.findLocationArgs(args) regions = if args[:region] [args[:region]] else MU::Cloud::Google.listRegions @@ -211,11 +209,11 @@ end # Reverse-map our cloud description into a runnable config hash. # We assume that any values we have in +@config+ are placeholders, and # calculate our own accordingly based on what's live in the cloud. - def toKitten(rootparent: nil, billing: nil, habitats: nil) + def toKitten(**_args) bok = { "cloud" => "Google", "credentials" => @credentials, "cloud_id" => @cloud_id, "region" => @config['region'], @@ -360,44 +358,22 @@ # @param pool [Hash]: The resource to process and validate # @param configurator [MU::Config]: The overall deployment configurator of which this resource is a member # @return [Boolean]: True if validation succeeded, False otherwise def self.validateConfig(pool, configurator) ok = true -start = Time.now +#start = Time.now pool['project'] ||= MU::Cloud::Google.defaultProject(pool['credentials']) if pool['service_account'] pool['service_account']['cloud'] = "Google" pool['service_account']['habitat'] ||= pool['project'] found = MU::Config::Ref.get(pool['service_account']) if found.id and !found.kitten MU.log "GKE pool #{pool['name']} failed to locate service account #{pool['service_account']} in project #{pool['project']}", MU::ERR ok = false end else - user = { - "name" => pool['name'], - "cloud" => "Google", - "project" => pool["project"], - "credentials" => pool["credentials"], - "type" => "service" - } - if user["name"].length < 6 - user["name"] += Password.pronounceable(6) - end - configurator.insertKitten(user, "users", true) - pool['dependencies'] ||= [] - pool['service_account'] = MU::Config::Ref.get( - type: "users", - cloud: "Google", - name: pool["name"], - project: pool["project"], - credentials: pool["credentials"] - ) - pool['dependencies'] << { - "type" => "user", - "name" => pool["name"] - } + pool = MU::Cloud::Google::User.genericServiceAccount(pool, configurator) end pool['named_ports'] ||= [] if !pool['named_ports'].include?({"name" => "ssh", "port" => 22}) pool['named_ports'] << {"name" => "ssh", "port" => 22} @@ -456,9 +432,14 @@ # @param region [String]: The cloud provider region # @return [void] def self.cleanup(noop: false, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {}) flags["project"] ||= MU::Cloud::Google.defaultProject(credentials) return if !MU::Cloud::Google::Habitat.isLive?(flags["project"], credentials) + filter = %Q{(labels.mu-id = "#{MU.deploy_id.downcase}")} + if !ignoremaster and MU.mu_public_ip + filter += %Q{ AND (labels.mu-master-ip = "#{MU.mu_public_ip.gsub(/\./, "_")}")} + end + MU.log "Placeholder: Google ServerPool artifacts do not support labels, so ignoremaster cleanup flag has no effect", MU::DEBUG, details: filter if !flags["global"] ["region_autoscaler", "region_instance_group_manager"].each { |type| MU::Cloud::Google.compute(credentials: credentials).delete( type,