mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Move pkg/api.FinanlizerOrphan into metav1
This commit is contained in:
		@@ -101,7 +101,7 @@ func TestDaemonSetController(t *testing.T) {
 | 
				
			|||||||
	updatedDaemonSet := GetDaemonSetFromChan(daemonsetUpdateChan)
 | 
						updatedDaemonSet := GetDaemonSetFromChan(daemonsetUpdateChan)
 | 
				
			||||||
	assert.True(t, daemonsetController.hasFinalizerFunc(updatedDaemonSet, deletionhelper.FinalizerDeleteFromUnderlyingClusters))
 | 
						assert.True(t, daemonsetController.hasFinalizerFunc(updatedDaemonSet, deletionhelper.FinalizerDeleteFromUnderlyingClusters))
 | 
				
			||||||
	updatedDaemonSet = GetDaemonSetFromChan(daemonsetUpdateChan)
 | 
						updatedDaemonSet = GetDaemonSetFromChan(daemonsetUpdateChan)
 | 
				
			||||||
	assert.True(t, daemonsetController.hasFinalizerFunc(updatedDaemonSet, apiv1.FinalizerOrphan))
 | 
						assert.True(t, daemonsetController.hasFinalizerFunc(updatedDaemonSet, metav1.FinalizerOrphan))
 | 
				
			||||||
	daemonset1 = *updatedDaemonSet
 | 
						daemonset1 = *updatedDaemonSet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	createdDaemonSet := GetDaemonSetFromChan(cluster1CreateChan)
 | 
						createdDaemonSet := GetDaemonSetFromChan(cluster1CreateChan)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -144,7 +144,7 @@ func TestIngressController(t *testing.T) {
 | 
				
			|||||||
	updatedIngress := GetIngressFromChan(t, fedIngressUpdateChan)
 | 
						updatedIngress := GetIngressFromChan(t, fedIngressUpdateChan)
 | 
				
			||||||
	assert.True(t, ingressController.hasFinalizerFunc(updatedIngress, deletionhelper.FinalizerDeleteFromUnderlyingClusters))
 | 
						assert.True(t, ingressController.hasFinalizerFunc(updatedIngress, deletionhelper.FinalizerDeleteFromUnderlyingClusters))
 | 
				
			||||||
	updatedIngress = GetIngressFromChan(t, fedIngressUpdateChan)
 | 
						updatedIngress = GetIngressFromChan(t, fedIngressUpdateChan)
 | 
				
			||||||
	assert.True(t, ingressController.hasFinalizerFunc(updatedIngress, apiv1.FinalizerOrphan), fmt.Sprintf("ingress does not have the orphan finalizer: %v", updatedIngress))
 | 
						assert.True(t, ingressController.hasFinalizerFunc(updatedIngress, metav1.FinalizerOrphan), fmt.Sprintf("ingress does not have the orphan finalizer: %v", updatedIngress))
 | 
				
			||||||
	fedIngress = *updatedIngress
 | 
						fedIngress = *updatedIngress
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	t.Log("Checking that Ingress was correctly created in cluster 1")
 | 
						t.Log("Checking that Ingress was correctly created in cluster 1")
 | 
				
			||||||
@@ -305,7 +305,7 @@ func WaitForFinalizersInFederationStore(ingressController *IngressController, st
 | 
				
			|||||||
			return false, err
 | 
								return false, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ingress := obj.(*extensionsv1beta1.Ingress)
 | 
							ingress := obj.(*extensionsv1beta1.Ingress)
 | 
				
			||||||
		if ingressController.hasFinalizerFunc(ingress, apiv1.FinalizerOrphan) &&
 | 
							if ingressController.hasFinalizerFunc(ingress, metav1.FinalizerOrphan) &&
 | 
				
			||||||
			ingressController.hasFinalizerFunc(ingress, deletionhelper.FinalizerDeleteFromUnderlyingClusters) {
 | 
								ingressController.hasFinalizerFunc(ingress, deletionhelper.FinalizerDeleteFromUnderlyingClusters) {
 | 
				
			||||||
			return true, nil
 | 
								return true, nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -149,7 +149,7 @@ func TestNamespaceController(t *testing.T) {
 | 
				
			|||||||
	// Delete the namespace with orphan finalizer (let namespaces
 | 
						// Delete the namespace with orphan finalizer (let namespaces
 | 
				
			||||||
	// in underlying clusters be as is).
 | 
						// in underlying clusters be as is).
 | 
				
			||||||
	// TODO: Add a test without orphan finalizer.
 | 
						// TODO: Add a test without orphan finalizer.
 | 
				
			||||||
	ns1.ObjectMeta.Finalizers = append(ns1.ObjectMeta.Finalizers, apiv1.FinalizerOrphan)
 | 
						ns1.ObjectMeta.Finalizers = append(ns1.ObjectMeta.Finalizers, metav1.FinalizerOrphan)
 | 
				
			||||||
	ns1.DeletionTimestamp = &metav1.Time{Time: time.Now()}
 | 
						ns1.DeletionTimestamp = &metav1.Time{Time: time.Now()}
 | 
				
			||||||
	namespaceWatch.Modify(&ns1)
 | 
						namespaceWatch.Modify(&ns1)
 | 
				
			||||||
	assert.Equal(t, ns1.Name, GetStringFromChan(nsDeleteChan))
 | 
						assert.Equal(t, ns1.Name, GetStringFromChan(nsDeleteChan))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -101,7 +101,7 @@ func TestSecretController(t *testing.T) {
 | 
				
			|||||||
	updatedSecret := GetSecretFromChan(secretUpdateChan)
 | 
						updatedSecret := GetSecretFromChan(secretUpdateChan)
 | 
				
			||||||
	assert.True(t, secretController.hasFinalizerFunc(updatedSecret, deletionhelper.FinalizerDeleteFromUnderlyingClusters))
 | 
						assert.True(t, secretController.hasFinalizerFunc(updatedSecret, deletionhelper.FinalizerDeleteFromUnderlyingClusters))
 | 
				
			||||||
	updatedSecret = GetSecretFromChan(secretUpdateChan)
 | 
						updatedSecret = GetSecretFromChan(secretUpdateChan)
 | 
				
			||||||
	assert.True(t, secretController.hasFinalizerFunc(updatedSecret, apiv1.FinalizerOrphan))
 | 
						assert.True(t, secretController.hasFinalizerFunc(updatedSecret, metav1.FinalizerOrphan))
 | 
				
			||||||
	secret1 = *updatedSecret
 | 
						secret1 = *updatedSecret
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Verify that the secret is created in underlying cluster1.
 | 
						// Verify that the secret is created in underlying cluster1.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,11 +24,11 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/runtime"
 | 
						"k8s.io/apimachinery/pkg/runtime"
 | 
				
			||||||
	"k8s.io/client-go/tools/record"
 | 
						"k8s.io/client-go/tools/record"
 | 
				
			||||||
	"k8s.io/kubernetes/federation/pkg/federation-controller/util"
 | 
						"k8s.io/kubernetes/federation/pkg/federation-controller/util"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
	api_v1 "k8s.io/kubernetes/pkg/api/v1"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/golang/glog"
 | 
						"github.com/golang/glog"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -96,9 +96,9 @@ func (dh *DeletionHelper) EnsureFinalizers(obj runtime.Object) (
 | 
				
			|||||||
			return obj, err
 | 
								return obj, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if !dh.hasFinalizerFunc(obj, api_v1.FinalizerOrphan) {
 | 
						if !dh.hasFinalizerFunc(obj, metav1.FinalizerOrphan) {
 | 
				
			||||||
		glog.V(2).Infof("Adding finalizer %s to %s", api_v1.FinalizerOrphan, dh.objNameFunc(obj))
 | 
							glog.V(2).Infof("Adding finalizer %s to %s", metav1.FinalizerOrphan, dh.objNameFunc(obj))
 | 
				
			||||||
		obj, err := dh.addFinalizerFunc(obj, api_v1.FinalizerOrphan)
 | 
							obj, err := dh.addFinalizerFunc(obj, metav1.FinalizerOrphan)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return obj, err
 | 
								return obj, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -120,7 +120,7 @@ func (dh *DeletionHelper) HandleObjectInUnderlyingClusters(obj runtime.Object) (
 | 
				
			|||||||
		glog.V(2).Infof("obj does not have %s finalizer. Nothing to do", FinalizerDeleteFromUnderlyingClusters)
 | 
							glog.V(2).Infof("obj does not have %s finalizer. Nothing to do", FinalizerDeleteFromUnderlyingClusters)
 | 
				
			||||||
		return obj, nil
 | 
							return obj, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	hasOrphanFinalizer := dh.hasFinalizerFunc(obj, api_v1.FinalizerOrphan)
 | 
						hasOrphanFinalizer := dh.hasFinalizerFunc(obj, metav1.FinalizerOrphan)
 | 
				
			||||||
	if hasOrphanFinalizer {
 | 
						if hasOrphanFinalizer {
 | 
				
			||||||
		glog.V(2).Infof("Found finalizer orphan. Nothing to do, just remove the finalizer")
 | 
							glog.V(2).Infof("Found finalizer orphan. Nothing to do, just remove the finalizer")
 | 
				
			||||||
		// If the obj has FinalizerOrphan finalizer, then we need to orphan the
 | 
							// If the obj has FinalizerOrphan finalizer, then we need to orphan the
 | 
				
			||||||
@@ -130,7 +130,7 @@ func (dh *DeletionHelper) HandleObjectInUnderlyingClusters(obj runtime.Object) (
 | 
				
			|||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return obj, err
 | 
								return obj, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return dh.removeFinalizerFunc(obj, api_v1.FinalizerOrphan)
 | 
							return dh.removeFinalizerFunc(obj, metav1.FinalizerOrphan)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	glog.V(2).Infof("Deleting obj %s from underlying clusters", objName)
 | 
						glog.V(2).Infof("Deleting obj %s from underlying clusters", objName)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -244,7 +244,7 @@ func IsServiceIPRequested(service *Service) bool {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
var standardFinalizers = sets.NewString(
 | 
					var standardFinalizers = sets.NewString(
 | 
				
			||||||
	string(FinalizerKubernetes),
 | 
						string(FinalizerKubernetes),
 | 
				
			||||||
	FinalizerOrphan,
 | 
						metav1.FinalizerOrphan,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// HasAnnotation returns a bool if passed in annotation exists
 | 
					// HasAnnotation returns a bool if passed in annotation exists
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2798,10 +2798,10 @@ type NamespaceSpec struct {
 | 
				
			|||||||
// FinalizerName is the name identifying a finalizer during namespace lifecycle.
 | 
					// FinalizerName is the name identifying a finalizer during namespace lifecycle.
 | 
				
			||||||
type FinalizerName string
 | 
					type FinalizerName string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// These are internal finalizer values to Kubernetes, must be qualified name unless defined here
 | 
					// These are internal finalizer values to Kubernetes, must be qualified name unless defined here or
 | 
				
			||||||
 | 
					// in metav1.
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	FinalizerKubernetes FinalizerName = "kubernetes"
 | 
						FinalizerKubernetes FinalizerName = "kubernetes"
 | 
				
			||||||
	FinalizerOrphan     string        = "orphan"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NamespaceStatus is information about the current status of a Namespace.
 | 
					// NamespaceStatus is information about the current status of a Namespace.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,7 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/labels"
 | 
						"k8s.io/apimachinery/pkg/labels"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/selection"
 | 
						"k8s.io/apimachinery/pkg/selection"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/types"
 | 
						"k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
@@ -82,7 +83,7 @@ func IsServiceIPRequested(service *Service) bool {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
var standardFinalizers = sets.NewString(
 | 
					var standardFinalizers = sets.NewString(
 | 
				
			||||||
	string(FinalizerKubernetes),
 | 
						string(FinalizerKubernetes),
 | 
				
			||||||
	FinalizerOrphan,
 | 
						metav1.FinalizerOrphan,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func IsStandardFinalizerName(str string) bool {
 | 
					func IsStandardFinalizerName(str string) bool {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3220,10 +3220,10 @@ type NodeList struct {
 | 
				
			|||||||
// FinalizerName is the name identifying a finalizer during namespace lifecycle.
 | 
					// FinalizerName is the name identifying a finalizer during namespace lifecycle.
 | 
				
			||||||
type FinalizerName string
 | 
					type FinalizerName string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// These are internal finalizer values to Kubernetes, must be qualified name unless defined here
 | 
					// These are internal finalizer values to Kubernetes, must be qualified name unless defined here or
 | 
				
			||||||
 | 
					// in metav1.
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	FinalizerKubernetes FinalizerName = "kubernetes"
 | 
						FinalizerKubernetes FinalizerName = "kubernetes"
 | 
				
			||||||
	FinalizerOrphan     string        = "orphan"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NamespaceSpec describes the attributes on a Namespace.
 | 
					// NamespaceSpec describes the attributes on a Namespace.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,7 +39,6 @@ import (
 | 
				
			|||||||
	"k8s.io/client-go/tools/cache"
 | 
						"k8s.io/client-go/tools/cache"
 | 
				
			||||||
	"k8s.io/client-go/util/clock"
 | 
						"k8s.io/client-go/util/clock"
 | 
				
			||||||
	"k8s.io/client-go/util/workqueue"
 | 
						"k8s.io/client-go/util/workqueue"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api/v1"
 | 
					 | 
				
			||||||
	"k8s.io/kubernetes/pkg/controller/garbagecollector/metaonly"
 | 
						"k8s.io/kubernetes/pkg/controller/garbagecollector/metaonly"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// import known versions
 | 
						// import known versions
 | 
				
			||||||
@@ -235,7 +234,7 @@ func shouldOrphanDependents(e *event, accessor metav1.Object) bool {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	finalizers := accessor.GetFinalizers()
 | 
						finalizers := accessor.GetFinalizers()
 | 
				
			||||||
	for _, finalizer := range finalizers {
 | 
						for _, finalizer := range finalizers {
 | 
				
			||||||
		if finalizer == v1.FinalizerOrphan {
 | 
							if finalizer == metav1.FinalizerOrphan {
 | 
				
			||||||
			return true
 | 
								return true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -280,7 +279,7 @@ func (gc *GarbageCollector) removeOrphanFinalizer(owner *node) error {
 | 
				
			|||||||
		var newFinalizers []string
 | 
							var newFinalizers []string
 | 
				
			||||||
		found := false
 | 
							found := false
 | 
				
			||||||
		for _, f := range finalizers {
 | 
							for _, f := range finalizers {
 | 
				
			||||||
			if f == v1.FinalizerOrphan {
 | 
								if f == metav1.FinalizerOrphan {
 | 
				
			||||||
				found = true
 | 
									found = true
 | 
				
			||||||
				break
 | 
									break
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,6 @@ import (
 | 
				
			|||||||
	"k8s.io/apimachinery/pkg/runtime"
 | 
						"k8s.io/apimachinery/pkg/runtime"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/wait"
 | 
						"k8s.io/apimachinery/pkg/util/wait"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/watch"
 | 
						"k8s.io/apimachinery/pkg/watch"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestDecoratedWatcher(t *testing.T) {
 | 
					func TestDecoratedWatcher(t *testing.T) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,7 +37,6 @@ import (
 | 
				
			|||||||
	"k8s.io/apimachinery/pkg/watch"
 | 
						"k8s.io/apimachinery/pkg/watch"
 | 
				
			||||||
	genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
 | 
						genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
 | 
				
			||||||
	"k8s.io/apiserver/pkg/storage"
 | 
						"k8s.io/apiserver/pkg/storage"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
					 | 
				
			||||||
	"k8s.io/kubernetes/pkg/genericapiserver/registry/generic"
 | 
						"k8s.io/kubernetes/pkg/genericapiserver/registry/generic"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/genericapiserver/registry/rest"
 | 
						"k8s.io/kubernetes/pkg/genericapiserver/registry/rest"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/registry/cachesize"
 | 
						"k8s.io/kubernetes/pkg/registry/cachesize"
 | 
				
			||||||
@@ -546,7 +545,7 @@ func shouldUpdateFinalizers(e *Store, accessor metav1.Object, options *metav1.De
 | 
				
			|||||||
	hasOrphanFinalizer := false
 | 
						hasOrphanFinalizer := false
 | 
				
			||||||
	finalizers := accessor.GetFinalizers()
 | 
						finalizers := accessor.GetFinalizers()
 | 
				
			||||||
	for _, f := range finalizers {
 | 
						for _, f := range finalizers {
 | 
				
			||||||
		if f == api.FinalizerOrphan {
 | 
							if f == metav1.FinalizerOrphan {
 | 
				
			||||||
			shouldOrphan = true
 | 
								shouldOrphan = true
 | 
				
			||||||
			hasOrphanFinalizer = true
 | 
								hasOrphanFinalizer = true
 | 
				
			||||||
			break
 | 
								break
 | 
				
			||||||
@@ -558,13 +557,13 @@ func shouldUpdateFinalizers(e *Store, accessor metav1.Object, options *metav1.De
 | 
				
			|||||||
		shouldOrphan = *options.OrphanDependents
 | 
							shouldOrphan = *options.OrphanDependents
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if shouldOrphan && !hasOrphanFinalizer {
 | 
						if shouldOrphan && !hasOrphanFinalizer {
 | 
				
			||||||
		finalizers = append(finalizers, api.FinalizerOrphan)
 | 
							finalizers = append(finalizers, metav1.FinalizerOrphan)
 | 
				
			||||||
		return true, finalizers
 | 
							return true, finalizers
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if !shouldOrphan && hasOrphanFinalizer {
 | 
						if !shouldOrphan && hasOrphanFinalizer {
 | 
				
			||||||
		var newFinalizers []string
 | 
							var newFinalizers []string
 | 
				
			||||||
		for _, f := range finalizers {
 | 
							for _, f := range finalizers {
 | 
				
			||||||
			if f == api.FinalizerOrphan {
 | 
								if f == metav1.FinalizerOrphan {
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			newFinalizers = append(newFinalizers, f)
 | 
								newFinalizers = append(newFinalizers, f)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -798,7 +798,7 @@ func TestStoreDeleteWithOrphanDependents(t *testing.T) {
 | 
				
			|||||||
	initialGeneration := int64(1)
 | 
						initialGeneration := int64(1)
 | 
				
			||||||
	podWithOrphanFinalizer := func(name string) *api.Pod {
 | 
						podWithOrphanFinalizer := func(name string) *api.Pod {
 | 
				
			||||||
		return &api.Pod{
 | 
							return &api.Pod{
 | 
				
			||||||
			ObjectMeta: metav1.ObjectMeta{Name: name, Finalizers: []string{"foo.com/x", api.FinalizerOrphan, "bar.com/y"}, Generation: initialGeneration},
 | 
								ObjectMeta: metav1.ObjectMeta{Name: name, Finalizers: []string{"foo.com/x", metav1.FinalizerOrphan, "bar.com/y"}, Generation: initialGeneration},
 | 
				
			||||||
			Spec:       api.PodSpec{NodeName: "machine"},
 | 
								Spec:       api.PodSpec{NodeName: "machine"},
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -816,7 +816,7 @@ func TestStoreDeleteWithOrphanDependents(t *testing.T) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	podWithOnlyOrphanFinalizer := func(name string) *api.Pod {
 | 
						podWithOnlyOrphanFinalizer := func(name string) *api.Pod {
 | 
				
			||||||
		return &api.Pod{
 | 
							return &api.Pod{
 | 
				
			||||||
			ObjectMeta: metav1.ObjectMeta{Name: name, Finalizers: []string{api.FinalizerOrphan}, Generation: initialGeneration},
 | 
								ObjectMeta: metav1.ObjectMeta{Name: name, Finalizers: []string{metav1.FinalizerOrphan}, Generation: initialGeneration},
 | 
				
			||||||
			Spec:       api.PodSpec{NodeName: "machine"},
 | 
								Spec:       api.PodSpec{NodeName: "machine"},
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -844,28 +844,28 @@ func TestStoreDeleteWithOrphanDependents(t *testing.T) {
 | 
				
			|||||||
			orphanOptions,
 | 
								orphanOptions,
 | 
				
			||||||
			defaultDeleteStrategy,
 | 
								defaultDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{"foo.com/x", api.FinalizerOrphan, "bar.com/y"},
 | 
								[]string{"foo.com/x", metav1.FinalizerOrphan, "bar.com/y"},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithOtherFinalizers("pod2"),
 | 
								podWithOtherFinalizers("pod2"),
 | 
				
			||||||
			orphanOptions,
 | 
								orphanOptions,
 | 
				
			||||||
			defaultDeleteStrategy,
 | 
								defaultDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{"foo.com/x", "bar.com/y", api.FinalizerOrphan},
 | 
								[]string{"foo.com/x", "bar.com/y", metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithNoFinalizer("pod3"),
 | 
								podWithNoFinalizer("pod3"),
 | 
				
			||||||
			orphanOptions,
 | 
								orphanOptions,
 | 
				
			||||||
			defaultDeleteStrategy,
 | 
								defaultDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{api.FinalizerOrphan},
 | 
								[]string{metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithOnlyOrphanFinalizer("pod4"),
 | 
								podWithOnlyOrphanFinalizer("pod4"),
 | 
				
			||||||
			orphanOptions,
 | 
								orphanOptions,
 | 
				
			||||||
			defaultDeleteStrategy,
 | 
								defaultDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{api.FinalizerOrphan},
 | 
								[]string{metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		// cases run with DeleteOptions.OrphanDedependents=false
 | 
							// cases run with DeleteOptions.OrphanDedependents=false
 | 
				
			||||||
		// these cases all have oprhanDeleteStrategy, which should be ignored
 | 
							// these cases all have oprhanDeleteStrategy, which should be ignored
 | 
				
			||||||
@@ -907,14 +907,14 @@ func TestStoreDeleteWithOrphanDependents(t *testing.T) {
 | 
				
			|||||||
			nilOrphanOptions,
 | 
								nilOrphanOptions,
 | 
				
			||||||
			defaultDeleteStrategy,
 | 
								defaultDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{"foo.com/x", api.FinalizerOrphan, "bar.com/y"},
 | 
								[]string{"foo.com/x", metav1.FinalizerOrphan, "bar.com/y"},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithOrphanFinalizer("pod10"),
 | 
								podWithOrphanFinalizer("pod10"),
 | 
				
			||||||
			nilOrphanOptions,
 | 
								nilOrphanOptions,
 | 
				
			||||||
			orphanDeleteStrategy,
 | 
								orphanDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{"foo.com/x", api.FinalizerOrphan, "bar.com/y"},
 | 
								[]string{"foo.com/x", metav1.FinalizerOrphan, "bar.com/y"},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithOtherFinalizers("pod11"),
 | 
								podWithOtherFinalizers("pod11"),
 | 
				
			||||||
@@ -928,7 +928,7 @@ func TestStoreDeleteWithOrphanDependents(t *testing.T) {
 | 
				
			|||||||
			nilOrphanOptions,
 | 
								nilOrphanOptions,
 | 
				
			||||||
			orphanDeleteStrategy,
 | 
								orphanDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{"foo.com/x", "bar.com/y", api.FinalizerOrphan},
 | 
								[]string{"foo.com/x", "bar.com/y", metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithNoFinalizer("pod13"),
 | 
								podWithNoFinalizer("pod13"),
 | 
				
			||||||
@@ -942,21 +942,21 @@ func TestStoreDeleteWithOrphanDependents(t *testing.T) {
 | 
				
			|||||||
			nilOrphanOptions,
 | 
								nilOrphanOptions,
 | 
				
			||||||
			orphanDeleteStrategy,
 | 
								orphanDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{api.FinalizerOrphan},
 | 
								[]string{metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithOnlyOrphanFinalizer("pod15"),
 | 
								podWithOnlyOrphanFinalizer("pod15"),
 | 
				
			||||||
			nilOrphanOptions,
 | 
								nilOrphanOptions,
 | 
				
			||||||
			defaultDeleteStrategy,
 | 
								defaultDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{api.FinalizerOrphan},
 | 
								[]string{metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithOnlyOrphanFinalizer("pod16"),
 | 
								podWithOnlyOrphanFinalizer("pod16"),
 | 
				
			||||||
			nilOrphanOptions,
 | 
								nilOrphanOptions,
 | 
				
			||||||
			orphanDeleteStrategy,
 | 
								orphanDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{api.FinalizerOrphan},
 | 
								[]string{metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// cases run with nil DeleteOptions should have exact same behavior.
 | 
							// cases run with nil DeleteOptions should have exact same behavior.
 | 
				
			||||||
@@ -967,14 +967,14 @@ func TestStoreDeleteWithOrphanDependents(t *testing.T) {
 | 
				
			|||||||
			nil,
 | 
								nil,
 | 
				
			||||||
			defaultDeleteStrategy,
 | 
								defaultDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{"foo.com/x", api.FinalizerOrphan, "bar.com/y"},
 | 
								[]string{"foo.com/x", metav1.FinalizerOrphan, "bar.com/y"},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithOrphanFinalizer("pod18"),
 | 
								podWithOrphanFinalizer("pod18"),
 | 
				
			||||||
			nil,
 | 
								nil,
 | 
				
			||||||
			orphanDeleteStrategy,
 | 
								orphanDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{"foo.com/x", api.FinalizerOrphan, "bar.com/y"},
 | 
								[]string{"foo.com/x", metav1.FinalizerOrphan, "bar.com/y"},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithOtherFinalizers("pod19"),
 | 
								podWithOtherFinalizers("pod19"),
 | 
				
			||||||
@@ -988,7 +988,7 @@ func TestStoreDeleteWithOrphanDependents(t *testing.T) {
 | 
				
			|||||||
			nil,
 | 
								nil,
 | 
				
			||||||
			orphanDeleteStrategy,
 | 
								orphanDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{"foo.com/x", "bar.com/y", api.FinalizerOrphan},
 | 
								[]string{"foo.com/x", "bar.com/y", metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithNoFinalizer("pod21"),
 | 
								podWithNoFinalizer("pod21"),
 | 
				
			||||||
@@ -1002,21 +1002,21 @@ func TestStoreDeleteWithOrphanDependents(t *testing.T) {
 | 
				
			|||||||
			nil,
 | 
								nil,
 | 
				
			||||||
			orphanDeleteStrategy,
 | 
								orphanDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{api.FinalizerOrphan},
 | 
								[]string{metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithOnlyOrphanFinalizer("pod23"),
 | 
								podWithOnlyOrphanFinalizer("pod23"),
 | 
				
			||||||
			nil,
 | 
								nil,
 | 
				
			||||||
			defaultDeleteStrategy,
 | 
								defaultDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{api.FinalizerOrphan},
 | 
								[]string{metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			podWithOnlyOrphanFinalizer("pod24"),
 | 
								podWithOnlyOrphanFinalizer("pod24"),
 | 
				
			||||||
			nil,
 | 
								nil,
 | 
				
			||||||
			orphanDeleteStrategy,
 | 
								orphanDeleteStrategy,
 | 
				
			||||||
			false,
 | 
								false,
 | 
				
			||||||
			[]string{api.FinalizerOrphan},
 | 
								[]string{metav1.FinalizerOrphan},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -141,7 +141,7 @@ func (r *REST) Delete(ctx genericapirequest.Context, name string, options *metav
 | 
				
			|||||||
					newFinalizers := []string{}
 | 
										newFinalizers := []string{}
 | 
				
			||||||
					for i := range existingNamespace.ObjectMeta.Finalizers {
 | 
										for i := range existingNamespace.ObjectMeta.Finalizers {
 | 
				
			||||||
						finalizer := existingNamespace.ObjectMeta.Finalizers[i]
 | 
											finalizer := existingNamespace.ObjectMeta.Finalizers[i]
 | 
				
			||||||
						if string(finalizer) != api.FinalizerOrphan {
 | 
											if string(finalizer) != metav1.FinalizerOrphan {
 | 
				
			||||||
							newFinalizers = append(newFinalizers, finalizer)
 | 
												newFinalizers = append(newFinalizers, finalizer)
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -71,6 +71,11 @@ type ListMeta struct {
 | 
				
			|||||||
	ResourceVersion string `json:"resourceVersion,omitempty" protobuf:"bytes,2,opt,name=resourceVersion"`
 | 
						ResourceVersion string `json:"resourceVersion,omitempty" protobuf:"bytes,2,opt,name=resourceVersion"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// These are internal finalizer values for Kubernetes-like APIs, must be qualified name unless defined here
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						FinalizerOrphan     string        = "orphan"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ObjectMeta is metadata that all persisted resources must have, which includes all objects
 | 
					// ObjectMeta is metadata that all persisted resources must have, which includes all objects
 | 
				
			||||||
// users must create.
 | 
					// users must create.
 | 
				
			||||||
type ObjectMeta struct {
 | 
					type ObjectMeta struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,6 +26,7 @@ import (
 | 
				
			|||||||
	"k8s.io/apimachinery/pkg/types"
 | 
						"k8s.io/apimachinery/pkg/types"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/sets"
 | 
						"k8s.io/apimachinery/pkg/util/sets"
 | 
				
			||||||
	"k8s.io/client-go/pkg/api"
 | 
						"k8s.io/client-go/pkg/api"
 | 
				
			||||||
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// IsOpaqueIntResourceName returns true if the resource name has the opaque
 | 
					// IsOpaqueIntResourceName returns true if the resource name has the opaque
 | 
				
			||||||
@@ -82,7 +83,7 @@ func IsServiceIPRequested(service *Service) bool {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
var standardFinalizers = sets.NewString(
 | 
					var standardFinalizers = sets.NewString(
 | 
				
			||||||
	string(FinalizerKubernetes),
 | 
						string(FinalizerKubernetes),
 | 
				
			||||||
	FinalizerOrphan,
 | 
						metav1.FinalizerOrphan,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func IsStandardFinalizerName(str string) bool {
 | 
					func IsStandardFinalizerName(str string) bool {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3223,7 +3223,6 @@ type FinalizerName string
 | 
				
			|||||||
// These are internal finalizer values to Kubernetes, must be qualified name unless defined here
 | 
					// These are internal finalizer values to Kubernetes, must be qualified name unless defined here
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	FinalizerKubernetes FinalizerName = "kubernetes"
 | 
						FinalizerKubernetes FinalizerName = "kubernetes"
 | 
				
			||||||
	FinalizerOrphan     string        = "orphan"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NamespaceSpec describes the attributes on a Namespace.
 | 
					// NamespaceSpec describes the attributes on a Namespace.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -297,7 +297,7 @@ func setupRCsPods(t *testing.T, gc *garbagecollector.GarbageCollector, clientSet
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		podUIDs = append(podUIDs, pod.ObjectMeta.UID)
 | 
							podUIDs = append(podUIDs, pod.ObjectMeta.UID)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	orphan := (options != nil && options.OrphanDependents != nil && *options.OrphanDependents) || (options == nil && len(initialFinalizers) != 0 && initialFinalizers[0] == api.FinalizerOrphan)
 | 
						orphan := (options != nil && options.OrphanDependents != nil && *options.OrphanDependents) || (options == nil && len(initialFinalizers) != 0 && initialFinalizers[0] == metav1.FinalizerOrphan)
 | 
				
			||||||
	// if we intend to orphan the pods, we need wait for the gc to observe the
 | 
						// if we intend to orphan the pods, we need wait for the gc to observe the
 | 
				
			||||||
	// creation of the pods, otherwise if the deletion of RC is observed before
 | 
						// creation of the pods, otherwise if the deletion of RC is observed before
 | 
				
			||||||
	// the creation of the pods, the pods will not be orphaned.
 | 
						// the creation of the pods, the pods will not be orphaned.
 | 
				
			||||||
@@ -356,9 +356,9 @@ func TestStressingCascadingDeletion(t *testing.T) {
 | 
				
			|||||||
		// rc is created with empty finalizers, deleted with nil delete options, pods will remain.
 | 
							// rc is created with empty finalizers, deleted with nil delete options, pods will remain.
 | 
				
			||||||
		go setupRCsPods(t, gc, clientSet, "collection1-"+strconv.Itoa(i), ns.Name, []string{}, nil, &wg, rcUIDs)
 | 
							go setupRCsPods(t, gc, clientSet, "collection1-"+strconv.Itoa(i), ns.Name, []string{}, nil, &wg, rcUIDs)
 | 
				
			||||||
		// rc is created with the orphan finalizer, deleted with nil options, pods will remain.
 | 
							// rc is created with the orphan finalizer, deleted with nil options, pods will remain.
 | 
				
			||||||
		go setupRCsPods(t, gc, clientSet, "collection2-"+strconv.Itoa(i), ns.Name, []string{api.FinalizerOrphan}, nil, &wg, rcUIDs)
 | 
							go setupRCsPods(t, gc, clientSet, "collection2-"+strconv.Itoa(i), ns.Name, []string{metav1.FinalizerOrphan}, nil, &wg, rcUIDs)
 | 
				
			||||||
		// rc is created with the orphan finalizer, deleted with DeleteOptions.OrphanDependents=false, pods will be deleted.
 | 
							// rc is created with the orphan finalizer, deleted with DeleteOptions.OrphanDependents=false, pods will be deleted.
 | 
				
			||||||
		go setupRCsPods(t, gc, clientSet, "collection3-"+strconv.Itoa(i), ns.Name, []string{api.FinalizerOrphan}, getNonOrphanOptions(), &wg, rcUIDs)
 | 
							go setupRCsPods(t, gc, clientSet, "collection3-"+strconv.Itoa(i), ns.Name, []string{metav1.FinalizerOrphan}, getNonOrphanOptions(), &wg, rcUIDs)
 | 
				
			||||||
		// rc is created with empty finalizers, deleted with DeleteOptions.OrphanDependents=true, pods will remain.
 | 
							// rc is created with empty finalizers, deleted with DeleteOptions.OrphanDependents=true, pods will remain.
 | 
				
			||||||
		go setupRCsPods(t, gc, clientSet, "collection4-"+strconv.Itoa(i), ns.Name, []string{}, getOrphanOptions(), &wg, rcUIDs)
 | 
							go setupRCsPods(t, gc, clientSet, "collection4-"+strconv.Itoa(i), ns.Name, []string{}, getOrphanOptions(), &wg, rcUIDs)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user