mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-05-07 01:46:39 +00:00
* fix(makefile): no need specifying ginkgo version Signed-off-by: Dario Tranchitella <dario@tranchitella.eu> * fix(chore): referring to make using shortcut Signed-off-by: Dario Tranchitella <dario@tranchitella.eu> * feat: default runtimeclass webhook Signed-off-by: Dario Tranchitella <dario@tranchitella.eu> * feat(helm): default runtimeclass spec Signed-off-by: Dario Tranchitella <dario@tranchitella.eu> --------- Signed-off-by: Dario Tranchitella <dario@tranchitella.eu>
40 lines
986 B
Go
40 lines
986 B
Go
// Copyright 2020-2023 Project Capsule Authors.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
|
|
|
"github.com/projectcapsule/capsule/pkg/api"
|
|
)
|
|
|
|
func ErroredResponse(err error) *admission.Response {
|
|
response := admission.Errored(http.StatusInternalServerError, err)
|
|
|
|
return &response
|
|
}
|
|
|
|
func DefaultAllowedValuesErrorMessage(allowed api.DefaultAllowedListSpec, err string) string {
|
|
var extra []string
|
|
if len(allowed.Exact) > 0 {
|
|
extra = append(extra, fmt.Sprintf("use one from the following list (%s)", strings.Join(allowed.Exact, ", ")))
|
|
}
|
|
|
|
if len(allowed.Regex) > 0 {
|
|
extra = append(extra, fmt.Sprintf("use one matching the following regex (%s)", allowed.Regex))
|
|
}
|
|
|
|
if len(allowed.MatchLabels) > 0 || len(allowed.MatchExpressions) > 0 {
|
|
extra = append(extra, "matching the label selector defined in the Tenant")
|
|
}
|
|
|
|
err += strings.Join(extra, " or ")
|
|
|
|
return err
|
|
}
|