本文整理汇总了Golang中k8s/io/kubernetes/pkg/api.Node.Annotations方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Annotations方法的具体用法?Golang Node.Annotations怎么用?Golang Node.Annotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/api.Node
的用法示例。
在下文中一共展示了Node.Annotations方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: generateNodeAndTaintedNode
func generateNodeAndTaintedNode(oldTaints []api.Taint, newTaints []api.Taint) (*api.Node, *api.Node) {
var taintedNode *api.Node
oldTaintsData, _ := json.Marshal(oldTaints)
// Create a node.
node := &api.Node{
ObjectMeta: api.ObjectMeta{
Name: "node-name",
CreationTimestamp: unversioned.Time{Time: time.Now()},
Annotations: map[string]string{
api.TaintsAnnotationKey: string(oldTaintsData),
},
},
Spec: api.NodeSpec{
ExternalID: "node-name",
},
Status: api.NodeStatus{},
}
clone, _ := conversion.NewCloner().DeepCopy(node)
newTaintsData, _ := json.Marshal(newTaints)
// A copy of the same node, but tainted.
taintedNode = clone.(*api.Node)
taintedNode.Annotations = map[string]string{
api.TaintsAnnotationKey: string(newTaintsData),
}
return node, taintedNode
}
示例2: addTaint
func addTaint(client *kube_client.Client, node *kube_api.Node, value string) error {
taints, err := kube_api.GetTaintsFromNodeAnnotations(node.Annotations)
if err != nil {
return err
}
taint := kube_api.Taint{
Key: criticalAddonsOnlyTaintKey,
Value: value,
Effect: kube_api.TaintEffectNoSchedule,
}
taints = append(taints, taint)
taintsJson, err := json.Marshal(taints)
if err != nil {
return err
}
if node.Annotations == nil {
node.Annotations = make(map[string]string)
}
node.Annotations[kube_api.TaintsAnnotationKey] = string(taintsJson)
_, err = client.Nodes().Update(node)
if err != nil {
return err
}
return nil
}
示例3: reconcileCMADAnnotationWithExistingNode
// reconcileCMADAnnotationWithExistingNode reconciles the controller-managed
// attach-detach annotation on a new node and the existing node, returning
// whether the existing node must be updated.
func (kl *Kubelet) reconcileCMADAnnotationWithExistingNode(node, existingNode *api.Node) bool {
var (
existingCMAAnnotation = existingNode.Annotations[volumehelper.ControllerManagedAttachAnnotation]
newCMAAnnotation, newSet = node.Annotations[volumehelper.ControllerManagedAttachAnnotation]
)
if newCMAAnnotation == existingCMAAnnotation {
return false
}
// If the just-constructed node and the existing node do
// not have the same value, update the existing node with
// the correct value of the annotation.
if !newSet {
glog.Info("Controller attach-detach setting changed to false; updating existing Node")
delete(existingNode.Annotations, volumehelper.ControllerManagedAttachAnnotation)
} else {
glog.Info("Controller attach-detach setting changed to true; updating existing Node")
if existingNode.Annotations == nil {
existingNode.Annotations = make(map[string]string)
}
existingNode.Annotations[volumehelper.ControllerManagedAttachAnnotation] = newCMAAnnotation
}
return true
}
示例4: Create
// Create creates a new node api object with the given hostname,
// slave attribute labels and annotations
func Create(
client *client.Client,
hostName string,
slaveAttrLabels,
annotations map[string]string,
) (*api.Node, error) {
n := api.Node{
ObjectMeta: api.ObjectMeta{
Name: hostName,
},
Spec: api.NodeSpec{
ExternalID: hostName,
},
Status: api.NodeStatus{
Phase: api.NodePending,
},
}
n.Labels = mergeMaps(
map[string]string{"kubernetes.io/hostname": hostName},
slaveAttrLabels,
)
n.Annotations = annotations
// try to create
return client.Nodes().Create(&n)
}
示例5: Create
// Create creates a new node api object with the given hostname,
// slave attribute labels and annotations
func Create(
client unversionedcore.NodesGetter,
hostName string,
slaveAttrLabels,
annotations map[string]string,
) (*api.Node, error) {
n := api.Node{
ObjectMeta: api.ObjectMeta{
Name: hostName,
},
Spec: api.NodeSpec{
ExternalID: hostName,
},
Status: api.NodeStatus{
Phase: api.NodePending,
// WORKAROUND(sttts): make sure that the Ready condition is the
// first one. The kube-ui v3 depends on this assumption.
// TODO(sttts): remove this workaround when kube-ui v4 is used or we
// merge this with the statusupdate in the controller manager.
Conditions: []api.NodeCondition{
{
Type: api.NodeReady,
Status: api.ConditionTrue,
Reason: slaveReadyReason,
Message: slaveReadyMessage,
LastHeartbeatTime: unversioned.Now(),
},
},
},
}
n.Labels = mergeMaps(
map[string]string{"kubernetes.io/hostname": hostName},
slaveAttrLabels,
)
n.Annotations = annotations
// try to create
return client.Nodes().Create(&n)
}