mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-05-21 16:52:51 +00:00
* feat(controllers): add concurrency * feat(controller): add workers flag Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore(deps): update actions/upload-artifact action to v5 (#1721) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore(deps): update github/codeql-action action to v4.31.0 (#1720) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: satisfy linter Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: use serviceaccount parsing Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * fix(deps): update module github.com/onsi/ginkgo/v2 to v2.27.1 (#1714) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore(deps): update github/codeql-action digest to ae78991 (#1719) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: use serviceaccount parsing Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: use serviceaccount parsing Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> --------- Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
// Copyright 2020-2025 Project Capsule Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package tenant
|
|
|
|
import (
|
|
"context"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
"k8s.io/apimachinery/pkg/labels"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/apimachinery/pkg/selection"
|
|
"k8s.io/client-go/util/retry"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
|
|
"github.com/projectcapsule/capsule/pkg/utils"
|
|
)
|
|
|
|
// pruningResources is taking care of removing the no more requested sub-resources as LimitRange, ResourceQuota or
|
|
// NetworkPolicy using the "exists" and "notin" LabelSelector to perform an outer-join removal.
|
|
func (r *Manager) pruningResources(ctx context.Context, ns string, keys []string, obj client.Object) (err error) {
|
|
var capsuleLabel string
|
|
|
|
if capsuleLabel, err = utils.GetTypeLabel(obj); err != nil {
|
|
return err
|
|
}
|
|
|
|
selector := labels.NewSelector()
|
|
|
|
var exists *labels.Requirement
|
|
|
|
if exists, err = labels.NewRequirement(capsuleLabel, selection.Exists, []string{}); err != nil {
|
|
return err
|
|
}
|
|
|
|
selector = selector.Add(*exists)
|
|
|
|
if len(keys) > 0 {
|
|
var notIn *labels.Requirement
|
|
|
|
if notIn, err = labels.NewRequirement(capsuleLabel, selection.NotIn, keys); err != nil {
|
|
return err
|
|
}
|
|
|
|
selector = selector.Add(*notIn)
|
|
}
|
|
|
|
r.Log.V(3).Info("Pruning objects with label selector " + selector.String())
|
|
|
|
return retry.RetryOnConflict(retry.DefaultBackoff, func() error {
|
|
return r.DeleteAllOf(ctx, obj, &client.DeleteAllOfOptions{
|
|
ListOptions: client.ListOptions{
|
|
LabelSelector: selector,
|
|
Namespace: ns,
|
|
},
|
|
DeleteOptions: client.DeleteOptions{},
|
|
})
|
|
})
|
|
}
|
|
|
|
func (r *Manager) emitEvent(object runtime.Object, namespace string, res controllerutil.OperationResult, msg string, err error) {
|
|
eventType := corev1.EventTypeNormal
|
|
|
|
if err != nil {
|
|
eventType = corev1.EventTypeWarning
|
|
res = "Error"
|
|
}
|
|
|
|
r.Recorder.AnnotatedEventf(object, map[string]string{"OperationResult": string(res)}, eventType, namespace, msg)
|
|
}
|