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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
channelsapi "k8s.io/kops/channels/pkg/api"
|
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)
|
return fmt.Errorf("error remapping manifest %s: %v", manifestPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trim whitespace
|
||||||
|
manifestBytes = []byte(strings.TrimSpace(string(manifestBytes)))
|
||||||
|
|
||||||
rawManifest := string(manifestBytes)
|
rawManifest := string(manifestBytes)
|
||||||
klog.V(4).Infof("Manifest %v", rawManifest)
|
klog.V(4).Infof("Manifest %v", rawManifest)
|
||||||
|
|
||||||
manifestHash, err := utils.HashString(&rawManifest)
|
manifestHash, err := utils.HashString(rawManifest)
|
||||||
klog.V(4).Infof("hash %s", manifestHash)
|
klog.V(4).Infof("hash %s", manifestHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
manifestHash = ""
|
return fmt.Errorf("error hashing manifest: %v", err)
|
||||||
}
|
}
|
||||||
a.ManifestHash = manifestHash
|
a.ManifestHash = manifestHash
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,12 @@ package utils
|
||||||
import (
|
import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HashString Takes String and returns a sha1 hash represented as a string
|
// 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()
|
h := sha1.New()
|
||||||
ts := strings.TrimSpace(*s)
|
_, err := h.Write([]byte(s))
|
||||||
_, err := h.Write([]byte(ts))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue