Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCE: use recreateInstance when rolling a MIG #3533

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/cloudinstances/cloud_instance_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type CloudInstanceGroupMember struct {
ID string
// Node is the associated k8s instance, if it is known
Node *v1.Node
// CloudInstanceGroup is the managing CloudInstanceGroup
CloudInstanceGroup *CloudInstanceGroup
}

// NewCloudInstanceGroupMember creates a new CloudInstanceGroupMember
Expand All @@ -52,7 +54,8 @@ func (c *CloudInstanceGroup) NewCloudInstanceGroupMember(instanceId string, newG
return fmt.Errorf("instance id for cloud instance member cannot be empty")
}
cm := &CloudInstanceGroupMember{
ID: instanceId,
ID: instanceId,
CloudInstanceGroup: c,
}
node := nodeMap[instanceId]
if node != nil {
Expand Down
35 changes: 32 additions & 3 deletions upup/pkg/fi/cloudup/gce/instancegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,40 @@ func (c *mockGCECloud) DeleteGroup(g *cloudinstances.CloudInstanceGroup) error {

// DeleteInstance deletes a GCE instance
func (c *gceCloudImplementation) DeleteInstance(i *cloudinstances.CloudInstanceGroupMember) error {
return DeleteInstance(c, i.ID)
return recreateCloudInstanceGroupMember(c, i)
}

// DeleteInstance deletes a GCE instance
func (c *mockGCECloud) DeleteInstance(i *cloudinstances.CloudInstanceGroupMember) error {
return DeleteInstance(c, i.ID)
return recreateCloudInstanceGroupMember(c, i)
}

// recreateCloudInstanceGroupMember recreates the specified instances, managed by an InstanceGroupManager
func recreateCloudInstanceGroupMember(c GCECloud, i *cloudinstances.CloudInstanceGroupMember) error {
mig := i.CloudInstanceGroup.Raw.(*compute.InstanceGroupManager)

glog.V(2).Infof("Recreating GCE Instance %s in MIG %s", i.ID, mig.Name)

migURL, err := ParseGoogleCloudURL(mig.SelfLink)
if err != nil {
return err
}

req := &compute.InstanceGroupManagersRecreateInstancesRequest{
Instances: []string{
i.ID,
},
}
op, err := c.Compute().InstanceGroupManagers.RecreateInstances(migURL.Project, migURL.Zone, migURL.Name, req).Do()
if err != nil {
if IsNotFound(err) {
glog.Infof("Instance not found, assuming deleted: %q", i.ID)
return nil
}
return fmt.Errorf("error recreating Instance %s: %v", i.ID, err)
}

return c.WaitForOp(op)
}

// GetCloudGroups returns a map of CloudGroup that backs a list of instance groups
Expand Down Expand Up @@ -135,7 +163,8 @@ func getCloudGroups(c GCECloud, cluster *kops.Cluster, instancegroups []*kops.In
for _, i := range instances {
id := i.Instance
cm := &cloudinstances.CloudInstanceGroupMember{
ID: id,
ID: id,
CloudInstanceGroup: g,
}

node := nodesByExternalID[strconv.FormatUint(i.Id, 10)]
Expand Down