Skip to content

Commit

Permalink
Merge pull request #291 from gianlucam76/hash
Browse files Browse the repository at this point in the history
Consider reloader knob in the hash function
  • Loading branch information
gianlucam76 authored Aug 7, 2023
2 parents a9bcf68 + 874547d commit 7a390da
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions controllers/handlers_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ func helmHash(ctx context.Context, c client.Client, clusterSummaryScope *scope.C
h := sha256.New()
var config string

// If Reloader changes, Reloader needs to be deployed or undeployed
// So consider it in the hash
config += fmt.Sprintf("%v", clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.Reloader)

clusterSummary := clusterSummaryScope.ClusterSummary
if clusterSummary.Spec.ClusterProfileSpec.HelmCharts == nil {
return h.Sum(nil), nil
Expand Down
4 changes: 3 additions & 1 deletion controllers/handlers_helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"crypto/sha256"
"errors"
"fmt"
"reflect"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -607,7 +608,8 @@ var _ = Describe("Hash methods", func() {
})
Expect(err).To(BeNil())

config := render.AsCode(kyvernoChart)
config := fmt.Sprintf("%v", clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.Reloader)
config += render.AsCode(kyvernoChart)
config += render.AsCode(nginxChart)
h := sha256.New()
h.Write([]byte(config))
Expand Down
4 changes: 4 additions & 0 deletions controllers/handlers_kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ func kustomizationHash(ctx context.Context, c client.Client, clusterSummaryScope
h := sha256.New()
var config string

// If Reloader changes, Reloader needs to be deployed or undeployed
// So consider it in the hash
config += fmt.Sprintf("%v", clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.Reloader)

config += render.AsCode(clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.KustomizationRefs)

for i := range clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.KustomizationRefs {
Expand Down
3 changes: 2 additions & 1 deletion controllers/handlers_kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"compress/gzip"
"context"
"crypto/sha256"
"fmt"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -295,7 +296,7 @@ var _ = Describe("Hash methods", func() {
})
Expect(err).To(BeNil())

var config string
config := fmt.Sprintf("%v", clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.Reloader)
config += render.AsCode(clusterSummary.Spec.ClusterProfileSpec.KustomizationRefs)
for i := 0; i < repoNum; i++ {
config += gitRepositories[i].Status.Artifact.Revision
Expand Down
4 changes: 4 additions & 0 deletions controllers/handlers_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ func resourcesHash(ctx context.Context, c client.Client, clusterSummaryScope *sc
h := sha256.New()
var config string

// If Reloader changes, Reloader needs to be deployed or undeployed
// So consider it in the hash
config += fmt.Sprintf("%v", clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.Reloader)

clusterSummary := clusterSummaryScope.ClusterSummary
for i := range clusterSummary.Spec.ClusterProfileSpec.PolicyRefs {
reference := &clusterSummary.Spec.ClusterProfileSpec.PolicyRefs[i]
Expand Down
3 changes: 2 additions & 1 deletion controllers/handlers_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ var _ = Describe("Hash methods", func() {
})
Expect(err).To(BeNil())

config := render.AsCode(configMap1.Data)
config := fmt.Sprintf("%v", clusterSummaryScope.ClusterSummary.Spec.ClusterProfileSpec.Reloader)
config += render.AsCode(configMap1.Data)
config += render.AsCode(configMap2.Data)
h := sha256.New()
h.Write([]byte(config))
Expand Down

0 comments on commit 7a390da

Please sign in to comment.