diff --git a/cloud/scope/machinepool.go b/cloud/scope/machinepool.go index 57932c745..faf7b9d0a 100644 --- a/cloud/scope/machinepool.go +++ b/cloud/scope/machinepool.go @@ -538,6 +538,16 @@ func (m *MachinePoolScope) InstanceServiceAccountsSpec() *compute.ServiceAccount // InstanceGroupBuilder returns an instance group manager spec. func (m *MachinePoolScope) InstanceGroupBuilder(instanceTemplateName string) *compute.InstanceGroupManager { + return &compute.InstanceGroupManager{ + Name: m.GCPMachinePool.Name, + BaseInstanceName: m.GCPMachinePool.Name, + InstanceTemplate: path.Join("projects", m.ClusterGetter.Project(), "global", "instanceTemplates", instanceTemplateName), + TargetSize: int64(m.DesiredReplicas()), + } +} + +// InstanceGroupUpdate returns an instance group manager spec. +func (m *MachinePoolScope) InstanceGroupUpdate(instanceTemplateName string) *compute.InstanceGroupManager { return &compute.InstanceGroupManager{ Name: m.GCPMachinePool.Name, BaseInstanceName: m.GCPMachinePool.Name, diff --git a/cloud/services/compute/instancegroups/instancegroups.go b/cloud/services/compute/instancegroups/instancegroups.go index 92f3b8229..b0f01ef64 100644 --- a/cloud/services/compute/instancegroups/instancegroups.go +++ b/cloud/services/compute/instancegroups/instancegroups.go @@ -204,7 +204,7 @@ func (s *Service) patchInstanceGroup(ctx context.Context, instanceTemplateName s if fetchedInstanceTemplateName != instanceTemplateName { log.Info("Instance group is not using the latest instance template, setting instance template", "instance group", instanceGroup.InstanceTemplate, "instance template", instanceTemplateName) // Set instance template. - setInstanceTemplateOperation, err := s.Client.SetInstanceGroupTemplate(ctx, s.scope.Project(), s.scope.GCPMachinePool.Spec.Zone, s.scope.InstanceGroupBuilder(instanceTemplateName)) + setInstanceTemplateOperation, err := s.Client.SetInstanceGroupTemplate(ctx, s.scope.Project(), s.scope.GCPMachinePool.Spec.Zone, s.scope.InstanceGroupUpdate(instanceTemplateName)) if err != nil { log.Error(err, "Error setting instance group template") return false, err