From 69773dce590bbf7ee748c2445c0781323abe0187 Mon Sep 17 00:00:00 2001 From: ColdsteelRail <574252631@qq.com> Date: Sat, 12 Oct 2024 10:01:19 +0800 Subject: [PATCH] still watch ignored pod --- config/manager/kustomization.yaml | 2 +- pkg/controllers/collaset/podcontrol/pod_control.go | 12 ++++++++++-- pkg/controllers/collaset/predicts.go | 9 ++++----- pkg/utils/common.go | 8 -------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 2e820674..e9617245 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: controller - newName: kusionstack/kuperator + newName: coldsteelrail/kusion-kuperator newTag: test diff --git a/pkg/controllers/collaset/podcontrol/pod_control.go b/pkg/controllers/collaset/podcontrol/pod_control.go index 0c3b1aa2..f6fe855b 100644 --- a/pkg/controllers/collaset/podcontrol/pod_control.go +++ b/pkg/controllers/collaset/podcontrol/pod_control.go @@ -24,10 +24,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime" + "kusionstack.io/kube-api/apps/v1alpha1" "sigs.k8s.io/controller-runtime/pkg/client" refmanagerutil "kusionstack.io/kuperator/pkg/controllers/utils/refmanager" - "kusionstack.io/kuperator/pkg/utils" "kusionstack.io/kuperator/pkg/utils/inject" ) @@ -136,7 +136,7 @@ func FilterOutIgnoredPod(pods []*corev1.Pod) []*corev1.Pod { var filteredPod []*corev1.Pod for i := range pods { - if utils.IgnoredByCollaSet(pods[i]) { + if IgnoredByCollaSet(pods[i]) { continue } @@ -144,3 +144,11 @@ func FilterOutIgnoredPod(pods []*corev1.Pod) []*corev1.Pod { } return filteredPod } + +func IgnoredByCollaSet(obj client.Object) bool { + if obj == nil || obj.GetLabels() == nil { + return false + } + _, ok := obj.GetLabels()[v1alpha1.PodIgnoringIndicationLabelKey] + return ok +} diff --git a/pkg/controllers/collaset/predicts.go b/pkg/controllers/collaset/predicts.go index 27a0a1e2..4b0b8cd7 100644 --- a/pkg/controllers/collaset/predicts.go +++ b/pkg/controllers/collaset/predicts.go @@ -27,21 +27,20 @@ type PodPredicate struct { // Create returns true if the Create event should be processed func (p *PodPredicate) Create(e event.CreateEvent) bool { - return utils.ControlledByKusionStack(e.Object) && !utils.IgnoredByCollaSet(e.Object) + return utils.ControlledByKusionStack(e.Object) } // Delete returns true if the Delete event should be processed func (p *PodPredicate) Delete(e event.DeleteEvent) bool { - return utils.ControlledByKusionStack(e.Object) && !utils.IgnoredByCollaSet(e.Object) + return utils.ControlledByKusionStack(e.Object) } // Update returns true if the Update event should be processed func (p *PodPredicate) Update(e event.UpdateEvent) bool { - return (utils.ControlledByKusionStack(e.ObjectNew) && !utils.IgnoredByCollaSet(e.ObjectNew)) || - (utils.ControlledByKusionStack(e.ObjectOld) && !utils.IgnoredByCollaSet(e.ObjectOld)) + return utils.ControlledByKusionStack(e.ObjectNew) || utils.ControlledByKusionStack(e.ObjectOld) } // Generic returns true if the Generic event should be processed func (p *PodPredicate) Generic(e event.GenericEvent) bool { - return utils.ControlledByKusionStack(e.Object) && !utils.IgnoredByCollaSet(e.Object) + return utils.ControlledByKusionStack(e.Object) } diff --git a/pkg/utils/common.go b/pkg/utils/common.go index b622909d..5fdc2225 100644 --- a/pkg/utils/common.go +++ b/pkg/utils/common.go @@ -47,11 +47,3 @@ func ControlByKusionStack(obj client.Object) { obj.GetLabels()[v1alpha1.ControlledByKusionStackLabelKey] = "true" } } - -func IgnoredByCollaSet(obj client.Object) bool { - if obj == nil || obj.GetLabels() == nil { - return false - } - _, ok := obj.GetLabels()[v1alpha1.PodIgnoringIndicationLabelKey] - return ok -}