Skip to content

Commit

Permalink
Merge pull request #79 from natron-io/pvcs_by_storageclass
Browse files Browse the repository at this point in the history
implement pvcs by storageclass
  • Loading branch information
janlauber authored Feb 10, 2022
2 parents f813c6a + 308eafb commit 1ae2959
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
6 changes: 3 additions & 3 deletions controllers/tenantController.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ func GetPVCs(c *fiber.Ctx) error {
}

// create a map for each tenant with a added memory requests
tenantPVCs, err := util.GetPVCsByTenant(tenants)
tenantPVCsByStorageClass, err := util.GetPVCsByTenantByStorageClass(tenants)
if err != nil {
return c.Status(500).JSON(fiber.Map{
"message": "Internal Server Error",
})
}

if tenant == "" {
return c.JSON(tenantPVCs)
return c.JSON(tenantPVCsByStorageClass)
} else {
return c.JSON(tenantPVCs[tenant])
return c.JSON(tenantPVCsByStorageClass[tenant])
}
}

Expand Down
28 changes: 20 additions & 8 deletions util/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,30 @@ func GetPodsByTenant(tenants []string) (map[string][]string, error) {
return tenantPods, nil
}

func GetPVCsByTenant(tenants []string) (map[string][]string, error) {
tenantPVCs := make(map[string][]string)
func GetPVCsByTenantByStorageClass(tenants []string) (map[string]map[string][]string, error) {
tenantPVCs := make(map[string]map[string][]string)
storageClasses, err := GetStorageClassesInCluster()
if err != nil {
return nil, err
}

for _, tenant := range tenants {
pvcList, err := Clientset.CoreV1().PersistentVolumeClaims(tenant).List(context.TODO(), metav1.ListOptions{})
if err != nil && !strings.Contains(err.Error(), "not found") {
return nil, err
}
tenantPVCs[tenant] = make(map[string][]string)
for _, storageClass := range storageClasses {
// get pvc by storageclass pvc spec
pvcs, err := Clientset.CoreV1().PersistentVolumeClaims(tenant).List(context.TODO(), metav1.ListOptions{})
if err != nil && !strings.Contains(err.Error(), "not found") {
return nil, err
}

for _, pvc := range pvcList.Items {
tenantPVCs[tenant] = append(tenantPVCs[tenant], pvc.Name)
for _, pvc := range pvcs.Items {
if *pvc.Spec.StorageClassName == storageClass {
tenantPVCs[tenant][storageClass] = append(tenantPVCs[tenant][storageClass], pvc.Name)
}
}
}
}

return tenantPVCs, nil
}

Expand Down

0 comments on commit 1ae2959

Please sign in to comment.