本文整理匯總了Golang中k8s/io/kubernetes/pkg/util.DeepHashObject函數的典型用法代碼示例。如果您正苦於以下問題:Golang DeepHashObject函數的具體用法?Golang DeepHashObject怎麽用?Golang DeepHashObject使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了DeepHashObject函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
util.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 = kubeletTypes.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)
return nil
}
示例2: getDesiredRC
// Returns an RC that matches the intent of the given deployment.
// It creates a new RC if required.
func (d *DeploymentController) getDesiredRC(deployment *experimental.Deployment) (*api.ReplicationController, error) {
namespace := deployment.ObjectMeta.Namespace
// Find if the required RC exists already.
rcList, err := d.client.ReplicationControllers(namespace).List(labels.Everything())
if err != nil {
return nil, fmt.Errorf("error listing replication controllers: %v", err)
}
for _, rc := range rcList.Items {
if api.Semantic.DeepEqual(rc.Spec.Template, deployment.Spec.Template) {
// This is the desired RC.
return &rc, nil
}
}
// desired RC does not exist, create a new one.
podTemplateSpecHasher := adler32.New()
util.DeepHashObject(podTemplateSpecHasher, deployment.Spec.Template)
podTemplateSpecHash := podTemplateSpecHasher.Sum32()
rcName := fmt.Sprintf("deploymentrc-%d", podTemplateSpecHash)
desiredRC := api.ReplicationController{
ObjectMeta: api.ObjectMeta{
Name: rcName,
Namespace: namespace,
},
Spec: api.ReplicationControllerSpec{
Replicas: 0,
Template: deployment.Spec.Template,
},
}
createdRC, err := d.client.ReplicationControllers(namespace).Create(&desiredRC)
if err != nil {
return nil, fmt.Errorf("error creating replication controller: %v", err)
}
return createdRC, nil
}
示例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 := []*api.EndpointAddress{}
for k := range addrs {
slice = append(slice, k)
}
sort.Sort(addrPtrsByIpAndUID(slice))
hasher := md5.New()
util.DeepHashObject(hasher, slice)
return hex.EncodeToString(hasher.Sum(nil)[0:])
}
示例4: 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()
util.DeepHashObject(hasher, slice)
return hex.EncodeToString(hasher.Sum(nil)[0:])
}
示例5: verifyPackUnpack
func verifyPackUnpack(t *testing.T, podNamespace, podUID, podName, containerName string) {
container := &api.Container{Name: containerName}
hasher := adler32.New()
util.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)
}
}
示例6: GetPodTemplateSpecHash
func GetPodTemplateSpecHash(template api.PodTemplateSpec) uint32 {
podTemplateSpecHasher := adler32.New()
util.DeepHashObject(podTemplateSpecHasher, template)
return podTemplateSpecHasher.Sum32()
}
示例7: 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()
util.DeepHashObject(hash, *container)
return uint64(hash.Sum32())
}
示例8: hashObject
func hashObject(hasher hash.Hash, obj interface{}) []byte {
util.DeepHashObject(hasher, obj)
return hasher.Sum(nil)
}