mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-05-17 23:06:37 +00:00
* chore(refactor): project and api refactoring Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore(refactor): project and api refactoring Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> --------- Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
43 lines
836 B
Go
43 lines
836 B
Go
// Copyright 2020-2025 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package namespace
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
"github.com/projectcapsule/capsule/pkg/utils/tenant"
|
|
)
|
|
|
|
type OwnerReference struct{}
|
|
|
|
func (o OwnerReference) Object() client.Object {
|
|
return &corev1.Namespace{}
|
|
}
|
|
|
|
func (o OwnerReference) Field() string {
|
|
return ".metadata.ownerReferences[*].capsule"
|
|
}
|
|
|
|
func (o OwnerReference) Func() client.IndexerFunc {
|
|
return func(object client.Object) []string {
|
|
res := []string{}
|
|
ns, ok := object.(*corev1.Namespace)
|
|
|
|
if !ok {
|
|
panic(fmt.Errorf("expected *corev1.Namespace, got %T", ns))
|
|
}
|
|
|
|
for _, or := range ns.OwnerReferences {
|
|
if tenant.IsTenantOwnerReference(or) {
|
|
res = append(res, or.Name)
|
|
}
|
|
}
|
|
|
|
return res
|
|
}
|
|
}
|