diff options
Diffstat (limited to 'vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils')
-rw-r--r-- | vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go | 2 | ||||
-rw-r--r-- | vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/predicate.go | 65 |
2 files changed, 66 insertions, 1 deletions
diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go index 17cad0e5..b379d916 100644 --- a/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go +++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go @@ -211,7 +211,7 @@ func RebuildCollectdConf(rc client.Client, ns string, isDelete bool, delPlugin s collectdConf += cpConf + "\n" } - collectdConf += "#Last line (collectd requires ā\\nā at the last line)\n" + collectdConf += "#Last line (collectd requires '\\n' at the last line)\n" return collectdConf, nil } diff --git a/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/predicate.go b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/predicate.go new file mode 100644 index 00000000..a9ec1dc4 --- /dev/null +++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/predicate.go @@ -0,0 +1,65 @@ +// Copyright 2018 The Operator-SDK Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package utils + +import ( + appsv1 "k8s.io/api/apps/v1" + + "sigs.k8s.io/controller-runtime/pkg/event" + "sigs.k8s.io/controller-runtime/pkg/predicate" + logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" +) + +var plog = logf.Log.WithName("predicate").WithName("eventFilters") + +// DaemonSetStatusChangedPredicate implements a default update predicate function on status change for Daemonsets +// (adapted from sigs.k8s.io/controller-runtime/pkg/predicate/predicate.GenerationChangedPredicate) +type DaemonSetStatusChangedPredicate struct { + predicate.Funcs +} + +// Update implements default UpdateEvent filter for validating generation change +func (DaemonSetStatusChangedPredicate) Update(e event.UpdateEvent) bool { + newDS := e.ObjectNew.DeepCopyObject().(*appsv1.DaemonSet) + oldDS := e.ObjectOld.DeepCopyObject().(*appsv1.DaemonSet) + 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) + if newDS.Status.UpdatedNumberScheduled >= oldDS.Status.UpdatedNumberScheduled { + if (newDS.Status.UpdatedNumberScheduled == newDS.Status.NumberReady) && + (newDS.Status.UpdatedNumberScheduled == newDS.Status.NumberAvailable) { + return true + } + } + if e.MetaOld == nil { + plog.Error(nil, "Update event has no old metadata", "event", e) + return false + } + if e.ObjectOld == nil { + plog.Error(nil, "Update event has no old runtime object to update", "event", e) + return false + } + if e.ObjectNew == nil { + plog.Error(nil, "Update event has no new runtime object for update", "event", e) + return false + } + if e.MetaNew == nil { + plog.Error(nil, "Update event has no new metadata", "event", e) + return false + } + if e.MetaNew.GetGeneration() == e.MetaOld.GetGeneration() { + return false + } + + return true +} |