Commit 51854ad5 authored by Edmund Ochieng's avatar Edmund Ochieng

add checksum for configmap

parent deae99bb
......@@ -2,6 +2,7 @@ package utils
import (
"context"
"encoding/hex"
"fmt"
"io/ioutil"
"math/rand"
......@@ -11,6 +12,9 @@ import (
"encoding/base64"
"crypto/sha256"
"encoding/json"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
......@@ -279,3 +283,20 @@ func GetDeploymentPods(kclient client.Client, name, namespace string) (result []
return result, err
}
// ConfigMapWithHash returns configmap with
// annotation containing a SHA256 hash of its data
func ConfigMapWithHash(cm *corev1.ConfigMap) (*corev1.ConfigMap, error) {
jdata, err := json.Marshal(cm.Data)
if err != nil {
return nil, err
}
hash := sha256.Sum256(jdata)
cm.Annotations = map[string]string{
"checksum": hex.EncodeToString(hash[:]),
}
return cm, nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment