Use hashutil to hold hash tools

This commit is contained in:
harry 2016-01-05 15:31:20 +08:00 committed by Harry Zhang
parent d6ab35a088
commit 2a52976983
7 changed files with 13 additions and 13 deletions

View File

@ -25,7 +25,7 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/types" "k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util" hashutil "k8s.io/kubernetes/pkg/util/hash"
) )
// RepackSubsets takes a slice of EndpointSubset objects, expands it to the full // RepackSubsets takes a slice of EndpointSubset objects, expands it to the full
@ -138,7 +138,7 @@ func hashAddresses(addrs addressSet) string {
} }
sort.Sort(addrsReady(slice)) sort.Sort(addrsReady(slice))
hasher := md5.New() hasher := md5.New()
util.DeepHashObject(hasher, slice) hashutil.DeepHashObject(hasher, slice)
return hex.EncodeToString(hasher.Sum(nil)[0:]) return hex.EncodeToString(hasher.Sum(nil)[0:])
} }
@ -191,7 +191,7 @@ func SortSubsets(subsets []api.EndpointSubset) []api.EndpointSubset {
} }
func hashObject(hasher hash.Hash, obj interface{}) []byte { func hashObject(hasher hash.Hash, obj interface{}) []byte {
util.DeepHashObject(hasher, obj) hashutil.DeepHashObject(hasher, obj)
return hasher.Sum(nil) return hasher.Sum(nil)
} }

View File

@ -27,7 +27,7 @@ import (
"k8s.io/kubernetes/pkg/api/validation" "k8s.io/kubernetes/pkg/api/validation"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types" kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/types" "k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/pkg/util/hash"
utilyaml "k8s.io/kubernetes/pkg/util/yaml" utilyaml "k8s.io/kubernetes/pkg/util/yaml"
"github.com/golang/glog" "github.com/golang/glog"
@ -47,7 +47,7 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName string) er
} else { } else {
fmt.Fprintf(hasher, "url:%s", source) fmt.Fprintf(hasher, "url:%s", source)
} }
util.DeepHashObject(hasher, pod) hash.DeepHashObject(hasher, pod)
pod.UID = types.UID(hex.EncodeToString(hasher.Sum(nil)[0:])) pod.UID = types.UID(hex.EncodeToString(hasher.Sum(nil)[0:]))
glog.V(5).Infof("Generated UID %q pod %q from %s", pod.UID, pod.Name, source) glog.V(5).Infof("Generated UID %q pod %q from %s", pod.UID, pod.Name, source)
} }

View File

@ -25,7 +25,7 @@ import (
"k8s.io/kubernetes/pkg/client/record" "k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/kubelet/util/format" "k8s.io/kubernetes/pkg/kubelet/util/format"
"k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util" hashutil "k8s.io/kubernetes/pkg/util/hash"
"k8s.io/kubernetes/third_party/golang/expansion" "k8s.io/kubernetes/third_party/golang/expansion"
"github.com/golang/glog" "github.com/golang/glog"
@ -127,7 +127,7 @@ func ConvertPodStatusToRunningPod(podStatus *PodStatus) Pod {
// the running container with its desired spec. // the running container with its desired spec.
func HashContainer(container *api.Container) uint64 { func HashContainer(container *api.Container) uint64 {
hash := adler32.New() hash := adler32.New()
util.DeepHashObject(hash, *container) hashutil.DeepHashObject(hash, *container)
return uint64(hash.Sum32()) return uint64(hash.Sum32())
} }

View File

@ -36,7 +36,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/network" "k8s.io/kubernetes/pkg/kubelet/network"
kubetypes "k8s.io/kubernetes/pkg/kubelet/types" kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
"k8s.io/kubernetes/pkg/types" "k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util" hashutil "k8s.io/kubernetes/pkg/util/hash"
"k8s.io/kubernetes/pkg/util/parsers" "k8s.io/kubernetes/pkg/util/parsers"
) )
@ -116,7 +116,7 @@ func TestGetContainerID(t *testing.T) {
func verifyPackUnpack(t *testing.T, podNamespace, podUID, podName, containerName string) { func verifyPackUnpack(t *testing.T, podNamespace, podUID, podName, containerName string) {
container := &api.Container{Name: containerName} container := &api.Container{Name: containerName}
hasher := adler32.New() hasher := adler32.New()
util.DeepHashObject(hasher, *container) hashutil.DeepHashObject(hasher, *container)
computedHash := uint64(hasher.Sum32()) computedHash := uint64(hasher.Sum32())
podFullName := fmt.Sprintf("%s_%s", podName, podNamespace) podFullName := fmt.Sprintf("%s_%s", podName, podNamespace)
_, name := BuildDockerName(KubeletContainerName{podFullName, types.UID(podUID), container.Name}, container) _, name := BuildDockerName(KubeletContainerName{podFullName, types.UID(podUID), container.Name}, container)

View File

@ -25,7 +25,7 @@ import (
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
client "k8s.io/kubernetes/pkg/client/unversioned" client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util" hashutil "k8s.io/kubernetes/pkg/util/hash"
) )
// GetOldRCs returns the old RCs targeted by the given Deployment; get PodList and RCList from client interface. // GetOldRCs returns the old RCs targeted by the given Deployment; get PodList and RCList from client interface.
@ -141,7 +141,7 @@ func CloneAndAddLabel(labels map[string]string, labelKey string, labelValue uint
func GetPodTemplateSpecHash(template api.PodTemplateSpec) uint32 { func GetPodTemplateSpecHash(template api.PodTemplateSpec) uint32 {
podTemplateSpecHasher := adler32.New() podTemplateSpecHasher := adler32.New()
util.DeepHashObject(podTemplateSpecHasher, template) hashutil.DeepHashObject(podTemplateSpecHasher, template)
return podTemplateSpecHasher.Sum32() return podTemplateSpecHasher.Sum32()
} }

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package util package hash
import ( import (
"hash" "hash"

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package util package hash
import ( import (
"fmt" "fmt"