File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ package controller
2626
2727import (
2828 "context"
29+ "crypto/sha256"
30+ "encoding/hex"
2931 "encoding/json"
3032 "fmt"
3133 "maps"
@@ -220,6 +222,22 @@ func KustomizeHash(obj client.Object) (hash string, err error) {
220222 return kustomizeHasher .Hash (objKYaml )
221223}
222224
225+ // GenerateHashFromStrings generates a hash from a list of strings. This hash can be used to identify resources and
226+ // if they can be removed. E.g. the ogcapi-operator provides the volume-operator with a hash so it knows what resources
227+ // to create or remove.
228+ func GenerateHashFromStrings (sliceToHash []string ) string {
229+ // Concatenate all strings to hash
230+ var data string
231+
232+ for _ , val := range sliceToHash {
233+ data += val
234+ }
235+
236+ hash := sha256 .Sum256 ([]byte (data ))
237+ // Take the first 8 bytes of the hash to make it in the same format as the kustomize hash.
238+ return hex .EncodeToString (hash [:8 ])
239+ }
240+
223241func EnsureSetGVK (c client.Client , src client.Object , obj schema.ObjectKind ) error {
224242 gvk , err := c .GroupVersionKindFor (src )
225243 if err != nil {
You can’t perform that action at this time.
0 commit comments