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


Golang api.PodTemplateSpec类代码示例

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


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

示例1: Convert_v1_PodTemplateSpec_To_api_PodTemplateSpec

func Convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in *PodTemplateSpec, out *api.PodTemplateSpec, s conversion.Scope) error {
	// TODO: when we move init container to beta, remove these conversions
	if value, ok := in.Annotations[PodInitContainersAnnotationKey]; ok {
		var values []Container
		if err := json.Unmarshal([]byte(value), &values); err != nil {
			return err
		}
		// Conversion from external to internal version exists more to
		// satisfy the needs of the decoder than it does to be a general
		// purpose tool. And Decode always creates an intermediate object
		// to decode to. Thus the caller of UnsafeConvertToVersion is
		// taking responsibility to ensure mutation of in is not exposed
		// back to the caller.
		in.Spec.InitContainers = values
	}

	if err := autoConvert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in, out, s); err != nil {
		return err
	}
	if len(out.Annotations) > 0 {
		old := out.Annotations
		out.Annotations = make(map[string]string, len(old))
		for k, v := range old {
			out.Annotations[k] = v
		}
		delete(out.Annotations, PodInitContainersAnnotationKey)
	}
	return nil
}
开发者ID:40a,项目名称:bootkube,代码行数:29,代码来源:conversion.go

示例2: Convert_v1_PodTemplateSpec_To_api_PodTemplateSpec

func Convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in *PodTemplateSpec, out *api.PodTemplateSpec, s conversion.Scope) error {
	// TODO: sometime after we move init container to stable, remove these conversions
	// If there is a beta annotation, copy to alpha key.
	// See commit log for PR #31026 for why we do this.
	if valueBeta, okBeta := in.Annotations[PodInitContainersBetaAnnotationKey]; okBeta {
		in.Annotations[PodInitContainersAnnotationKey] = valueBeta
	}
	// Move the annotation to the internal repr. field
	if value, ok := in.Annotations[PodInitContainersAnnotationKey]; ok {
		var values []Container
		if err := json.Unmarshal([]byte(value), &values); err != nil {
			return err
		}
		// Conversion from external to internal version exists more to
		// satisfy the needs of the decoder than it does to be a general
		// purpose tool. And Decode always creates an intermediate object
		// to decode to. Thus the caller of UnsafeConvertToVersion is
		// taking responsibility to ensure mutation of in is not exposed
		// back to the caller.
		in.Spec.InitContainers = values

		// Call defaulters explicitly until annotations are removed
		for i := range in.Spec.InitContainers {
			c := &in.Spec.InitContainers[i]
			SetDefaults_Container(c)
		}
	}

	if err := autoConvert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in, out, s); err != nil {
		return err
	}
	if len(out.Annotations) > 0 {
		old := out.Annotations
		out.Annotations = make(map[string]string, len(old))
		for k, v := range old {
			out.Annotations[k] = v
		}
		delete(out.Annotations, PodInitContainersAnnotationKey)
		delete(out.Annotations, PodInitContainersBetaAnnotationKey)
	}
	return nil
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:42,代码来源:conversion.go

示例3: writePodTemplateSpec

func writePodTemplateSpec(r *schema.ResourceData, item *api.PodTemplateSpec) error {
	var template map[string]interface{}
	if x, ok := extractSingleMap(r.Get("template")); ok {
		template = x
	}
	if template == nil {
		return fmt.Errorf("missing template")
	}

	if x, ok := extractSingleMap(template["labels"]); ok && x != nil {
		item.Labels = map[string]string{}
		for k, v := range x {
			item.Labels[k] = v.(string)
		}
	}

	if x, ok := extractSingleMap(template["node_selector"]); ok && x != nil {
		item.Spec.NodeSelector = map[string]string{}
		for k, v := range x {
			item.Spec.NodeSelector[k] = v.(string)
		}
	}

	if x, ok := template["volume"].([]interface{}); ok && x != nil {
		for _, i := range x {
			volume := api.Volume{}
			writePodVolume(i.(map[string]interface{}), &volume)
			item.Spec.Volumes = append(item.Spec.Volumes, volume)
		}
	}

	if x, ok := template["image_pull_secret"].([]interface{}); ok && x != nil {
		for _, i := range x {
			ref := api.LocalObjectReference{}
			writePodImagePullSecret(i.(map[string]interface{}), &ref)
			item.Spec.ImagePullSecrets = append(item.Spec.ImagePullSecrets, ref)
		}
	}

	if x, ok := template["container"].([]interface{}); ok && x != nil {
		for _, i := range x {
			ref := api.Container{}
			err := writePodContainer(i.(map[string]interface{}), &ref)
			if err != nil {
				return err
			}
			item.Spec.Containers = append(item.Spec.Containers, ref)
		}
	}

	if x, ok := template["restart_policy"].(string); ok {
		item.Spec.RestartPolicy = api.RestartPolicy(x)
	}

	if x, ok := template["dns_policy"].(string); ok {
		item.Spec.DNSPolicy = api.DNSPolicy(x)
	}

	if x, ok := template["service_account_name"].(string); ok {
		item.Spec.ServiceAccountName = x
	}

	if x, ok := template["node_name"].(string); ok {
		item.Spec.NodeName = x
	}

	if x, ok := template["termination_grace_period"].(int); ok && x > 0 {
		l := int64(x)
		item.Spec.TerminationGracePeriodSeconds = &l
	}

	if x, ok := template["active_deadline"].(int); ok && x > 0 {
		l := int64(x)
		item.Spec.ActiveDeadlineSeconds = &l
	}

	return nil
}
开发者ID:fd,项目名称:terraform-provider-kubernetes,代码行数:78,代码来源:replication_controller_resource.go


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