cmd/kube-controller-manager
This commit is contained in:
@@ -28,9 +28,10 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/release_1_5/fake"
|
||||
"k8s.io/kubernetes/pkg/client/restclient"
|
||||
"k8s.io/kubernetes/pkg/client/testing/core"
|
||||
"k8s.io/kubernetes/pkg/client/typed/dynamic"
|
||||
@@ -39,15 +40,15 @@ import (
|
||||
)
|
||||
|
||||
func TestFinalized(t *testing.T) {
|
||||
testNamespace := &api.Namespace{
|
||||
Spec: api.NamespaceSpec{
|
||||
Finalizers: []api.FinalizerName{"a", "b"},
|
||||
testNamespace := &v1.Namespace{
|
||||
Spec: v1.NamespaceSpec{
|
||||
Finalizers: []v1.FinalizerName{"a", "b"},
|
||||
},
|
||||
}
|
||||
if finalized(testNamespace) {
|
||||
t.Errorf("Unexpected result, namespace is not finalized")
|
||||
}
|
||||
testNamespace.Spec.Finalizers = []api.FinalizerName{}
|
||||
testNamespace.Spec.Finalizers = []v1.FinalizerName{}
|
||||
if !finalized(testNamespace) {
|
||||
t.Errorf("Expected object to be finalized")
|
||||
}
|
||||
@@ -55,16 +56,16 @@ func TestFinalized(t *testing.T) {
|
||||
|
||||
func TestFinalizeNamespaceFunc(t *testing.T) {
|
||||
mockClient := &fake.Clientset{}
|
||||
testNamespace := &api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
testNamespace := &v1.Namespace{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Name: "test",
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Spec: api.NamespaceSpec{
|
||||
Finalizers: []api.FinalizerName{"kubernetes", "other"},
|
||||
Spec: v1.NamespaceSpec{
|
||||
Finalizers: []v1.FinalizerName{"kubernetes", "other"},
|
||||
},
|
||||
}
|
||||
finalizeNamespace(mockClient, testNamespace, api.FinalizerKubernetes)
|
||||
finalizeNamespace(mockClient, testNamespace, v1.FinalizerKubernetes)
|
||||
actions := mockClient.Actions()
|
||||
if len(actions) != 1 {
|
||||
t.Errorf("Expected 1 mock client action, but got %v", len(actions))
|
||||
@@ -72,7 +73,7 @@ func TestFinalizeNamespaceFunc(t *testing.T) {
|
||||
if !actions[0].Matches("create", "namespaces") || actions[0].GetSubresource() != "finalize" {
|
||||
t.Errorf("Expected finalize-namespace action %v", actions[0])
|
||||
}
|
||||
finalizers := actions[0].(core.CreateAction).GetObject().(*api.Namespace).Spec.Finalizers
|
||||
finalizers := actions[0].(core.CreateAction).GetObject().(*v1.Namespace).Spec.Finalizers
|
||||
if len(finalizers) != 1 {
|
||||
t.Errorf("There should be a single finalizer remaining")
|
||||
}
|
||||
@@ -84,28 +85,28 @@ func TestFinalizeNamespaceFunc(t *testing.T) {
|
||||
func testSyncNamespaceThatIsTerminating(t *testing.T, versions *unversioned.APIVersions) {
|
||||
now := unversioned.Now()
|
||||
namespaceName := "test"
|
||||
testNamespacePendingFinalize := &api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
testNamespacePendingFinalize := &v1.Namespace{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Name: namespaceName,
|
||||
ResourceVersion: "1",
|
||||
DeletionTimestamp: &now,
|
||||
},
|
||||
Spec: api.NamespaceSpec{
|
||||
Finalizers: []api.FinalizerName{"kubernetes"},
|
||||
Spec: v1.NamespaceSpec{
|
||||
Finalizers: []v1.FinalizerName{"kubernetes"},
|
||||
},
|
||||
Status: api.NamespaceStatus{
|
||||
Phase: api.NamespaceTerminating,
|
||||
Status: v1.NamespaceStatus{
|
||||
Phase: v1.NamespaceTerminating,
|
||||
},
|
||||
}
|
||||
testNamespaceFinalizeComplete := &api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
testNamespaceFinalizeComplete := &v1.Namespace{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Name: namespaceName,
|
||||
ResourceVersion: "1",
|
||||
DeletionTimestamp: &now,
|
||||
},
|
||||
Spec: api.NamespaceSpec{},
|
||||
Status: api.NamespaceStatus{
|
||||
Phase: api.NamespaceTerminating,
|
||||
Spec: v1.NamespaceSpec{},
|
||||
Status: v1.NamespaceStatus{
|
||||
Phase: v1.NamespaceTerminating,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -126,7 +127,7 @@ func testSyncNamespaceThatIsTerminating(t *testing.T, versions *unversioned.APIV
|
||||
}
|
||||
|
||||
scenarios := map[string]struct {
|
||||
testNamespace *api.Namespace
|
||||
testNamespace *v1.Namespace
|
||||
kubeClientActionSet sets.String
|
||||
dynamicClientActionSet sets.String
|
||||
gvrError error
|
||||
@@ -172,7 +173,7 @@ func testSyncNamespaceThatIsTerminating(t *testing.T, versions *unversioned.APIV
|
||||
return groupVersionResources, nil
|
||||
}
|
||||
|
||||
err := syncNamespace(mockClient, clientPool, &operationNotSupportedCache{m: make(map[operationKey]bool)}, fn, testInput.testNamespace, api.FinalizerKubernetes)
|
||||
err := syncNamespace(mockClient, clientPool, &operationNotSupportedCache{m: make(map[operationKey]bool)}, fn, testInput.testNamespace, v1.FinalizerKubernetes)
|
||||
if err != nil {
|
||||
t.Errorf("scenario %s - Unexpected error when synching namespace %v", scenario, err)
|
||||
}
|
||||
@@ -202,14 +203,14 @@ func testSyncNamespaceThatIsTerminating(t *testing.T, versions *unversioned.APIV
|
||||
func TestRetryOnConflictError(t *testing.T) {
|
||||
mockClient := &fake.Clientset{}
|
||||
numTries := 0
|
||||
retryOnce := func(kubeClient clientset.Interface, namespace *api.Namespace) (*api.Namespace, error) {
|
||||
retryOnce := func(kubeClient clientset.Interface, namespace *v1.Namespace) (*v1.Namespace, error) {
|
||||
numTries++
|
||||
if numTries <= 1 {
|
||||
return namespace, errors.NewConflict(api.Resource("namespaces"), namespace.Name, fmt.Errorf("ERROR!"))
|
||||
}
|
||||
return namespace, nil
|
||||
}
|
||||
namespace := &api.Namespace{}
|
||||
namespace := &v1.Namespace{}
|
||||
_, err := retryOnConflictError(mockClient, namespace, retryOnce)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %v", err)
|
||||
@@ -229,22 +230,22 @@ func TestSyncNamespaceThatIsTerminatingV1Beta1(t *testing.T) {
|
||||
|
||||
func TestSyncNamespaceThatIsActive(t *testing.T) {
|
||||
mockClient := &fake.Clientset{}
|
||||
testNamespace := &api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
testNamespace := &v1.Namespace{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
Name: "test",
|
||||
ResourceVersion: "1",
|
||||
},
|
||||
Spec: api.NamespaceSpec{
|
||||
Finalizers: []api.FinalizerName{"kubernetes"},
|
||||
Spec: v1.NamespaceSpec{
|
||||
Finalizers: []v1.FinalizerName{"kubernetes"},
|
||||
},
|
||||
Status: api.NamespaceStatus{
|
||||
Phase: api.NamespaceActive,
|
||||
Status: v1.NamespaceStatus{
|
||||
Phase: v1.NamespaceActive,
|
||||
},
|
||||
}
|
||||
fn := func() ([]unversioned.GroupVersionResource, error) {
|
||||
return testGroupVersionResources(), nil
|
||||
}
|
||||
err := syncNamespace(mockClient, nil, &operationNotSupportedCache{m: make(map[operationKey]bool)}, fn, testNamespace, api.FinalizerKubernetes)
|
||||
err := syncNamespace(mockClient, nil, &operationNotSupportedCache{m: make(map[operationKey]bool)}, fn, testNamespace, v1.FinalizerKubernetes)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error when synching namespace %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user