-// ComputeSHA256 returns hash of data as string
-func ComputeSHA256(data []byte) string {
- hash := sha256.Sum256(data)
- return fmt.Sprintf("%x", hash)
-}
-
-// findResourceMapForCR returns the configMap, collectd Daemonset and list of Collectd Plugins
-func (r *ReconcileCollectdPlugin) findResourceMapForCR(cr *onapv1alpha1.CollectdPlugin) (ResourceMap, error) {
- cmList := &corev1.ConfigMapList{}
- opts := &client.ListOptions{}
- rmap := ResourceMap{}
-
- // Select ConfigMaps with label app=collectd
- opts.SetLabelSelector("app=collectd")
- opts.InNamespace(cr.Namespace)
- err := r.client.List(context.TODO(), opts, cmList)
- if err != nil {
- return rmap, err
- }
-
- if cmList.Items == nil || len(cmList.Items) == 0 {
- return rmap, err
- }
-
- // Select DaemonSets with label app=collectd
- dsList := &extensionsv1beta1.DaemonSetList{}
- err = r.client.List(context.TODO(), opts, dsList)
- if err != nil {
- return rmap, err
- }
-
- if dsList.Items == nil || len(dsList.Items) == 0 {
- return rmap, err
- }
-
- // Get all collectd plugins in the current namespace to rebuild conf.
- collectdPlugins := &onapv1alpha1.CollectdPluginList{}
- cpOpts := &client.ListOptions{}
- cpOpts.InNamespace(cr.Namespace)
- err = r.client.List(context.TODO(), cpOpts, collectdPlugins)
- if err != nil {
- return rmap, err
- }
-
- rmap.configMap = &cmList.Items[0]
- rmap.daemonSet = &dsList.Items[0]
- rmap.collectdPlugins = &collectdPlugins.Items //will be nil if no plugins exist
- return rmap, err
-}
-
-// Get all collectd plugins and reconstruct, compute Hash and check for changes
-func rebuildCollectdConf(cpList *[]onapv1alpha1.CollectdPlugin) (string, error) {
- var collectdConf string
- if *cpList == nil || len(*cpList) == 0 {
- return "", errors.NewNotFound(corev1.Resource("collectdplugin"), "CollectdPlugin")
- }
- loadPlugin := make(map[string]string)
- for _, cp := range *cpList {
- if cp.Spec.PluginName == "global" {
- collectdConf += cp.Spec.PluginConf + "\n"
- } else {
- loadPlugin[cp.Spec.PluginName] = cp.Spec.PluginConf
- }
- }
-
- log.V(1).Info("::::::: Plugins Map ::::::: ", "PluginMap ", loadPlugin)
-
- for cpName, cpConf := range loadPlugin {
- collectdConf += "LoadPlugin" + " " + cpName + "\n"
- collectdConf += cpConf + "\n"
- }
-
- collectdConf += "\n#Last line (collectd requires ā\\nā at the last line)"
-
- return collectdConf, nil
-}
-