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


Golang Node.Annotations方法代碼示例

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


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

示例1: 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 *v1.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
}
開發者ID:kubernetes,項目名稱:kubernetes,代碼行數:29,代碼來源:kubelet_node_status.go

示例2: addToBeDeletedTaint

func addToBeDeletedTaint(node *apiv1.Node) (bool, error) {
	taints, err := apiv1.GetTaintsFromNodeAnnotations(node.Annotations)
	if err != nil {
		glog.Warningf("Error while getting Taints for node %v: %v", node.Name, err)
		return false, err
	}
	for _, taint := range taints {
		if taint.Key == ToBeDeletedTaint {
			glog.Infof("ToBeDeletedTaint already present on on node %v", taint, node.Name)
			return false, nil
		}
	}
	taints = append(taints, apiv1.Taint{
		Key:    ToBeDeletedTaint,
		Value:  time.Now().String(),
		Effect: apiv1.TaintEffectNoSchedule,
	})
	taintsJson, err := json.Marshal(taints)
	if err != nil {
		glog.Warningf("Error while adding taints on node %v: %v", node.Name, err)
		return false, err
	}
	if node.Annotations == nil {
		node.Annotations = make(map[string]string)
	}
	node.Annotations[apiv1.TaintsAnnotationKey] = string(taintsJson)
	return true, nil
}
開發者ID:kubernetes,項目名稱:contrib,代碼行數:28,代碼來源:scale_down.go


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