コード例 #1
0
ファイル: apiclient.go プロジェクト: ncdc/kubernetes
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)
}
コード例 #2
0
func autoConvert_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 := api.Convert_unversioned_Time_To_unversioned_Time(&in.CreationTimestamp, &out.CreationTimestamp, s); err != nil {
		return err
	}
	// unable to generate simple pointer conversion for unversioned.Time -> unversioned.Time
	if in.DeletionTimestamp != nil {
		out.DeletionTimestamp = new(unversioned.Time)
		if err := api.Convert_unversioned_Time_To_unversioned_Time(in.DeletionTimestamp, out.DeletionTimestamp, s); 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
}
コード例 #3
0
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
}
コード例 #4
0
ファイル: filters.go プロジェクト: johndmulhausen/kubernetes
// 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
	}
}
コード例 #5
0
ファイル: deploy.go プロジェクト: gashcrumb/gofabric8
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
}
コード例 #6
0
// 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)
}
コード例 #7
0
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
			}
		}
	}
}
コード例 #8
0
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.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
}
コード例 #9
0
ファイル: apiclient.go プロジェクト: ncdc/kubernetes
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)
}
コード例 #10
0
ファイル: main.go プロジェクト: aclisp/kubecon
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))
}
コード例 #11
0
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["labels"]; ok {
		obj.Labels = convertMapTypeToStringMap(metadata["labels"].(map[string]interface{}))
	}
	if _, ok := metadata["annotations"]; ok {
		obj.Annotations = convertNameValueListToStringMap(metadata["annotations"].([]interface{}))
	}
	if _, ok := metadata["resource_version"]; ok {
		obj.ResourceVersion = metadata["resource_version"].(string)
	}
}
コード例 #12
0
ファイル: controller_base.go プロジェクト: roackb2/kubernetes
func setAnnotation(obj *api.ObjectMeta, ann string, value string) {
	if obj.Annotations == nil {
		obj.Annotations = make(map[string]string)
	}
	obj.Annotations[ann] = value
}