1 // Copyright 2018 The Operator-SDK Authors
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
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
18 appsv1 "k8s.io/api/apps/v1"
20 "sigs.k8s.io/controller-runtime/pkg/event"
21 "sigs.k8s.io/controller-runtime/pkg/predicate"
22 logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
25 var plog = logf.Log.WithName("predicate").WithName("eventFilters")
27 // DaemonSetStatusChangedPredicate implements a default update predicate function on status change for Daemonsets
28 // (adapted from sigs.k8s.io/controller-runtime/pkg/predicate/predicate.GenerationChangedPredicate)
29 type DaemonSetStatusChangedPredicate struct {
33 // Update implements default UpdateEvent filter for validating generation change
34 func (DaemonSetStatusChangedPredicate) Update(e event.UpdateEvent) bool {
35 newDS := e.ObjectNew.DeepCopyObject().(*appsv1.DaemonSet)
36 oldDS := e.ObjectOld.DeepCopyObject().(*appsv1.DaemonSet)
37 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)
38 if newDS.Status.UpdatedNumberScheduled >= oldDS.Status.UpdatedNumberScheduled {
39 if (newDS.Status.UpdatedNumberScheduled == newDS.Status.NumberReady) &&
40 (newDS.Status.UpdatedNumberScheduled == newDS.Status.NumberAvailable) {
45 plog.Error(nil, "Update event has no old metadata", "event", e)
48 if e.ObjectOld == nil {
49 plog.Error(nil, "Update event has no old runtime object to update", "event", e)
52 if e.ObjectNew == nil {
53 plog.Error(nil, "Update event has no new runtime object for update", "event", e)
57 plog.Error(nil, "Update event has no new metadata", "event", e)
60 if e.MetaNew.GetGeneration() == e.MetaOld.GetGeneration() {