aboutsummaryrefslogtreecommitdiffstats
path: root/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go
diff options
context:
space:
mode:
authorDileep Ranganathan <dileep.ranganathan@intel.com>2019-09-05 21:46:59 -0700
committerMarco Platania <platania@research.att.com>2019-09-06 12:45:28 +0000
commitb2651f39b6dbe79e05d42f8a3bfbbc11c42c5d4c (patch)
treede00fc8fac262ffcfa8b3f8f50dba70a1cfd3264 /vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go
parentfb00a06a25dda69958891705c7c18ddddfea25f9 (diff)
Fix issue with concurrent CR creation
The collectd operator is going into deadlock when concurrent update operations happen within the same controller trying to update the resource. Fixed this by adding Mutex. Deleted the old build_image.sh which is replaced by new script which builds and pushes from inside a builder docker container. This helps in tackling the dependency issues for image build. Updated the README for build image script usage. Issue-ID: ONAPARC-461 Signed-off-by: Dileep Ranganathan <dileep.ranganathan@intel.com> Change-Id: Ib3c2d1edd266e70bb713885de7ad046ebf5ad086
Diffstat (limited to 'vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go')
-rw-r--r--vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go56
1 files changed, 22 insertions, 34 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 95604835..6a85103c 100644
--- a/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go
+++ b/vnfs/DAaaS/microservices/collectd-operator/pkg/controller/utils/collectdutils.go
@@ -72,14 +72,28 @@ func GetWatchLabels() (string, error) {
return labelSelector, nil
}
-// FindResourceMapForCR returns the configMap, collectd Daemonset and list of Collectd Plugins
-func FindResourceMapForCR(rc client.Client, reqLogger logr.Logger, ns string) (*ResourceMap, error) {
+// GetCollectdPluginList returns the list of CollectdPlugin instances in the namespace ns
+func GetCollectdPluginList(rc client.Client, ns string) (*onapv1alpha1.CollectdPluginList, error) {
+ // Get all collectd plugins in the current namespace to rebuild conf.
+ collectdPlugins := &onapv1alpha1.CollectdPluginList{}
+ cpOpts := &client.ListOptions{}
+ cpOpts.InNamespace(ns)
+ err := rc.List(context.TODO(), cpOpts, collectdPlugins)
+ if err != nil {
+ return nil, err
+ }
+ return collectdPlugins, nil
+}
+
+// GetConfigMap returns the GetConfigMap in the namespace ns
+func GetConfigMap(rc client.Client, reqLogger logr.Logger, ns string) (*corev1.ConfigMap, error) {
lock.Lock()
defer lock.Unlock()
+
+ reqLogger.Info("Get ConfigMap for collectd.conf")
+ // Get all collectd plugins in the current namespace to rebuild conf.
cmList := &corev1.ConfigMapList{}
opts := &client.ListOptions{}
- rmap := &ResourceMap{}
-
// Select ConfigMaps with label
labelSelector, err := GetWatchLabels()
if err != nil {
@@ -90,41 +104,15 @@ func FindResourceMapForCR(rc client.Client, reqLogger logr.Logger, ns string) (*
err = rc.List(context.TODO(), opts, cmList)
if err != nil {
- return rmap, err
+ return nil, err
}
if cmList.Items == nil || len(cmList.Items) == 0 {
- return rmap, errors.NewNotFound(corev1.Resource("configmap"), "ConfigMap")
- }
-
- // Select DaemonSets with label
- dsList := &appsv1.DaemonSetList{}
- err = rc.List(context.TODO(), opts, dsList)
- if err != nil {
- return rmap, err
+ return nil, errors.NewNotFound(corev1.Resource("configmap"), "ConfigMap")
}
- if dsList.Items == nil || len(dsList.Items) == 0 {
- return rmap, errors.NewNotFound(corev1.Resource("daemonset"), "DaemonSet")
- }
-
- rmap.ConfigMap = &cmList.Items[0]
- rmap.DaemonSet = &dsList.Items[0]
-
- return rmap, err
-}
-
-// GetCollectdPluginList returns the list of CollectdPlugin instances in the namespace ns
-func GetCollectdPluginList(rc client.Client, ns string) (*onapv1alpha1.CollectdPluginList, error) {
- // Get all collectd plugins in the current namespace to rebuild conf.
- collectdPlugins := &onapv1alpha1.CollectdPluginList{}
- cpOpts := &client.ListOptions{}
- cpOpts.InNamespace(ns)
- err := rc.List(context.TODO(), cpOpts, collectdPlugins)
- if err != nil {
- return nil, err
- }
- return collectdPlugins, nil
+ cm := &cmList.Items[0]
+ return cm, nil
}
// GetCollectdGlobal returns the CollectdGlobal instance in the namespace ns