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

Add Provider IDs to GCPMachinePools #5

Merged
merged 2 commits into from
Mar 13, 2024
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
6 changes: 6 additions & 0 deletions cloud/services/compute/instancegroups/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Client interface {
UpdateInstanceGroup(ctx context.Context, project, zone string, instanceGroup *compute.InstanceGroupManager) (*compute.Operation, error)
SetInstanceGroupTemplate(ctx context.Context, project, zone string, instanceGroup *compute.InstanceGroupManager) (*compute.Operation, error)
DeleteInstanceGroup(ctx context.Context, project, zone, name string) (*compute.Operation, error)
ListInstanceGroupInstances(ctx context.Context, project, zone, name string) (*compute.InstanceGroupManagersListManagedInstancesResponse, error)
// InstanceGroupTemplate Interfaces
GetInstanceTemplate(ctx context.Context, project, name string) (*compute.InstanceTemplate, error)
CreateInstanceTemplate(ctx context.Context, project string, instanceTemplate *compute.InstanceTemplate) (*compute.Operation, error)
Expand Down Expand Up @@ -87,6 +88,11 @@ func (c *GCPClient) DeleteInstanceGroup(_ context.Context, project, zone, name s
return c.service.InstanceGroupManagers.Delete(project, zone, name).Do()
}

// ListInstanceGroupInstances returns a response that contains the list of managed instances in the instance group.
func (c *GCPClient) ListInstanceGroupInstances(_ context.Context, project, zone, name string) (*compute.InstanceGroupManagersListManagedInstancesResponse, error) {
return c.service.InstanceGroupManagers.ListManagedInstances(project, zone, name).Do()
}

// GetInstanceTemplate returns a specific instance template in a project.
func (c *GCPClient) GetInstanceTemplate(_ context.Context, project, name string) (*compute.InstanceTemplate, error) {
return c.service.InstanceTemplates.Get(project, name).Do()
Expand Down
18 changes: 18 additions & 0 deletions cloud/services/compute/instancegroups/instancegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package instancegroups

import (
"context"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -123,6 +124,23 @@ func (s *Service) Reconcile(ctx context.Context) (ctrl.Result, error) {
return ctrl.Result{}, err
}

instanceGroupResponse, err := s.Client.ListInstanceGroupInstances(ctx, s.scope.Project(), s.scope.GCPMachinePool.Spec.Zone, s.scope.GCPMachinePool.Name)
if err != nil {
log.Error(err, "Error listing instance group instances")
return ctrl.Result{}, err
}

providerIDList := []string{}
for _, managedInstance := range instanceGroupResponse.ManagedInstances {
managedInstanceFmt := fmt.Sprintf("gce://%s/%s/%s", s.scope.Project(), s.scope.GCPMachinePool.Spec.Zone, managedInstance.Name)
providerIDList = append(providerIDList, managedInstanceFmt)
}

// update ProviderID and ProviderId List
s.scope.MachinePool.Spec.ProviderIDList = providerIDList
s.scope.GCPMachinePool.Spec.ProviderID = fmt.Sprintf("gce://%s/%s/%s", s.scope.Project(), s.scope.GCPMachinePool.Spec.Zone, instanceGroup.Name)
s.scope.GCPMachinePool.Spec.ProviderIDList = providerIDList

log.Info("Instance group updated", "instance group", instanceGroup.Name, "instance group status", instanceGroup.Status, "instance group target size", instanceGroup.TargetSize, "instance group current size", instanceGroup.TargetSize)
// Set the status.
conditions.MarkFalse(s.scope.ConditionSetter(), infrav1exp.GCPMachinePoolUpdatingCondition, infrav1exp.GCPMachinePoolUpdatedReason, clusterv1.ConditionSeverityInfo, "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ spec:
description: Network is the network to be used by machines in the
machine pool.
type: string
providerID:
description: ProviderID is the identification ID of the Managed Instance
Group
type: string
providerIDList:
description: ProviderIDList is the unique identifier as specified
by the cloud provider.
items:
type: string
type: array
publicIP:
description: PublicIP specifies whether the instance should get a
public IP. Set this to true if you don't have a NAT instances or
Expand Down
8 changes: 8 additions & 0 deletions exp/api/v1beta1/gcpmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ type GCPMachinePoolSpec struct {
// +optional
PublicIP *bool `json:"publicIP,omitempty"`

// ProviderID is the identification ID of the Managed Instance Group
// +optional
ProviderID string `json:"providerID,omitempty"`

// ProviderIDList is the unique identifier as specified by the cloud provider.
// +optional
ProviderIDList []string `json:"providerIDList,omitempty"`

// RootDeviceSize is the size of the root volume in GB.
// Defaults to 30.
// +optional
Expand Down
5 changes: 5 additions & 0 deletions exp/api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading