Files
capsule/pkg/meta/labels.go
T
Oliver BählerandGitHub 5ac0f83c5a feat(controller): refactor namespace core loop and state management (#1680)
* feat(controller): allow owners to promote serviceaccounts within tenant as owners

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

* feat(controller): refactor status handling for tenants and owned namespaces (including metrics)

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

---------

Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com>
2025-10-06 08:19:26 +02:00

60 lines
1.3 KiB
Go

// Copyright 2020-2025 Project Capsule Authors
// SPDX-License-Identifier: Apache-2.0
package meta
import (
"strings"
"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
FreezeLabel = "projectcapsule.dev/freeze"
FreezeLabelTrigger = "true"
OwnerPromotionLabel = "owner.projectcapsule.dev/promote"
OwnerPromotionLabelTrigger = "true"
CordonedLabel = "projectcapsule.dev/cordoned"
CordonedLabelTrigger = "true"
)
func FreezeLabelTriggers(obj client.Object) bool {
return labelTriggers(obj, FreezeLabel, FreezeLabelTrigger)
}
func FreezeLabelRemove(obj client.Object) {
labelRemove(obj, FreezeLabel)
}
func OwnerPromotionLabelTriggers(obj client.Object) bool {
return labelTriggers(obj, OwnerPromotionLabel, OwnerPromotionLabelTrigger)
}
func OwnerPromotionLabelRemove(obj client.Object) {
labelRemove(obj, OwnerPromotionLabel)
}
func labelRemove(obj client.Object, anno string) {
annotations := obj.GetLabels()
if _, ok := annotations[anno]; ok {
delete(annotations, anno)
obj.SetLabels(annotations)
}
}
func labelTriggers(obj client.Object, anno string, trigger string) bool {
annotations := obj.GetLabels()
if val, ok := annotations[anno]; ok {
if strings.ToLower(val) == trigger {
return true
}
}
return false
}