Fix the Collectd operator panic issue 70/89770/1
authorDileep Ranganathan <dileep.ranganathan@intel.com>
Mon, 10 Jun 2019 21:23:15 +0000 (14:23 -0700)
committerDileep Ranganathan <dileep.ranganathan@intel.com>
Thu, 13 Jun 2019 04:18:47 +0000 (21:18 -0700)
Fixed the panic issue as the daemonset was used instead of
DaemonsetList. Improved the logging to get data from configmap.
Filters used to query ConfigMap was wrong.

Issue-ID: OPTFRA-461
Signed-off-by: Dileep Ranganathan <dileep.ranganathan@intel.com>
Change-Id: I14807f7b254ccc0636b5cef6d58b4b6cc0c0e375

vnfs/DAaaS/microservices/collectd-operator/Makefile
vnfs/DAaaS/microservices/collectd-operator/deploy/crds/cpu_collectdplugin_cr.yaml [moved from vnfs/DAaaS/microservices/collectd-operator/deploy/crds/onap_v1alpha1_collectdplugin_cr.yaml with 66% similarity]
vnfs/DAaaS/microservices/collectd-operator/deploy/crds/memory_collectdplugin_cr.yaml [new file with mode: 0644]
vnfs/DAaaS/microservices/collectd-operator/deploy/operator.yaml
vnfs/DAaaS/microservices/collectd-operator/deploy/role_binding.yaml
vnfs/DAaaS/microservices/collectd-operator/pkg/controller/collectdplugin/collectdplugin_controller.go

index 0b07b4b..e3269b4 100644 (file)
@@ -13,16 +13,16 @@ BUILD := $(shell git rev-parse --short HEAD)
 PROJECTNAME := $(shell basename "$(PWD)")
 
 GOPATH := $(shell realpath "$(PWD)/../../../../../../")
-COP = ${PWD}/build/_output/bin/collectd-operator
-IMAGE_NAME = dcr.cluster.local/collectd-operator:latest
+COP := ${PWD}/build/_output/bin/collectd-operator
+IMAGE_NAME := collectd-operator:latest
 
 export GOPATH ...
 export GO111MODULE=on
 
 .PHONY: clean plugins
 
-## all: Generate the k8s and openapi artifacts using operator-sdk
-all: clean vendor
+## build: Generate the k8s and openapi artifacts using operator-sdk
+build: clean vendor
        GOOS=linux GOARCH=amd64
        operator-sdk generate k8s --verbose
        operator-sdk generate openapi --verbose
@@ -33,8 +33,8 @@ all: clean vendor
 # no need to create a static binary with additional flags. However, for generating binary, additional build flags are necessary. This if used with
 # mock plugin errors out for unit tests. So the seperation avoids the error.
 
-## build: clean the
-build: clean test cover
+## all: Delete the image, binary, complete build, test and run coverage
+all: build test cover
 deploy: build publish
 vendor:
        @go mod vendor
@@ -1,10 +1,14 @@
 apiVersion: onap.org/v1alpha1
 kind: CollectdPlugin
 metadata:
-  name: example-collectdplugin
+  name: cpu
 spec:
   # Add fields here
   pluginName: "cpu"
   pluginConf: |
     <Plugin "cpu">
+      Interval 5
+      ReportByState false
+      ReportByCpu false
     </Plugin>
\ No newline at end of file
diff --git a/vnfs/DAaaS/microservices/collectd-operator/deploy/crds/memory_collectdplugin_cr.yaml b/vnfs/DAaaS/microservices/collectd-operator/deploy/crds/memory_collectdplugin_cr.yaml
new file mode 100644 (file)
index 0000000..ee051ed
--- /dev/null
@@ -0,0 +1,14 @@
+apiVersion: onap.org/v1alpha1
+kind: CollectdPlugin
+metadata:
+  name: memory
+spec:
+  # Add fields here
+  pluginName: "memory"
+  pluginConf: |
+    <Plugin "memory">
+      Interval 30
+      ValuesAbsolute false
+      ValuesPercentage true
+    </Plugin>
\ No newline at end of file
index 108719a..b39543e 100644 (file)
@@ -16,7 +16,7 @@ spec:
       containers:
         - name: collectd-operator
           # Replace this with the built image name
-          image: dcr.cluster.local:31976/collectd-operator:latest
+          image: dcr.cluster.local:32644/collectd-operator:latest
           command:
           - collectd-operator
           imagePullPolicy: Always
index 5f42508..09da292 100644 (file)
@@ -5,6 +5,7 @@ metadata:
 subjects:
 - kind: ServiceAccount
   name: collectd-operator
+  namespace: cop
 roleRef:
   kind: ClusterRole
   name: collectd-operator
index fd35c6f..5298258 100644 (file)
@@ -136,14 +136,14 @@ func (r *ReconcileCollectdPlugin) Reconcile(request reconcile.Request) (reconcil
        if err := controllerutil.SetControllerReference(instance, cm, r.scheme); err != nil {
                return reconcile.Result{}, err
        }
-       // Set CollectdConf instance as the owner and controller
+       // Set CollectdPlugin instance as the owner and controller
        if err := controllerutil.SetControllerReference(instance, ds, r.scheme); err != nil {
                return reconcile.Result{}, err
        }
 
        // Update the ConfigMap with new Spec and reload DaemonSets
        reqLogger.Info("Updating the ConfigMap", "ConfigMap.Namespace", cm.Namespace, "ConfigMap.Name", cm.Name)
-       log.Info("Map: ", cm.Data)
+       log.Info("ConfigMap Data", "Map: ", cm.Data)
        err = r.client.Update(context.TODO(), cm)
        if err != nil {
                return reconcile.Result{}, err
@@ -180,14 +180,14 @@ func findResourceMapForCR(r *ReconcileCollectdPlugin, cr *onapv1alpha1.CollectdP
        }
 
        // Select DaemonSets with label app=collectd
-       dsList := &extensionsv1beta1.DaemonSet{}
+       dsList := &extensionsv1beta1.DaemonSetList{}
        err = r.client.List(context.TODO(), opts, dsList)
        if err != nil {
                return rmap, err
        }
 
        rmap.configMap = &cmList.Items[0]
-       rmap.daemonSet = dsList
+       rmap.daemonSet = &dsList.Items[0]
        return rmap, err
 }