mirror of https://github.com/kubernetes/kops.git
Manifest hashing: move trimming out of hash function
It's a little confusing to have a hash function which auto-trims. But trimming the manifests does make sense. We also want to be sure that the hash matches the raw hash of the manifest, which it didn't when we transformed the manifest "inside the hash".
This commit is contained in:
parent
0e27206973
commit
e098f0f353
|
|
@ -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