Skip to content

Commit 53de71c

Browse files
author
Matthew Barnes
committed
ocm: Add ListCSClusters and ListCSNodePools methods
1 parent 0a734bb commit 53de71c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

internal/ocm/mock.go

+8
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ func (mcsc *MockClusterServiceClient) DeleteCSCluster(ctx context.Context, inter
9191
return nil
9292
}
9393

94+
func (mcsc *MockClusterServiceClient) ListCSClusters(searchExpression string) ClusterListIterator {
95+
return ClusterListIterator{err: fmt.Errorf("ListCSClusters not implemented")}
96+
}
97+
9498
func (mcsc *MockClusterServiceClient) GetCSNodePool(ctx context.Context, internalID InternalID) (*cmv1.NodePool, error) {
9599
nodePool, ok := mcsc.nodePools[internalID]
96100
if !ok {
@@ -133,3 +137,7 @@ func (mcsc *MockClusterServiceClient) DeleteCSNodePool(ctx context.Context, inte
133137
delete(mcsc.nodePools, internalID)
134138
return nil
135139
}
140+
141+
func (mcsc *MockClusterServiceClient) ListCSNodePools(clusterInternalID InternalID, searchExpression string) NodePoolListIterator {
142+
return NodePoolListIterator{err: fmt.Errorf("ListCSClusters not implemented")}
143+
}

internal/ocm/ocm.go

+28
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ type ClusterServiceClientSpec interface {
1818
PostCSCluster(ctx context.Context, cluster *cmv1.Cluster) (*cmv1.Cluster, error)
1919
UpdateCSCluster(ctx context.Context, internalID InternalID, cluster *cmv1.Cluster) (*cmv1.Cluster, error)
2020
DeleteCSCluster(ctx context.Context, internalID InternalID) error
21+
ListCSClusters(searchExpression string) ClusterListIterator
2122
GetCSNodePool(ctx context.Context, internalID InternalID) (*cmv1.NodePool, error)
2223
PostCSNodePool(ctx context.Context, clusterInternalID InternalID, nodePool *cmv1.NodePool) (*cmv1.NodePool, error)
2324
UpdateCSNodePool(ctx context.Context, internalID InternalID, nodePool *cmv1.NodePool) (*cmv1.NodePool, error)
2425
DeleteCSNodePool(ctx context.Context, internalID InternalID) error
26+
ListCSNodePools(clusterInternalID InternalID, searchExpression string) NodePoolListIterator
2527
}
2628

2729
// Get the default set of properties for the Cluster Service
@@ -153,6 +155,17 @@ func (csc *ClusterServiceClient) DeleteCSCluster(ctx context.Context, internalID
153155
return err
154156
}
155157

158+
// ListCSClusters prepares a GET request with the given search expression. Call Items() on
159+
// the returned iterator in a for/range loop to execute the request and paginate over results,
160+
// then call GetError() to check for an iteration error.
161+
func (csc *ClusterServiceClient) ListCSClusters(searchExpression string) ClusterListIterator {
162+
clustersListRequest := csc.Conn.ClustersMgmt().V1().Clusters().List()
163+
if searchExpression != "" {
164+
clustersListRequest.Search(searchExpression)
165+
}
166+
return ClusterListIterator{request: clustersListRequest}
167+
}
168+
156169
// GetCSNodePool creates and sends a GET request to fetch a node pool from Clusters Service
157170
func (csc *ClusterServiceClient) GetCSNodePool(ctx context.Context, internalID InternalID) (*cmv1.NodePool, error) {
158171
client, ok := internalID.GetNodePoolClient(csc.Conn)
@@ -213,3 +226,18 @@ func (csc *ClusterServiceClient) DeleteCSNodePool(ctx context.Context, internalI
213226
_, err := client.Delete().SendContext(ctx)
214227
return err
215228
}
229+
230+
// ListCSNodePools prepares a GET request with the given search expression. Call Items() on
231+
// the returned iterator in a for/range loop to execute the request and paginate over results,
232+
// then call GetError() to check for an iteration error.
233+
func (csc *ClusterServiceClient) ListCSNodePools(clusterInternalID InternalID, searchExpression string) NodePoolListIterator {
234+
client, ok := clusterInternalID.GetClusterClient(csc.Conn)
235+
if !ok {
236+
return NodePoolListIterator{err: fmt.Errorf("OCM path is not a cluster: %s", clusterInternalID)}
237+
}
238+
nodePoolsListRequest := client.NodePools().List()
239+
if searchExpression != "" {
240+
nodePoolsListRequest.Search(searchExpression)
241+
}
242+
return NodePoolListIterator{request: nodePoolsListRequest}
243+
}

0 commit comments

Comments
 (0)