Skip to content

Commit

Permalink
Merge pull request #49 from natron-io/clean_code
Browse files Browse the repository at this point in the history
get ingress by name
  • Loading branch information
janlauber authored Jan 28, 2022
2 parents f2143de + 8b25a8b commit 4e3e419
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions controllers/costController.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ func GetIngressCostSum(c *fiber.Ctx) error {
// create a map for each tenant with a added ingress costs only if cost is not 0
tenantIngressCosts := make(map[string]float64)
for _, tenant := range tenants {
if tenantIngressRequests[tenant] != 0 {
tenantIngressCosts[tenant] = util.GetIngressCost(tenantIngressRequests[tenant])
if len(tenantIngressRequests[tenant]) != 0 {
tenantIngressCosts[tenant] = util.GetIngressCost(len(tenantIngressRequests[tenant]))
}
}

Expand Down Expand Up @@ -345,8 +345,8 @@ func GetTenantIngressCostSum(c *fiber.Ctx) error {
// create a map for each tenant with a added ingress costs only if cost is not 0
tenantIngressCosts := make(map[string]float64)
for _, tenant := range tenants {
if tenantIngressRequests[tenant] != 0 {
tenantIngressCosts[tenant] = util.GetIngressCost(tenantIngressRequests[tenant])
if len(tenantIngressRequests[tenant]) != 0 {
tenantIngressCosts[tenant] = util.GetIngressCost(len(tenantIngressRequests[tenant]))
}
}

Expand Down
2 changes: 1 addition & 1 deletion util/costs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ func GetStorageCost(storageClass string, size float64) (float64, error) {
return (STORAGE_COST[storageClass]["cost"] * float64(size) / (1024 * 1024 * 1024)) * (1 - STORAGE_DISCOUNT_PERCENT), nil
}

func GetIngressCost(ingress int64) float64 {
func GetIngressCost(ingress int) float64 {
return (INGRESS_COST * float64(ingress)) * (1 - INGRESS_DISCOUNT_PERCENT)
}
7 changes: 4 additions & 3 deletions util/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ func GetStorageRequestsSumByTenant(tenants []string) (map[string]map[string]int6
return tenantPVCs, nil
}

func GetIngressRequestsSumByTenant(tenants []string) (map[string]int64, error) {
tenantsIngress := make(map[string]int64)
func GetIngressRequestsSumByTenant(tenants []string) (map[string][]string, error) {
tenantsIngress := make(map[string][]string)

for _, tenant := range tenants {
namespaces, err := Clientset.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{
Expand Down Expand Up @@ -272,7 +272,8 @@ func GetIngressRequestsSumByTenant(tenants []string) (map[string]int64, error) {

INGRESS_DISCOUNT_PERCENT = discountFloat

tenantsIngress[tenant] += int64(len(ingress.Spec.Rules))
// apend ingress hostname to the list of ingress for the tenant
tenantsIngress[tenant] = append(tenantsIngress[tenant], ingress.Name)
}
}
}
Expand Down

0 comments on commit 4e3e419

Please sign in to comment.