Skip to content

Commit

Permalink
standardise object hash generation across the repo
Browse files Browse the repository at this point in the history
Signed-off-by: Tariq Ibrahim <[email protected]>
  • Loading branch information
tariq1890 committed Jun 27, 2024
1 parent 007f1fe commit 7068fec
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 546 deletions.
9 changes: 3 additions & 6 deletions controllers/object_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"path/filepath"

"github.com/davecgh/go-spew/spew"
"github.com/mitchellh/hashstructure"
apiconfigv1 "github.com/openshift/api/config/v1"
apiimagev1 "github.com/openshift/api/image/v1"
secv1 "github.com/openshift/api/security/v1"
Expand All @@ -53,6 +52,7 @@ import (
"sigs.k8s.io/yaml"

gpuv1 "github.com/NVIDIA/gpu-operator/api/nvidia/v1"
"github.com/NVIDIA/gpu-operator/internal/utils"
)

const (
Expand Down Expand Up @@ -1856,15 +1856,12 @@ func TransformKataManager(obj *appsv1.DaemonSet, config *gpuv1.ClusterPolicySpec
// Compute hash of kata manager config and add an annotation with the value.
// If the kata config changes, a new revision of the daemonset will be
// created and thus the kata-manager pods will restart with the updated config.
hash, err := hashstructure.Hash(config.KataManager.Config, nil)
if err != nil {
return fmt.Errorf("failed to get hash of kata-manager config: %v", err)
}
hash := utils.GetObjectHash(config.KataManager.Config)

if obj.Spec.Template.Annotations == nil {
obj.Spec.Template.Annotations = make(map[string]string)
}
obj.Spec.Template.Annotations[KataManagerAnnotationHashKey] = strconv.FormatUint(hash, 16)
obj.Spec.Template.Annotations[KataManagerAnnotationHashKey] = hash

return nil
}
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/NVIDIA/nvidia-container-toolkit v1.15.0
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/go-logr/logr v1.4.2
github.com/mitchellh/hashstructure v1.1.0
github.com/mittwald/go-helm-client v0.12.10
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa1
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/mitchellh/hashstructure v1.1.0 h1:P6P1hdjqAAknpY/M1CGipelZgp+4y9ja9kmUZPXP+H0=
github.com/mitchellh/hashstructure v1.1.0/go.mod h1:xUDAozZz0Wmdiufv0uyhnHkUTN6/6d8ulp4AwfLKrmA=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
Expand Down
3 changes: 1 addition & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"strings"

"github.com/davecgh/go-spew/spew"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/rand"
)

Expand Down Expand Up @@ -64,7 +63,7 @@ func BoolPtr(v bool) *bool {
}

// GetObjectHash invokes Sum32 Hash function to return hash value of an unstructured Object
func GetObjectHash(obj *unstructured.Unstructured) string {
func GetObjectHash(obj interface{}) string {
hasher := fnv.New32a()
printer := spew.ConfigState{
Indent: " ",
Expand Down
21 changes: 0 additions & 21 deletions vendor/github.com/mitchellh/hashstructure/LICENSE

This file was deleted.

67 changes: 0 additions & 67 deletions vendor/github.com/mitchellh/hashstructure/README.md

This file was deleted.

Loading

0 comments on commit 7068fec

Please sign in to comment.