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


Golang api.ObjectMeta类代码示例

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


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

示例1: SetMasterTaintTolerations

func SetMasterTaintTolerations(meta *api.ObjectMeta) {
	tolerationsAnnotation, _ := json.Marshal([]api.Toleration{{Key: "dedicated", Value: "master", Effect: "NoSchedule"}})
	if meta.Annotations == nil {
		meta.Annotations = map[string]string{}
	}
	meta.Annotations[api.TolerationsAnnotationKey] = string(tolerationsAnnotation)
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:7,代码来源:apiclient.go

示例2: Annotate

// Annotate safely copies annotation metadata from kv to meta.Annotations.
func Annotate(meta *api.ObjectMeta, kv map[string]string) {
	//TODO(jdef) this func probably belong in an "apiutil" package, but we don't
	//have much to put there right now so it can just live here.
	if meta.Annotations == nil {
		meta.Annotations = make(map[string]string)
	}
	for k, v := range kv {
		meta.Annotations[k] = v
	}
}
开发者ID:johndmulhausen,项目名称:kubernetes,代码行数:11,代码来源:filters.go

示例3: testNewKubeRC

func testNewKubeRC(meta kube.ObjectMeta, selector map[string]string, pod *kube.Pod) *kube.ReplicationController {
	var spec *kube.PodTemplateSpec
	if pod != nil {
		meta := pod.ObjectMeta
		meta.Namespace = kube.NamespaceDefault
		meta.Name = ""
		spec = &kube.PodTemplateSpec{
			ObjectMeta: meta,
			Spec:       pod.Spec,
		}
	}
	return &kube.ReplicationController{
		ObjectMeta: meta,
		Spec: kube.ReplicationControllerSpec{
			Selector: selector,
			Template: spec,
		},
	}
}
开发者ID:redspread,项目名称:spread,代码行数:19,代码来源:replicationcontroller_test.go

示例4: populateMetadata

func populateMetadata(obj *api.ObjectMeta, metadatas []interface{}) {
	if len(metadatas) == 0 {
		return
	}
	metadata := metadatas[0].(map[string]interface{})

	if _, ok := metadata["name"]; ok {
		obj.Name = metadata["name"].(string)
	}
	if _, ok := metadata["namespace"]; ok {
		obj.Namespace = metadata["namespace"].(string)
	}
	if _, ok := metadata["resource_version"]; ok {
		obj.ResourceVersion = metadata["resource_version"].(string)
	}
	if _, ok := metadata["labels"]; ok {
		obj.Labels = convertMapTypeToStringMap(metadata["labels"].(map[string]interface{}))
	}
}
开发者ID:kelcecil,项目名称:terraform-provider-kubernetes,代码行数:19,代码来源:build_kubernetes_resource_controller.go

示例5: writeLabels

func writeLabels(r *schema.ResourceData, meta *api.ObjectMeta) {
	meta.Labels = map[string]string{}
	if labels, _ := r.Get("labels").(map[string]interface{}); labels != nil {
		for k, v := range labels {
			if s, ok := v.(string); ok {
				meta.Labels[k] = s
			}
		}
	}
}
开发者ID:fd,项目名称:terraform-provider-kubernetes,代码行数:10,代码来源:utils.go

示例6: addLabelIfNotxisEt

func addLabelIfNotxisEt(metadata *api.ObjectMeta, name string, value string) bool {
	if metadata.Labels == nil {
		metadata.Labels = make(map[string]string)
	}
	labels := metadata.Labels
	current := labels[name]
	if len(current) == 0 {
		labels[name] = value
		return true
	}
	return false
}
开发者ID:rhuss,项目名称:gofabric8,代码行数:12,代码来源:deploy.go

示例7: addAnnotationIfNotExist

func addAnnotationIfNotExist(metadata *api.ObjectMeta, name string, value string) bool {
	if metadata.Annotations == nil {
		metadata.Annotations = make(map[string]string)
	}
	annotations := metadata.Annotations
	current := annotations[name]
	if len(current) == 0 {
		annotations[name] = value
		return true
	}
	return false
}
开发者ID:gashcrumb,项目名称:gofabric8,代码行数:12,代码来源:deploy.go

示例8: SetNodeAffinity

// SetNodeAffinity is a basic helper to set meta.Annotations[api.AffinityAnnotationKey] for one or more api.NodeSelectorRequirement(s)
func SetNodeAffinity(meta *api.ObjectMeta, expr ...api.NodeSelectorRequirement) {
	nodeAffinity := &api.NodeAffinity{
		RequiredDuringSchedulingIgnoredDuringExecution: &api.NodeSelector{
			NodeSelectorTerms: []api.NodeSelectorTerm{{MatchExpressions: expr}},
		},
	}
	affinityAnnotation, _ := json.Marshal(api.Affinity{NodeAffinity: nodeAffinity})
	if meta.Annotations == nil {
		meta.Annotations = map[string]string{}
	}
	meta.Annotations[api.AffinityAnnotationKey] = string(affinityAnnotation)
}
开发者ID:eljefedelrodeodeljefe,项目名称:kubernetes,代码行数:13,代码来源:apiclient.go

示例9: writeAnnotations

func writeAnnotations(r *schema.ResourceData, meta *api.ObjectMeta) {
	meta.Annotations = map[string]string{
		"terraform.io/owned": "true",
	}
	if annotations, _ := r.Get("annotations").(map[string]interface{}); annotations != nil {
		for k, v := range annotations {
			if s, ok := v.(string); ok {
				meta.Annotations[k] = s
			}
		}
	}
}
开发者ID:fd,项目名称:terraform-provider-kubernetes,代码行数:12,代码来源:utils.go

示例10: createReplicationController

func createReplicationController(c *gin.Context) {
	namespace := c.Param("ns")
	rcjson := c.PostForm("json")

	var rc api.ReplicationController
	err := json.Unmarshal([]byte(rcjson), &rc)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	if rc.Spec.Selector == nil {
		rc.Spec.Selector = make(map[string]string)
	}
	rc.Spec.Selector["managed-by"] = rc.Name
	if rc.Spec.Template.Labels == nil {
		rc.Spec.Template.Labels = make(map[string]string)
	}
	rc.Spec.Template.Labels["managed-by"] = rc.Name
	rc.Spec.Template.Spec.Containers[0].Name = rc.Name

	var meta api.ObjectMeta // clean metadata
	meta.Name = rc.Name
	meta.GenerateName = rc.GenerateName
	meta.Labels = rc.Labels
	meta.Annotations = rc.Annotations
	if meta.Labels != nil {
		meta.Labels["managed-by"] = rc.Name
	}
	rc.ObjectMeta = meta

	_, err = kubeclient.Get().ReplicationControllers(namespace).Create(&rc)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/namespaces/%s", namespace))
}
开发者ID:aclisp,项目名称:kubecon,代码行数:39,代码来源:main.go

示例11: exportObjectMeta

func exportObjectMeta(objMeta *kapi.ObjectMeta, exact bool) {
	objMeta.UID = ""
	if !exact {
		objMeta.Namespace = ""
	}
	objMeta.CreationTimestamp = util.Time{}
	objMeta.DeletionTimestamp = nil
	objMeta.ResourceVersion = ""
	objMeta.SelfLink = ""
	if len(objMeta.GenerateName) > 0 && !exact {
		objMeta.Name = ""
	}
}
开发者ID:dctse,项目名称:openshift-cucumber,代码行数:13,代码来源:exporter.go

示例12: SetMasterNodeAffinity

func SetMasterNodeAffinity(meta *api.ObjectMeta) {
	nodeAffinity := &api.NodeAffinity{
		RequiredDuringSchedulingIgnoredDuringExecution: &api.NodeSelector{
			NodeSelectorTerms: []api.NodeSelectorTerm{{
				MatchExpressions: []api.NodeSelectorRequirement{{
					Key: "kubeadm.alpha.kubernetes.io/role", Operator: api.NodeSelectorOpIn, Values: []string{"master"},
				}},
			}},
		},
	}
	affinityAnnotation, _ := json.Marshal(api.Affinity{NodeAffinity: nodeAffinity})
	if meta.Annotations == nil {
		meta.Annotations = map[string]string{}
	}
	meta.Annotations[api.AffinityAnnotationKey] = string(affinityAnnotation)
}
开发者ID:ncdc,项目名称:kubernetes,代码行数:16,代码来源:apiclient.go

示例13: setAnnotation

func setAnnotation(obj *api.ObjectMeta, ann string, value string) {
	if obj.Annotations == nil {
		obj.Annotations = make(map[string]string)
	}
	obj.Annotations[ann] = value
}
开发者ID:roackb2,项目名称:kubernetes,代码行数:6,代码来源:controller_base.go

示例14: convert_v1_ObjectMeta_To_api_ObjectMeta

func convert_v1_ObjectMeta_To_api_ObjectMeta(in *v1.ObjectMeta, out *api.ObjectMeta, s conversion.Scope) error {
	if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
		defaulting.(func(*v1.ObjectMeta))(in)
	}
	out.Name = in.Name
	out.GenerateName = in.GenerateName
	out.Namespace = in.Namespace
	out.SelfLink = in.SelfLink
	out.UID = in.UID
	out.ResourceVersion = in.ResourceVersion
	out.Generation = in.Generation
	if err := s.Convert(&in.CreationTimestamp, &out.CreationTimestamp, 0); err != nil {
		return err
	}
	if in.DeletionTimestamp != nil {
		if err := s.Convert(&in.DeletionTimestamp, &out.DeletionTimestamp, 0); err != nil {
			return err
		}
	} else {
		out.DeletionTimestamp = nil
	}
	if in.DeletionGracePeriodSeconds != nil {
		out.DeletionGracePeriodSeconds = new(int64)
		*out.DeletionGracePeriodSeconds = *in.DeletionGracePeriodSeconds
	} else {
		out.DeletionGracePeriodSeconds = nil
	}
	if in.Labels != nil {
		out.Labels = make(map[string]string)
		for key, val := range in.Labels {
			out.Labels[key] = val
		}
	} else {
		out.Labels = nil
	}
	if in.Annotations != nil {
		out.Annotations = make(map[string]string)
		for key, val := range in.Annotations {
			out.Annotations[key] = val
		}
	} else {
		out.Annotations = nil
	}
	return nil
}
开发者ID:ngbinh,项目名称:kubernetes,代码行数:45,代码来源:conversion_generated.go

