mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-25 16:07:24 +00:00
feat: upstream enterprise preview --------- Signed-off-by: Oliver Baehler <oliver@sudo-i.net> Co-authored-by: CorentinPtrl <pitrel.corentin@gmail.com>
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
// Copyright 2020-2026 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package generic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"k8s.io/client-go/tools/events"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
|
|
|
ad "github.com/projectcapsule/capsule/pkg/runtime/admission"
|
|
"github.com/projectcapsule/capsule/pkg/runtime/configuration"
|
|
"github.com/projectcapsule/capsule/pkg/runtime/handlers"
|
|
)
|
|
|
|
type cordoningHandler struct{}
|
|
|
|
func CordoningHandler(configuration configuration.Configuration) handlers.Handler {
|
|
return &cordoningHandler{}
|
|
}
|
|
|
|
func (h *cordoningHandler) OnCreate(
|
|
_ client.Client,
|
|
_ client.Reader,
|
|
_ admission.Decoder,
|
|
_ events.EventRecorder,
|
|
) handlers.Func {
|
|
return func(ctx context.Context, req admission.Request) *admission.Response {
|
|
return h.cordonHandler(req)
|
|
}
|
|
}
|
|
|
|
func (h *cordoningHandler) OnDelete(
|
|
_ client.Client,
|
|
_ client.Reader,
|
|
_ admission.Decoder,
|
|
recorder events.EventRecorder,
|
|
) handlers.Func {
|
|
return func(ctx context.Context, req admission.Request) *admission.Response {
|
|
return h.cordonHandler(req)
|
|
}
|
|
}
|
|
|
|
func (h *cordoningHandler) OnUpdate(
|
|
_ client.Client,
|
|
_ client.Reader,
|
|
_ admission.Decoder,
|
|
recorder events.EventRecorder,
|
|
) handlers.Func {
|
|
return func(ctx context.Context, req admission.Request) *admission.Response {
|
|
return h.cordonHandler(req)
|
|
}
|
|
}
|
|
|
|
func (h *cordoningHandler) cordonHandler(req admission.Request) *admission.Response {
|
|
return ad.Deny(fmt.Sprintf("The current namespace '%s' is cordoned. The attempted operation %s for %s/%s/%s/%s is not permitted during cordoning status.", req.Namespace, req.Operation, req.RequestKind.Group, req.RequestKind.Version, req.RequestKind.Kind, req.Name))
|
|
}
|