Files
capsule/pkg/webhook/service/errors.go
Oliver Bähler 3682283352 chore: add license headers (#1504)
* chore: add nwa

Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>

* chore: update helm-schema version

Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>

* chore: update helm-schema version

Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>

---------

Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
2025-06-13 07:31:04 +02:00

66 lines
1.6 KiB
Go

// Copyright 2020-2025 Project Capsule Authors
// SPDX-License-Identifier: Apache-2.0
package service
import (
"fmt"
"strings"
"github.com/projectcapsule/capsule/pkg/api"
)
type externalServiceIPForbiddenError struct {
cidr []string
}
func NewExternalServiceIPForbidden(allowedIps []api.AllowedIP) error {
cidr := make([]string, 0, len(allowedIps))
for _, i := range allowedIps {
cidr = append(cidr, string(i))
}
return &externalServiceIPForbiddenError{
cidr: cidr,
}
}
func (e externalServiceIPForbiddenError) Error() string {
if len(e.cidr) == 0 {
return "The current Tenant does not allow the use of Service with external IPs"
}
return fmt.Sprintf("The selected external IPs for the current Service are violating the following enforced CIDRs: %s", strings.Join(e.cidr, ", "))
}
type nodePortDisabledError struct{}
func NewNodePortDisabledError() error {
return &nodePortDisabledError{}
}
func (nodePortDisabledError) Error() string {
return "NodePort service types are forbidden for the tenant: please, reach out to the system administrators"
}
type externalNameDisabledError struct{}
func NewExternalNameDisabledError() error {
return &externalNameDisabledError{}
}
func (externalNameDisabledError) Error() string {
return "ExternalName service types are forbidden for the tenant: please, reach out to the system administrators"
}
type loadBalancerDisabledError struct{}
func NewLoadBalancerDisabled() error {
return &loadBalancerDisabledError{}
}
func (loadBalancerDisabledError) Error() string {
return "LoadBalancer service types are forbidden for the tenant: please, reach out to the system administrators"
}