mirror of https://github.com/kubernetes/kops.git
Merge pull request #7312 from justinsb/small_cleanup_to_hashing
Manifest hashing: move trimming out of hash function
This commit is contained in:
commit
39d03b1f97
|
@ -18,6 +18,7 @@ package cloudup
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"k8s.io/klog"
|
||||
channelsapi "k8s.io/kops/channels/pkg/api"
|
||||
|
@ -68,13 +69,16 @@ func (b *BootstrapChannelBuilder) Build(c *fi.ModelBuilderContext) error {
|
|||
return fmt.Errorf("error remapping manifest %s: %v", manifestPath, err)
|
||||
}
|
||||
|
||||
// Trim whitespace
|
||||
manifestBytes = []byte(strings.TrimSpace(string(manifestBytes)))
|
||||
|
||||
rawManifest := string(manifestBytes)
|
||||
klog.V(4).Infof("Manifest %v", rawManifest)
|
||||
|
||||
manifestHash, err := utils.HashString(&rawManifest)
|
||||
manifestHash, err := utils.HashString(rawManifest)
|
||||
klog.V(4).Infof("hash %s", manifestHash)
|
||||
if err != nil {
|
||||
manifestHash = ""
|
||||
return fmt.Errorf("error hashing manifest: %v", err)
|
||||
}
|
||||
a.ManifestHash = manifestHash
|
||||
|
||||
|
|
|
@ -19,14 +19,12 @@ package utils
|
|||
import (
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// HashString Takes String and returns a sha1 hash represented as a string
|
||||
func HashString(s *string) (string, error) {
|
||||
func HashString(s string) (string, error) {
|
||||
h := sha1.New()
|
||||
ts := strings.TrimSpace(*s)
|
||||
_, err := h.Write([]byte(ts))
|
||||
_, err := h.Write([]byte(s))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue