2 Copyright 2019 Intel Corporation.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software
8 distributed under the License is distributed on an "AS IS" BASIS,
9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 See the License for the specific language governing permissions and
11 limitations under the License.
17 appsv1 "k8s.io/api/apps/v1"
19 "sigs.k8s.io/controller-runtime/pkg/event"
20 "sigs.k8s.io/controller-runtime/pkg/predicate"
21 logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
24 var plog = logf.Log.WithName("predicate").WithName("eventFilters")
26 // DaemonSetStatusChangedPredicate implements a default update predicate function on status change for Daemonsets
27 // (adapted from sigs.k8s.io/controller-runtime/pkg/predicate/predicate.GenerationChangedPredicate)
28 type DaemonSetStatusChangedPredicate struct {
32 // Update implements default UpdateEvent filter for validating generation change
33 func (DaemonSetStatusChangedPredicate) Update(e event.UpdateEvent) bool {
34 newDS := e.ObjectNew.DeepCopyObject().(*appsv1.DaemonSet)
35 oldDS := e.ObjectOld.DeepCopyObject().(*appsv1.DaemonSet)
36 plog.V(2).Info("newDS", "nUNS:=", newDS.Status.UpdatedNumberScheduled, "oUNS:=", oldDS.Status.UpdatedNumberScheduled, "nDNS:=", newDS.Status.DesiredNumberScheduled, "nNR:=", newDS.Status.NumberReady, "nNA:=", newDS.Status.NumberAvailable)
37 if newDS.Status.UpdatedNumberScheduled >= oldDS.Status.UpdatedNumberScheduled {
38 if (newDS.Status.UpdatedNumberScheduled == newDS.Status.NumberReady) &&
39 (newDS.Status.UpdatedNumberScheduled == newDS.Status.NumberAvailable) {
44 plog.Error(nil, "Update event has no old metadata", "event", e)
47 if e.ObjectOld == nil {
48 plog.Error(nil, "Update event has no old runtime object to update", "event", e)
51 if e.ObjectNew == nil {
52 plog.Error(nil, "Update event has no new runtime object for update", "event", e)
56 plog.Error(nil, "Update event has no new metadata", "event", e)
59 if e.MetaNew.GetGeneration() == e.MetaOld.GetGeneration() {