Commit 1b97fa55 authored by Edmund Ochieng's avatar Edmund Ochieng

Merge branch 'checksum_configmap' into 'master'

Add configmap checksum

See merge request !30
parents deae99bb 2cbbae02
Pipeline #194636154 passed with stages
in 19 minutes and 15 seconds
......@@ -70,5 +70,8 @@ func GetConfigMap(cr *gitlabv1beta1.Runner) *corev1.ConfigMap {
"configure": configureScript,
}
// update configmap with checksum in annotation
gitlabutils.ConfigMapWithHash(runnerConfigMap)
return runnerConfigMap
}
......@@ -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,18 @@ func GetDeploymentPods(kclient client.Client, name, namespace string) (result []
return result, err
}
// ConfigMapWithHash updates configmap with
// annotation containing a SHA256 hash of its data
func ConfigMapWithHash(cm *corev1.ConfigMap) {
jdata, err := json.Marshal(cm.Data)
if err != nil {
return
}
hash := sha256.Sum256(jdata)
cm.Annotations = map[string]string{
"checksum": hex.EncodeToString(hash[:]),
}
}
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