mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-19 04:26:45 +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>
83 lines
1.8 KiB
Go
83 lines
1.8 KiB
Go
// Copyright 2020-2026 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package tenant
|
|
|
|
import (
|
|
corev1 "k8s.io/api/core/v1"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
capsulev1beta2 "github.com/projectcapsule/capsule/api/v1beta2"
|
|
"github.com/projectcapsule/capsule/pkg/runtime/sanitize"
|
|
"github.com/projectcapsule/capsule/pkg/utils"
|
|
)
|
|
|
|
// NewTenantContext returns the context for the tenant.
|
|
func NewTenantContext(tnt *capsulev1beta2.Tenant, scheme *runtime.Scheme, opts sanitize.SanitizeOptions) (map[string]any, error) {
|
|
if err := sanitize.SanitizeObject(tnt, scheme, opts); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
context, err := utils.ToUnstructuredMap(tnt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
context["rbac"] = tnt.GetClusterRolesBySubject(nil)
|
|
|
|
return context, nil
|
|
}
|
|
|
|
// NewTenantNamespaceContext returns the context for the tenant and a given namespace.
|
|
func NewTenantNamespaceContext(
|
|
tnt *capsulev1beta2.Tenant,
|
|
ns *corev1.Namespace,
|
|
scheme *runtime.Scheme,
|
|
opts sanitize.SanitizeOptions,
|
|
) (map[string]any, error) {
|
|
context := make(map[string]any)
|
|
|
|
if tnt != nil {
|
|
tntCopy := tnt.DeepCopy()
|
|
|
|
tCtx, err := NewTenantContext(tntCopy, scheme, opts)
|
|
if err != nil {
|
|
return context, err
|
|
}
|
|
|
|
context["tenant"] = tCtx
|
|
}
|
|
|
|
if ns != nil {
|
|
nsCopy := ns.DeepCopy()
|
|
|
|
if err := sanitize.SanitizeObject(nsCopy, scheme, opts); err != nil {
|
|
return context, err
|
|
}
|
|
|
|
nsMap, err := utils.ToUnstructuredMap(nsCopy)
|
|
if err != nil {
|
|
return context, err
|
|
}
|
|
|
|
context["namespace"] = nsMap
|
|
}
|
|
|
|
return context, nil
|
|
}
|
|
|
|
// TemplateForTenantAndNamespace applies templatingto the provided string.
|
|
func FastContextForTenantAndNamespace(tnt *capsulev1beta2.Tenant, ns *corev1.Namespace) map[string]string {
|
|
values := map[string]string{}
|
|
|
|
if tnt != nil {
|
|
values["tenant.name"] = tnt.Name
|
|
}
|
|
|
|
if ns != nil {
|
|
values["namespace"] = ns.Name
|
|
}
|
|
|
|
return values
|
|
}
|