Skip to content

Commit

Permalink
Add GetAllPersistentVolumeClaims to return all PVCs as unstructured…
Browse files Browse the repository at this point in the history
… objects (#63)
  • Loading branch information
ivanfetch-wt authored Mar 13, 2023
1 parent 6455721 commit e2eecfa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.1.2
* Add `GetAllPersistentVolumeClaims()` which returns all PVCs as unstructured objects.`

## 0.1.1
* Bumped Go to 1.17

Expand Down
15 changes: 15 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ func (client Client) GetAllTopControllersWithPods(namespace string) ([]Workload,
return client.getAllTopControllers(namespace, true)
}

// GetAllPersistentVolumeClaims returns all PVCs as unstructured objects.
func (client Client) GetAllPersistentVolumeClaims(namespace string) ([]unstructured.Unstructured, error) {
fqKind := schema.FromAPIVersionAndKind("v1", "PersistentVolumeClaim")
mapping, err := client.RESTMapper.RESTMapping(fqKind.GroupKind(), fqKind.Version)
if err != nil {
log.GetLogger().Error(err, "Error retrieving mapping", "v1", "PersistentVolumeClaim")
return nil, err
}
PVCs, err := client.Dynamic.Resource(mapping.Resource).Namespace(namespace).List(client.Context, metav1.ListOptions{})
if err != nil {
return nil, err
}
return PVCs.Items, nil
}

func (client Client) getAllTopControllers(namespace string, includePods bool) ([]Workload, error) {
workloadMap := map[string]Workload{}
objectCache := map[string]unstructured.Unstructured{}
Expand Down

0 comments on commit e2eecfa

Please sign in to comment.