-// 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(reqLogger logr.Logger, cr *onapv1alpha1.CollectdPlugin) (ResourceMap, error) {
- cmList := &corev1.ConfigMapList{}
- opts := &client.ListOptions{}
- rmap := ResourceMap{}
-
- // Select ConfigMaps with label
- labelSelector, err := getWatchLabels()
- if err != nil {
- reqLogger.Error(err, "Failed to get watch labels, continuing with default label")
- }
- opts.SetLabelSelector(labelSelector)
- 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, errors.NewNotFound(corev1.Resource("configmap"), "ConfigMap")
- }
-
- // Select DaemonSets with label
- 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, errors.NewNotFound(corev1.Resource("daemonset"), "DaemonSet")
- }
-
- // Get all collectd plugins in the current namespace to rebuild conf.
- cpList, err := r.getCollectdPluginList(cr.Namespace)
- if err != nil {
- return rmap, err
- }
-
- rmap.configMap = &cmList.Items[0]
- rmap.daemonSet = &dsList.Items[0]
- rmap.collectdPlugins = &cpList.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(cr *onapv1alpha1.CollectdPlugin, cpList *[]onapv1alpha1.CollectdPlugin, isDelete bool) (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
- }
- }
-
- if isDelete {
- delete(loadPlugin, cr.Spec.PluginName)
- }
-
- log.V(1).Info("::::::: Plugins Map ::::::: ", "PluginMap ", loadPlugin)
-
- for cpName, cpConf := range loadPlugin {
- collectdConf += "LoadPlugin" + " " + cpName + "\n"
- collectdConf += cpConf + "\n"
- }
-
- collectdConf += "#Last line (collectd requires ā\\nā at the last line)\n"
-
- return collectdConf, nil
-}
-