Skip to content

Assigning MIG instance template (PATCH) fails with named ports are immutable error #24808

@julik

Description

@julik

Environment details

  • OS:
  • Ruby version: 3.2.2
  • Gem name and version: google-cloud-common (1.4.0), google-cloud-compute-v1 (2.6.0), googleapis-common-protos-types (1.11.0)

Steps to reproduce

Attempt to manage an instance group using the SDK causes an error in a PATCH request

Code example

instance_group_managers_client = ::Google::Cloud::Compute::V1::RegionInstanceGroupManagers::Rest::Client.new do |config|
  # Our deploys can take a long time if many instances need to be rotated, and we can't really set
  # too high a maxSurge because of the DB connection limits, so we need to increase the timeout
  config.timeout = 20 * 60 # set in seconds
end

resource = {
  instance_template: nil,
  update_policy: {
    minimal_action: "REPLACE",
    max_unavailable: {
      fixed: 0
    },
    max_surge: {
      fixed: 5
    },
    type: "PROACTIVE"
  },
  versions: [
    instance_template: "projects/#{project}/global/instanceTemplates/#{service}-#{process}-#{version}"
  ]
}

operation = instance_group_managers_client.patch(
  instance_group_manager: "#{service}-#{process}",
  region: region,
  project: project,
  instance_group_manager_resource: resource
)

# Note that this waits until the #patch operation is done, it does *not* wait for the version to be rolled out.
operation.wait_until_done!(retry_policy: {
  initial_delay: 0.2, # 200ms
  max_delay: 30, # 30s
  timeout: 300 # 5 minutes
})
    
The instance template we create before running this script looks approximately as follows:

```ruby
template = ->(process) do
  {
    name: "#{service}-#{process}-#{version}",
    properties: {
      labels: {
        "app-version" => version,
        "service" => service,
        "process" => process
      },
      tags: {
        items: [
          "app",
          tag
        ]
      },
      machine_type: machine_types_per_env_and_mig[[env, process]],
      metadata: {
        items: [
          {
            key: "google-logging-enabled",
            value: "true"
          },
          {
            key: "user-data",
            value: generate_config.call(process)
          }
        ]
      },
      service_accounts: [
        {
          email: service_account,
          scopes: ["https://www.googleapis.com/auth/cloud-platform"]
        }
      ],
      can_ip_forward: false,
      network_interfaces: [
        {
          name: "nic0",
          network: network,
          subnetwork: subnet
        }
      ],
      disks: [
        {
          type: "PERSISTENT",
          device_name: "persistent-disk-0",
          auto_delete: true,
          boot: true,
          mode: "READ_WRITE",
          initialize_params: {
            source_image: "projects/cos-cloud/global/images/family/cos-stable"
          }
        }
      ],
      scheduling: {
        on_host_maintenance: "MIGRATE",
        automatic_restart: true,
        preemptible: false
      }
    }
  }

and creating the template succeeds.

Full backtrace

Google::Cloud::InvalidArgumentError: An error has occurred when making a REST request: Invalid value for field 'resource.namedPorts[0]': ''. named ports are immutable
    from /home/ubuntu/runner/_work/<redacted>/<redacted>/vendor/bundle/ruby/3.2.0/gems/google-cloud-compute-v1-2.6.0/lib/google/cloud/compute/v1/region_instance_group_managers/rest/client.rb:1398:in `rescue in patch'
    from /home/ubuntu/runner/_work/<redacted>/<redacted>/vendor/bundle/ruby/3.2.0/gems/google-cloud-compute-v1-2.6.0/lib/google/cloud/compute/v1/region_instance_group_managers/rest/client.rb:1357:in `patch'
    from deploy/deploy-version:81:in `block (2 levels) in <main>'
    from /home/ubuntu/runner/_work/<redacted>/<redacted>/vendor/bundle/ruby/3.2.0/gems/cli-ui-2.1.0/lib/cli/ui/spinner/spin_group.rb:65:in `block (2 levels) in initialize'
    from /home/ubuntu/runner/_work/<redacted>/<redacted>/vendor/bundle/ruby/3.2.0/gems/cli-ui-2.1.0/lib/cli/ui/stdout_router.rb:160:in `block in run'
    from /home/ubuntu/runner/_work/<redacted>/<redacted>/vendor/bundle/ruby/3.2.0/gems/cli-ui-2.1.0/lib/cli/ui/stdout_router.rb:108:in `with_stdin_masked'
    from /home/ubuntu/runner/_work/<redacted>/<redacted>/vendor/bundle/ruby/3.2.0/gems/cli-ui-2.1.0/lib/cli/ui/stdout_router.rb:148:in `run'
    from /home/ubuntu/runner/_work/<redacted>/<redacted>/vendor/bundle/ruby/3.2.0/gems/cli-ui-2.1.0/lib/cli/ui/spinner/spin_group.rb:67:in `block in initialize'

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions