This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new c355f8a12 Reduce write to hash, prepare string from secret, configmap
c355f8a12 is described below
commit c355f8a122c66a46cfd1060e6a1f82ed32d93b0c
Author: Lucie Krejcirova <[email protected]>
AuthorDate: Tue Feb 13 11:53:54 2024 +0100
Reduce write to hash, prepare string from secret, configmap
---
pkg/util/digest/digest.go | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/pkg/util/digest/digest.go b/pkg/util/digest/digest.go
index 0f17e1280..3e9d7b48c 100644
--- a/pkg/util/digest/digest.go
+++ b/pkg/util/digest/digest.go
@@ -140,10 +140,10 @@ func ComputeForIntegration(integration *v1.Integration,
configmaps []*corev1.Con
// Configmap content
for _, cm := range configmaps {
if cm != nil {
+ // prepare string from cm
+ var cmToString strings.Builder
// name, ns
- if _, err := hash.Write([]byte(fmt.Sprintf("%s/%s",
cm.Name, cm.Namespace))); err != nil {
- return "", err
- }
+ cmToString.WriteString(fmt.Sprintf("%s/%s", cm.Name,
cm.Namespace))
// Data with sorted keys
if cm.Data != nil {
// sort keys
@@ -153,9 +153,7 @@ func ComputeForIntegration(integration *v1.Integration,
configmaps []*corev1.Con
}
sort.Strings(keys)
for _, k := range keys {
- if _, err :=
hash.Write([]byte(fmt.Sprintf("%s=%v,", k, cm.Data[k]))); err != nil {
- return "", err
- }
+
cmToString.WriteString(fmt.Sprintf("%s=%v,", k, cm.Data[k]))
}
}
// BinaryData with sorted keys
@@ -166,21 +164,23 @@ func ComputeForIntegration(integration *v1.Integration,
configmaps []*corev1.Con
}
sort.Strings(keys)
for _, k := range keys {
- if _, err :=
hash.Write([]byte(fmt.Sprintf("%s=%v,", k, cm.BinaryData[k]))); err != nil {
- return "", err
- }
+
cmToString.WriteString(fmt.Sprintf("%s=%v,", k, cm.BinaryData[k]))
}
}
+ // write prepared string to hash
+ if _, err := hash.Write([]byte(cmToString.String()));
err != nil {
+ return "", err
+ }
}
}
// Secret content
for _, s := range secrets {
if s != nil {
+ // prepare string from secret
+ var secretToString strings.Builder
// name, ns
- if _, err := hash.Write([]byte(fmt.Sprintf("%s/%s",
s.Name, s.Namespace))); err != nil {
- return "", err
- }
+ secretToString.WriteString(fmt.Sprintf("%s/%s", s.Name,
s.Namespace))
// Data with sorted keys
if s.Data != nil {
keys := make([]string, 0, len(s.Data))
@@ -189,11 +189,13 @@ func ComputeForIntegration(integration *v1.Integration,
configmaps []*corev1.Con
}
sort.Strings(keys)
for _, k := range keys {
- if _, err :=
hash.Write([]byte(fmt.Sprintf("%s=%v,", k, s.Data[k]))); err != nil {
- return "", err
- }
+
secretToString.WriteString(fmt.Sprintf("%s=%v,", k, s.Data[k]))
}
}
+ // write prepared secret to hash
+ if _, err :=
hash.Write([]byte(secretToString.String())); err != nil {
+ return "", err
+ }
}
}