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


Golang Object.GetFinalizers方法代碼示例

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


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

示例1: shouldOrphanDependents

func shouldOrphanDependents(e event, accessor meta.Object) bool {
	// The delta_fifo may combine the creation and update of the object into one
	// event, so we need to check AddEvent as well.
	if e.oldObj == nil {
		if accessor.GetDeletionTimestamp() == nil {
			return false
		}
	} else {
		oldAccessor, err := meta.Accessor(e.oldObj)
		if err != nil {
			utilruntime.HandleError(fmt.Errorf("cannot access oldObj: %v", err))
			return false
		}
		// ignore the event if it's not updating DeletionTimestamp from non-nil to nil.
		if accessor.GetDeletionTimestamp() == nil || oldAccessor.GetDeletionTimestamp() != nil {
			return false
		}
	}
	finalizers := accessor.GetFinalizers()
	for _, finalizer := range finalizers {
		if finalizer == api.FinalizerOrphan {
			return true
		}
	}
	return false
}
開發者ID:FlyWings,項目名稱:kubernetes,代碼行數:26,代碼來源:garbagecollector.go

示例2: shouldUpdateFinalizers

// shouldUpdateFinalizers returns if we need to update the finalizers of the
// object, and the desired list of finalizers.
// When deciding whether to add the OrphanDependent finalizer, factors in the
// order of highest to lowest priority are: options.OrphanDependents, existing
// finalizers of the object, e.DeleteStrategy.DefaultGarbageCollectionPolicy.
func shouldUpdateFinalizers(e *Store, accessor meta.Object, options *api.DeleteOptions) (shouldUpdate bool, newFinalizers []string) {
	shouldOrphan := false
	// Get default orphan policy from this REST object type
	if gcStrategy, ok := e.DeleteStrategy.(rest.GarbageCollectionDeleteStrategy); ok {
		if gcStrategy.DefaultGarbageCollectionPolicy() == rest.OrphanDependents {
			shouldOrphan = true
		}
	}
	// If a finalizer is set in the object, it overrides the default
	hasOrphanFinalizer := false
	finalizers := accessor.GetFinalizers()
	for _, f := range finalizers {
		if f == api.FinalizerOrphan {
			shouldOrphan = true
			hasOrphanFinalizer = true
			break
		}
		// TODO: update this when we add a finalizer indicating a preference for the other behavior
	}
	// If an explicit policy was set at deletion time, that overrides both
	if options != nil && options.OrphanDependents != nil {
		shouldOrphan = *options.OrphanDependents
	}
	if shouldOrphan && !hasOrphanFinalizer {
		finalizers = append(finalizers, api.FinalizerOrphan)
		return true, finalizers
	}
	if !shouldOrphan && hasOrphanFinalizer {
		var newFinalizers []string
		for _, f := range finalizers {
			if f == api.FinalizerOrphan {
				continue
			}
			newFinalizers = append(newFinalizers, f)
		}
		return true, newFinalizers
	}
	return false, finalizers
}
開發者ID:xgwang-zte,項目名稱:origin,代碼行數:44,代碼來源:store.go

示例3: shouldUpdateFinalizers

// return if we need to update the finalizers of the object, and the desired list of finalizers
func shouldUpdateFinalizers(accessor meta.Object, options *api.DeleteOptions) (shouldUpdate bool, newFinalizers []string) {
	if options == nil || options.OrphanDependents == nil {
		return false, accessor.GetFinalizers()
	}
	shouldOrphan := *options.OrphanDependents
	alreadyOrphan := false
	finalizers := accessor.GetFinalizers()
	newFinalizers = make([]string, 0, len(finalizers))
	for _, f := range finalizers {
		if f == api.FinalizerOrphan {
			alreadyOrphan = true
			if !shouldOrphan {
				continue
			}
		}
		newFinalizers = append(newFinalizers, f)
	}
	if shouldOrphan && !alreadyOrphan {
		newFinalizers = append(newFinalizers, api.FinalizerOrphan)
	}
	shouldUpdate = shouldOrphan != alreadyOrphan
	return shouldUpdate, newFinalizers
}
開發者ID:Cloven,項目名稱:minikube,代碼行數:24,代碼來源:store.go


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