Skip to content

Commit

Permalink
Fix #1038: redeploy integration when trait config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Nov 12, 2019
1 parent 7f88b65 commit 2528e49
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/util/digest/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/sha256"
"encoding/base64"
"math/rand"
"sort"
"strconv"

"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
Expand Down Expand Up @@ -70,6 +71,23 @@ func ComputeForIntegration(integration *v1alpha1.Integration) (string, error) {
}
}

// Integration traits
for _, name := range sortedTraitSpecMapKeys(integration.Spec.Traits) {
if _, err := hash.Write([]byte(name + "[")); err != nil {
return "", err
}
spec := integration.Spec.Traits[name]
for _, prop := range sortedStringMapKeys(spec.Configuration) {
val := spec.Configuration[prop]
if _, err := hash.Write([]byte(prop + "=" + val + ",")); err != nil {
return "", err
}
}
if _, err := hash.Write([]byte("]")); err != nil {
return "", err
}
}

// Add a letter at the beginning and use URL safe encoding
digest := "v" + base64.RawURLEncoding.EncodeToString(hash.Sum(nil))
return digest, nil
Expand Down Expand Up @@ -104,3 +122,21 @@ func ComputeForIntegrationKit(kit *v1alpha1.IntegrationKit) (string, error) {
func Random() string {
return "v" + strconv.FormatInt(rand.Int63(), 10)
}

func sortedStringMapKeys(m map[string]string) []string {
res := make([]string, 0, len(m))
for k := range m {
res = append(res, k)
}
sort.Strings(res)
return res
}

func sortedTraitSpecMapKeys(m map[string]v1alpha1.TraitSpec) []string {
res := make([]string, 0, len(m))
for k := range m {
res = append(res, k)
}
sort.Strings(res)
return res
}

0 comments on commit 2528e49

Please sign in to comment.