示例15: deepCopy_api_ObjectMeta

func deepCopy_api_ObjectMeta(in api.ObjectMeta, out *api.ObjectMeta, c *conversion.Cloner) error {
	out.Name = in.Name
	out.GenerateName = in.GenerateName
	out.Namespace = in.Namespace
	out.SelfLink = in.SelfLink
	out.UID = in.UID
	out.ResourceVersion = in.ResourceVersion
	out.Generation = in.Generation
	if err := deepCopy_unversioned_Time(in.CreationTimestamp, &out.CreationTimestamp, c); err != nil {
		return err
	}
	if in.DeletionTimestamp != nil {
		out.DeletionTimestamp = new(unversioned.Time)
		if err := deepCopy_unversioned_Time(*in.DeletionTimestamp, out.DeletionTimestamp, c); err != nil {
			return err
		}
	} else {
		out.DeletionTimestamp = nil
	}
	if in.DeletionGracePeriodSeconds != nil {
		out.DeletionGracePeriodSeconds = new(int64)
		*out.DeletionGracePeriodSeconds = *in.DeletionGracePeriodSeconds
	} else {
		out.DeletionGracePeriodSeconds = nil
	}
	if in.Labels != nil {
		out.Labels = make(map[string]string)
		for key, val := range in.Labels {
			out.Labels[key] = val
		}
	} else {
		out.Labels = nil
	}
	if in.Annotations != nil {
		out.Annotations = make(map[string]string)
		for key, val := range in.Annotations {
			out.Annotations[key] = val
		}
	} else {
		out.Annotations = nil
	}
	return nil
}
开发者ID:josafat,项目名称:contrib,代码行数:43,代码来源:deep_copy_generated.go


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