當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Pod.Name方法代碼示例

本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet.Pod.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang Pod.Name方法的具體用法?Golang Pod.Name怎麽用?Golang Pod.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet.Pod的用法示例。


在下文中一共展示了Pod.Name方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: extractFromFile

func extractFromFile(name string) (kubelet.Pod, error) {
	var pod kubelet.Pod

	file, err := os.Open(name)
	if err != nil {
		return pod, err
	}
	defer file.Close()

	data, err := ioutil.ReadAll(file)
	if err != nil {
		glog.Errorf("Couldn't read from file: %v", err)
		return pod, err
	}

	if err := yaml.Unmarshal(data, &pod.Manifest); err != nil {
		return pod, fmt.Errorf("could not unmarshal manifest: %v", err)
	}

	podName := pod.Manifest.ID
	if podName == "" {
		podName = simpleSubdomainSafeHash(name)
	}
	pod.Name = podName

	return pod, nil
}
開發者ID:K-A-Z,項目名稱:kubernetes,代碼行數:27,代碼來源:file.go

示例2: extractFromURL

func (s *SourceURL) extractFromURL() error {
	resp, err := http.Get(s.url)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		return fmt.Errorf("%v: %v", s.url, resp.Status)
	}
	if len(data) == 0 {
		return fmt.Errorf("zero-length data received from %v", s.url)
	}

	// First try as if it's a single manifest
	var manifest api.ContainerManifest
	singleErr := yaml.Unmarshal(data, &manifest)
	if singleErr == nil {
		if errs := validation.ValidateManifest(&manifest); len(errs) > 0 {
			singleErr = fmt.Errorf("invalid manifest: %v", errs)
		}
	}
	if singleErr == nil {
		pod := kubelet.Pod{Name: manifest.ID, Manifest: manifest}
		if pod.Name == "" {
			pod.Name = "1"
		}
		s.updates <- kubelet.PodUpdate{[]kubelet.Pod{pod}, kubelet.SET}
		return nil
	}

	// That didn't work, so try an array of manifests.
	var manifests []api.ContainerManifest
	multiErr := yaml.Unmarshal(data, &manifests)
	// We're not sure if the person reading the logs is going to care about the single or
	// multiple manifest unmarshalling attempt, so we need to put both in the logs, as is
	// done at the end. Hence not returning early here.
	if multiErr == nil {
		for _, manifest := range manifests {
			if errs := validation.ValidateManifest(&manifest); len(errs) > 0 {
				multiErr = fmt.Errorf("invalid manifest: %v", errs)
				break
			}
		}
	}
	if multiErr == nil {
		pods := []kubelet.Pod{}
		for i, manifest := range manifests {
			pod := kubelet.Pod{Name: manifest.ID, Manifest: manifest}
			if pod.Name == "" {
				pod.Name = fmt.Sprintf("%d", i+1)
			}
			pods = append(pods, pod)
		}
		s.updates <- kubelet.PodUpdate{pods, kubelet.SET}
		return nil
	}

	return fmt.Errorf("%v: received '%v', but couldn't parse as a "+
		"single manifest (%v: %+v) or as multiple manifests (%v: %+v).\n",
		s.url, string(data), singleErr, manifest, multiErr, manifests)
}
開發者ID:asim,項目名稱:kubernetes,代碼行數:65,代碼來源:http.go

示例3: extractFromURL

func (s *SourceURL) extractFromURL() error {
	resp, err := http.Get(s.url)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	if len(data) == 0 {
		return fmt.Errorf("zero-length data received from %v", s.url)
	}

	// First try as if it's a single manifest
	var pod kubelet.Pod
	singleErr := yaml.Unmarshal(data, &pod.Manifest)
	// TODO: replace with validation
	if singleErr == nil && pod.Manifest.Version == "" {
		// If data is a []ContainerManifest, trying to put it into a ContainerManifest
		// will not give an error but also won't set any of the fields.
		// Our docs say that the version field is mandatory, so using that to judge wether
		// this was actually successful.
		singleErr = fmt.Errorf("got blank version field")
	}

	if singleErr == nil {
		name := pod.Manifest.ID
		if name == "" {
			name = "1"
		}
		pod.Name = name
		s.updates <- kubelet.PodUpdate{[]kubelet.Pod{pod}, kubelet.SET}
		return nil
	}

	// That didn't work, so try an array of manifests.
	var manifests []api.ContainerManifest
	multiErr := yaml.Unmarshal(data, &manifests)
	// We're not sure if the person reading the logs is going to care about the single or
	// multiple manifest unmarshalling attempt, so we need to put both in the logs, as is
	// done at the end. Hence not returning early here.
	if multiErr == nil && len(manifests) > 0 && manifests[0].Version == "" {
		multiErr = fmt.Errorf("got blank version field")
	}
	if multiErr == nil {
		pods := []kubelet.Pod{}
		for i := range manifests {
			pod := kubelet.Pod{Manifest: manifests[i]}
			name := pod.Manifest.ID
			if name == "" {
				name = fmt.Sprintf("%d", i+1)
			}
			pod.Name = name
			pods = append(pods, pod)
		}
		s.updates <- kubelet.PodUpdate{pods, kubelet.SET}
		return nil
	}

	return fmt.Errorf("%v: received '%v', but couldn't parse as a "+
		"single manifest (%v: %+v) or as multiple manifests (%v: %+v).\n",
		s.url, string(data), singleErr, pod.Manifest, multiErr, manifests)
}
開發者ID:RubanDeventhiran,項目名稱:kubernetes,代碼行數:64,代碼來源:http.go


注:本文中的github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet.Pod.Name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。