Skip to content

Commit

Permalink
log mismatches with "should be" constraints
Browse files Browse the repository at this point in the history
These types of constraints are only transitional and will be removed
when we have moved to "at least"/"at most"/"exactly" only.
  • Loading branch information
majewsky committed Jun 13, 2018
1 parent b60d3a8 commit f92b2c3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 9 additions & 0 deletions pkg/datamodel/domain_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ func checkDomainServiceConstraints(tx *gorp.Transaction, cluster *limes.Cluster,
res.Quota = newQuota
resourcesToUpdate = append(resourcesToUpdate, &res)
}

if constraint.Expected != nil && *constraint.Expected != res.Quota {
unit := cluster.InfoForResource(srv.Type, res.Name).Unit
util.LogError(`expectation mismatch: %s/%s quota for domain %s should be %s, but is %s`,
srv.Type, res.Name, domain.Name,
limes.ValueWithUnit{Value: *constraint.Expected, Unit: unit},
limes.ValueWithUnit{Value: res.Quota, Unit: unit},
)
}
}
if len(resourcesToUpdate) > 0 {
onlyQuota := func(c *gorp.ColumnMap) bool {
Expand Down
21 changes: 16 additions & 5 deletions pkg/datamodel/project_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func ValidateProjectServices(tx *gorp.Transaction, cluster *limes.Cluster, domai
}

//valid service -> check whether the existing quota values violate any constraints
compliant, err := checkProjectResourcesAgainstConstraint(tx, srv, constraints[srv.Type])
compliant, err := checkProjectResourcesAgainstConstraint(tx, cluster, domain, project, srv, constraints[srv.Type])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func ValidateProjectServices(tx *gorp.Transaction, cluster *limes.Cluster, domai
return services, nil
}

func checkProjectResourcesAgainstConstraint(tx *gorp.Transaction, srv db.ProjectService, serviceConstraints map[string]limes.QuotaConstraint) (ok bool, err error) {
func checkProjectResourcesAgainstConstraint(tx *gorp.Transaction, cluster *limes.Cluster, domain db.Domain, project db.Project, srv db.ProjectService, serviceConstraints map[string]limes.QuotaConstraint) (ok bool, err error) {
//do not hit the database if there are no constraints to check
if len(serviceConstraints) == 0 {
return true, nil
Expand All @@ -139,10 +139,21 @@ func checkProjectResourcesAgainstConstraint(tx *gorp.Transaction, srv db.Project
return false, err
}

ok = true
for _, res := range resources {
if !serviceConstraints[res.Name].Allows(res.Quota) {
return false, nil
constraint := serviceConstraints[res.Name]
if !constraint.Allows(res.Quota) {
ok = false
}

if constraint.Expected != nil && *constraint.Expected != res.Quota {
unit := cluster.InfoForResource(srv.Type, res.Name).Unit
util.LogError(`expectation mismatch: %s/%s quota for project %s/%s should be %s, but is %s`,
srv.Type, res.Name, domain.Name, project.Name,
limes.ValueWithUnit{Value: *constraint.Expected, Unit: unit},
limes.ValueWithUnit{Value: res.Quota, Unit: unit},
)
}
}
return true, nil
return ok, nil
}

0 comments on commit f92b2c3

Please sign in to comment.