Skip to content

Commit

Permalink
use better error for lack of the team label
Browse files Browse the repository at this point in the history
  • Loading branch information
hoptical committed Feb 3, 2024
1 parent 9c465d4 commit 6b0ba6f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/quota_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func findTeam(ctx context.Context, runtimeClient client.Client, suc *S3UserClaim

team, ok := ns.ObjectMeta.Labels[consts.LabelTeam]
if !ok {
return "", fmt.Errorf("namespace %s doesn't have team label", ns.ObjectMeta.Name)
return "", fmt.Errorf("namespace %s doesn't have the team label: %s", ns.ObjectMeta.Name, consts.LabelTeam)
}

return team, nil
Expand Down
6 changes: 2 additions & 4 deletions api/v1alpha1/s3userclaim_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ func validateQuota(suc *S3UserClaim, allErrs field.ErrorList) field.ErrorList {
case err == consts.ErrExceededNamespaceQuota:
allErrs = append(allErrs, field.Forbidden(quotaFieldPath, err.Error()))
case err != nil:
s3userclaimlog.Error(err, "failed to validate against cluster quota")
allErrs = append(allErrs, field.InternalError(quotaFieldPath, fmt.Errorf(consts.ContactCloudTeamErrMessage)))
allErrs = append(allErrs, field.InternalError(quotaFieldPath, fmt.Errorf("failed to validate against cluster quota, %w", err)))
}

switch err := validateAgainstClusterQuota(ctx, suc); {
Expand All @@ -162,8 +161,7 @@ func validateQuota(suc *S3UserClaim, allErrs field.ErrorList) field.ErrorList {
case goerrors.Is(err, consts.ErrClusterQuotaNotDefined):
allErrs = append(allErrs, field.Forbidden(quotaFieldPath, err.Error()))
case err != nil:
s3userclaimlog.Error(err, "failed to validate against cluster quota")
allErrs = append(allErrs, field.InternalError(quotaFieldPath, fmt.Errorf(consts.ContactCloudTeamErrMessage)))
allErrs = append(allErrs, field.InternalError(quotaFieldPath, fmt.Errorf("failed to validate against cluster quota, %w", err)))
}
return allErrs
}
Expand Down
1 change: 0 additions & 1 deletion pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const (
S3UserClassImmutableErrMessage = "s3UserClass is immutable"
S3UserRefImmutableErrMessage = "s3UserRef is immutable"
S3UserRefNotFoundErrMessage = "there is no s3UserClaim regarding the defined s3UserRef"
ContactCloudTeamErrMessage = "please contact the cloud team"

FinalizerPrefix = "s3.snappcloud.io/"
S3UserClaimCleanupFinalizer = FinalizerPrefix + "cleanup-s3userclaim"
Expand Down

0 comments on commit 6b0ba6f

Please sign in to comment.