Collectd Operator Unit Tests
[demo.git] / vnfs / DAaaS / microservices / collectd-operator / pkg / controller / utils / collectdutils.go
index 6a85103..1e73f69 100644 (file)
@@ -1,3 +1,16 @@
+/*
+Copyright 2019 Intel Corporation.
+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 (
@@ -5,6 +18,7 @@ import (
        "crypto/sha256"
        "fmt"
        "os"
+       "sort"
        "sync"
 
        "github.com/go-logr/logr"
@@ -30,6 +44,9 @@ const (
 
 var lock sync.Mutex
 
+// ReconcileLock - Used to sync between global and plugin controller
+var ReconcileLock sync.Mutex
+
 // ResourceMap to hold objects to update/reload
 type ResourceMap struct {
        ConfigMap       *corev1.ConfigMap
@@ -195,12 +212,19 @@ func RebuildCollectdConf(rc client.Client, ns string, isDelete bool, delPlugin s
                collectdConf += collectdGlobalConf
        }
 
-       for cpName, cpConf := range loadPlugin {
+       pluginKeys := make([]string, 0, len(loadPlugin))
+       for k := range loadPlugin {
+               pluginKeys = append(pluginKeys, k)
+       }
+       sort.Strings(pluginKeys)
+
+       for _, cpName := range pluginKeys {
+               cpConf := loadPlugin[cpName]
                collectdConf += "LoadPlugin" + " " + cpName + "\n"
                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
 }