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

feat: added pagination support for ListNetworkLoadBalancers,ListInstances #249

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
42 changes: 26 additions & 16 deletions cloud/scope/load_balancer_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,24 +273,34 @@ func (s *ClusterScope) GetLoadBalancers(ctx context.Context) (*loadbalancer.Load
return nil, errors.New("cluster api tags have been modified out of context")
}
}
lbs, err := s.LoadBalancerClient.ListLoadBalancers(ctx, loadbalancer.ListLoadBalancersRequest{
CompartmentId: common.String(s.GetCompartmentId()),
DisplayName: common.String(s.GetControlPlaneLoadBalancerName()),
})
if err != nil {
s.Logger.Error(err, "Failed to list lb by name")
return nil, errors.Wrap(err, "failed to list lb by name")
}
var page *string;
for {
lbs, err := s.LoadBalancerClient.ListLoadBalancers(ctx, loadbalancer.ListLoadBalancersRequest{
CompartmentId: common.String(s.GetCompartmentId()),
DisplayName: common.String(s.GetControlPlaneLoadBalancerName()),
Page: page,
})
if err != nil {
s.Logger.Error(err, "Failed to list lb by name")
return nil, errors.Wrap(err, "failed to list lb by name")
}

for _, lb := range lbs.Items {
if s.IsResourceCreatedByClusterAPI(lb.FreeformTags) {
resp, err := s.LoadBalancerClient.GetLoadBalancer(ctx, loadbalancer.GetLoadBalancerRequest{
LoadBalancerId: lb.Id,
})
if err != nil {
return nil, err
for _, lb := range lbs.Items {
if s.IsResourceCreatedByClusterAPI(lb.FreeformTags) {
resp, err := s.LoadBalancerClient.GetLoadBalancer(ctx, loadbalancer.GetLoadBalancerRequest{
LoadBalancerId: lb.Id,
})
if err != nil {
return nil, err
}
return &resp.LoadBalancer, nil
}
return &resp.LoadBalancer, nil
}

if lbs.OpcNextPage == nil {
break
} else {
page = lbs.OpcNextPage
}
}
return nil, nil
Expand Down
33 changes: 21 additions & 12 deletions cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,27 @@ func (m *MachineScope) getMachineFromOCID(ctx context.Context, instanceID *strin
// GetMachineByDisplayName returns the machine from the compartment if there is a matching DisplayName,
// and it was created by the cluster
func (m *MachineScope) GetMachineByDisplayName(ctx context.Context, name string) (*core.Instance, error) {
req := core.ListInstancesRequest{DisplayName: common.String(name),
CompartmentId: common.String(m.getCompartmentId())}
resp, err := m.ComputeClient.ListInstances(ctx, req)
if err != nil {
return nil, err
}
if len(resp.Items) == 0 {
return nil, nil
}
for _, instance := range resp.Items {
if m.IsResourceCreatedByClusterAPI(instance.FreeformTags) {
return &instance, nil
var page *string;
for {
req := core.ListInstancesRequest{DisplayName: common.String(name),
CompartmentId: common.String(m.getCompartmentId()), Page: page}
resp, err := m.ComputeClient.ListInstances(ctx, req)
if err != nil {
return nil, err
}
if len(resp.Items) == 0 {
return nil, nil
}
for _, instance := range resp.Items {
if m.IsResourceCreatedByClusterAPI(instance.FreeformTags) {
return &instance, nil
}
}

if resp.OpcNextPage == nil {
break
} else {
page = resp.OpcNextPage
}
}
return nil, nil
Expand Down