当前位置: 首页>>代码示例>>Golang>>正文


Golang hash.DeepHashObject函数代码示例

本文整理汇总了Golang中k8s/io/kubernetes/pkg/util/hash.DeepHashObject函数的典型用法代码示例。如果您正苦于以下问题:Golang DeepHashObject函数的具体用法?Golang DeepHashObject怎么用?Golang DeepHashObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了DeepHashObject函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: applyDefaults

func applyDefaults(pod *api.Pod, source string, isFile bool, nodeName string) error {
	if len(pod.UID) == 0 {
		hasher := md5.New()
		if isFile {
			fmt.Fprintf(hasher, "host:%s", nodeName)
			fmt.Fprintf(hasher, "file:%s", source)
		} else {
			fmt.Fprintf(hasher, "url:%s", source)
		}
		hash.DeepHashObject(hasher, pod)
		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)
	}

	pod.Name = generatePodName(pod.Name, nodeName)
	glog.V(5).Infof("Generated Name %q for UID %q from URL %s", pod.Name, pod.UID, source)

	if pod.Namespace == "" {
		pod.Namespace = kubetypes.NamespaceDefault
	}
	glog.V(5).Infof("Using namespace %q for pod %q from %s", pod.Namespace, pod.Name, source)

	// Set the Host field to indicate this pod is scheduled on the current node.
	pod.Spec.NodeName = nodeName

	pod.ObjectMeta.SelfLink = getSelfLink(pod.Name, pod.Namespace)

	if pod.Annotations == nil {
		pod.Annotations = make(map[string]string)
	}
	// The generated UID is the hash of the file.
	pod.Annotations[kubetypes.ConfigHashAnnotationKey] = string(pod.UID)
	return nil
}
开发者ID:jojimt,项目名称:contrib,代码行数:34,代码来源:common.go

示例2: keyFunc

// keyFunc returns the key of an object, which is used to look up in the cache for it's matching object.
// Since we match objects by namespace and Labels/Selector, so if two objects have the same namespace and labels,
// they will have the same key.
func keyFunc(obj objectWithMeta) uint64 {
	hash := adler32.New()
	hashutil.DeepHashObject(hash, &equivalenceLabelObj{
		namespace: obj.GetNamespace(),
		labels:    obj.GetLabels(),
	})
	return uint64(hash.Sum32())
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:11,代码来源:lookup_cache.go

示例3: hashAddresses

func hashAddresses(addrs addressSet) string {
	// Flatten the list of addresses into a string so it can be used as a
	// map key.  Unfortunately, DeepHashObject is implemented in terms of
	// spew, and spew does not handle non-primitive map keys well.  So
	// first we collapse it into a slice, sort the slice, then hash that.
	slice := make([]addrReady, 0, len(addrs))
	for k, ready := range addrs {
		slice = append(slice, addrReady{k, ready})
	}
	sort.Sort(addrsReady(slice))
	hasher := md5.New()
	hashutil.DeepHashObject(hasher, slice)
	return hex.EncodeToString(hasher.Sum(nil)[0:])
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:14,代码来源:util.go

示例4: verifyPackUnpack

func verifyPackUnpack(t *testing.T, podNamespace, podUID, podName, containerName string) {
	container := &api.Container{Name: containerName}
	hasher := adler32.New()
	hashutil.DeepHashObject(hasher, *container)
	computedHash := uint64(hasher.Sum32())
	podFullName := fmt.Sprintf("%s_%s", podName, podNamespace)
	_, name, _ := BuildDockerName(KubeletContainerName{podFullName, types.UID(podUID), container.Name}, container)
	returned, hash, err := ParseDockerName(name)
	if err != nil {
		t.Errorf("Failed to parse Docker container name %q: %v", name, err)
	}
	if podFullName != returned.PodFullName || podUID != string(returned.PodUID) || containerName != returned.ContainerName || computedHash != hash {
		t.Errorf("For (%s, %s, %s, %d), unpacked (%s, %s, %s, %d)", podFullName, podUID, containerName, computedHash, returned.PodFullName, returned.PodUID, returned.ContainerName, hash)
	}
}
开发者ID:jetsanix,项目名称:kubernetes,代码行数:15,代码来源:docker_test.go

示例5: HashContainer

// HashContainer returns the hash of the container. It is used to compare
// the running container with its desired spec.
func HashContainer(container *api.Container) uint64 {
	hash := adler32.New()
	hashutil.DeepHashObject(hash, *container)
	return uint64(hash.Sum32())
}
开发者ID:ZenoRewn,项目名称:origin,代码行数:7,代码来源:helpers.go

示例6: hashObject

func hashObject(hasher hash.Hash, obj interface{}) []byte {
	hashutil.DeepHashObject(hasher, obj)
	return hasher.Sum(nil)
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:4,代码来源:util.go

示例7: GetPodTemplateSpecHash

func GetPodTemplateSpecHash(template api.PodTemplateSpec) uint32 {
	podTemplateSpecHasher := adler32.New()
	hashutil.DeepHashObject(podTemplateSpecHasher, template)
	return podTemplateSpecHasher.Sum32()
}
开发者ID:jojimt,项目名称:contrib,代码行数:5,代码来源:deployment.go

示例8: hashEquivalencePod

// hashEquivalencePod returns the hash of equivalence pod.
func (ec *EquivalenceCache) hashEquivalencePod(pod *v1.Pod) uint64 {
	equivalencePod := ec.getEquivalencePod(pod)
	hash := adler32.New()
	hashutil.DeepHashObject(hash, equivalencePod)
	return uint64(hash.Sum32())
}
开发者ID:alex-mohr,项目名称:kubernetes,代码行数:7,代码来源:equivalence_cache.go

示例9: getTimeHash

func getTimeHash(scheduledTime time.Time) uint32 {
	timeHasher := adler32.New()
	hashutil.DeepHashObject(timeHasher, scheduledTime)
	return timeHasher.Sum32()
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:5,代码来源:utils.go

示例10: GetPodTemplateSpecHashFnv

func GetPodTemplateSpecHashFnv(template v1.PodTemplateSpec) uint32 {
	podTemplateSpecHasher := fnv.New32a()
	hashutil.DeepHashObject(podTemplateSpecHasher, template)
	return podTemplateSpecHasher.Sum32()
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:5,代码来源:pod_util.go


注:本文中的k8s/io/kubernetes/pkg/util/hash.DeepHashObject函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。