mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-23 22:46:59 +00:00
* fix(controller): decode old object for delete requests Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * fix: preserve ca-bundles injected from external providers Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: abstract ruling Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api * feat: migrate events api --------- Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> Signed-off-by: Oliver Baehler <oliver@sudo-i.net>
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
// Copyright 2020-2026 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package cfg
|
|
|
|
import (
|
|
"context"
|
|
|
|
admissionv1 "k8s.io/api/admission/v1"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
|
|
|
capsulev1beta2 "github.com/projectcapsule/capsule/api/v1beta2"
|
|
"github.com/projectcapsule/capsule/pkg/runtime/events"
|
|
"github.com/projectcapsule/capsule/pkg/runtime/handlers"
|
|
)
|
|
|
|
type warningHandler struct{}
|
|
|
|
func WarningHandler() handlers.TypedHandler[*capsulev1beta2.CapsuleConfiguration] {
|
|
return &warningHandler{}
|
|
}
|
|
|
|
func (h *warningHandler) OnCreate(
|
|
_ client.Client,
|
|
_ client.Reader,
|
|
cfg *capsulev1beta2.CapsuleConfiguration,
|
|
decoder admission.Decoder,
|
|
_ events.EventRecorder,
|
|
) handlers.Func {
|
|
return func(_ context.Context, req admission.Request) *admission.Response {
|
|
return h.handle(cfg, req)
|
|
}
|
|
}
|
|
|
|
func (h *warningHandler) OnDelete(
|
|
client.Client,
|
|
client.Reader,
|
|
*capsulev1beta2.CapsuleConfiguration,
|
|
admission.Decoder,
|
|
events.EventRecorder,
|
|
) handlers.Func {
|
|
return func(context.Context, admission.Request) *admission.Response {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (h *warningHandler) OnUpdate(
|
|
_ client.Client,
|
|
_ client.Reader,
|
|
cfg *capsulev1beta2.CapsuleConfiguration,
|
|
_ *capsulev1beta2.CapsuleConfiguration,
|
|
decoder admission.Decoder,
|
|
_ events.EventRecorder,
|
|
) handlers.Func {
|
|
return func(_ context.Context, req admission.Request) *admission.Response {
|
|
return h.handle(cfg, req)
|
|
}
|
|
}
|
|
|
|
func (h *warningHandler) handle(config *capsulev1beta2.CapsuleConfiguration, req admission.Request) *admission.Response {
|
|
response := &admission.Response{
|
|
AdmissionResponse: admissionv1.AdmissionResponse{
|
|
UID: req.UID,
|
|
Allowed: true,
|
|
},
|
|
}
|
|
|
|
//nolint:staticcheck
|
|
if len(config.Spec.UserGroups) > 0 {
|
|
response.Warnings = append(response.Warnings,
|
|
"The field `userGroups` is deprecated and will be removed in a future release. Please migrate to the `users` field. See: https://projectcapsule.dev/docs/operating/setup/configuration/#users.",
|
|
)
|
|
}
|
|
|
|
//nolint:staticcheck
|
|
if len(config.Spec.UserNames) > 0 {
|
|
response.Warnings = append(response.Warnings,
|
|
"The field `userNames` is deprecated and will be removed in a future release. Please migrate to the `users` field. See: https://projectcapsule.dev/docs/operating/setup/configuration/#users.",
|
|
)
|
|
}
|
|
|
|
return response
|
|
}
|