Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5ac9d860
Unverified
Commit
5ac9d860
authored
Jun 01, 2017
by
Mikhail Mazurskiy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test finalization of CRD
Updates #45511
parent
7043372d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
0 deletions
+112
-0
Godeps.json
...g/src/k8s.io/kube-apiextensions-server/Godeps/Godeps.json
+12
-0
BUILD
...c/k8s.io/kube-apiextensions-server/test/integration/BUILD
+2
-0
finalization_test.go
...piextensions-server/test/integration/finalization_test.go
+98
-0
No files found.
staging/src/k8s.io/kube-apiextensions-server/Godeps/Godeps.json
View file @
5ac9d860
...
...
@@ -255,6 +255,10 @@
"Rev"
:
"a22138067af1c4942683050411a841ade67fe1eb"
},
{
"ImportPath"
:
"github.com/pmezard/go-difflib/difflib"
,
"Rev"
:
"d8ed2627bdf02c080bf22230dbb337003b7aba2d"
},
{
"ImportPath"
:
"github.com/prometheus/client_golang/prometheus"
,
"Rev"
:
"e51041b3fa41cece0dca035740ba6411905be473"
},
...
...
@@ -283,6 +287,14 @@
"Rev"
:
"9ff6c6923cfffbcd502984b8e0c80539a94968b7"
},
{
"ImportPath"
:
"github.com/stretchr/testify/assert"
,
"Rev"
:
"e3a8ff8ce36581f87a15341206f205b1da467059"
},
{
"ImportPath"
:
"github.com/stretchr/testify/require"
,
"Rev"
:
"e3a8ff8ce36581f87a15341206f205b1da467059"
},
{
"ImportPath"
:
"github.com/ugorji/go/codec"
,
"Rev"
:
"ded73eae5db7e7a0ef6f55aace87a2873c5d2b74"
},
...
...
staging/src/k8s.io/kube-apiextensions-server/test/integration/BUILD
View file @
5ac9d860
...
...
@@ -11,6 +11,7 @@ go_test(
name = "go_default_test",
srcs = [
"basic_test.go",
"finalization_test.go",
"registration_test.go",
],
tags = [
...
...
@@ -19,6 +20,7 @@ go_test(
],
deps = [
"//vendor/github.com/coreos/etcd/clientv3:go_default_library",
"//vendor/github.com/stretchr/testify/require:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
...
...
staging/src/k8s.io/kube-apiextensions-server/test/integration/finalization_test.go
0 → 100644
View file @
5ac9d860
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
integration
import
(
"testing"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/api/errors"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
apiextensionsv1beta1
"k8s.io/kube-apiextensions-server/pkg/apis/apiextensions/v1beta1"
"k8s.io/kube-apiextensions-server/test/integration/testserver"
)
func
TestFinalization
(
t
*
testing
.
T
)
{
stopCh
,
apiExtensionClient
,
clientPool
,
err
:=
testserver
.
StartDefaultServer
()
require
.
NoError
(
t
,
err
)
defer
close
(
stopCh
)
noxuDefinition
:=
testserver
.
NewNoxuCustomResourceDefinition
(
apiextensionsv1beta1
.
ClusterScoped
)
noxuVersionClient
,
err
:=
testserver
.
CreateNewCustomResourceDefinition
(
noxuDefinition
,
apiExtensionClient
,
clientPool
)
require
.
NoError
(
t
,
err
)
ns
:=
"not-the-default"
name
:=
"foo123"
noxuResourceClient
:=
NewNamespacedCustomResourceClient
(
ns
,
noxuVersionClient
,
noxuDefinition
)
instance
:=
testserver
.
NewNoxuInstance
(
ns
,
name
)
instance
.
SetFinalizers
([]
string
{
"noxu.example.com/finalizer"
})
createdNoxuInstance
,
err
:=
instantiateCustomResource
(
t
,
instance
,
noxuResourceClient
,
noxuDefinition
)
require
.
NoError
(
t
,
err
)
uid
:=
createdNoxuInstance
.
GetUID
()
err
=
noxuResourceClient
.
Delete
(
name
,
&
metav1
.
DeleteOptions
{
Preconditions
:
&
metav1
.
Preconditions
{
UID
:
&
uid
,
},
})
require
.
NoError
(
t
,
err
)
// Deleting something with a finalizer sets deletion timestamp to a not-nil value but does not
// remove the object from the API server. Here we read it to confirm this.
gottenNoxuInstance
,
err
:=
noxuResourceClient
.
Get
(
name
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
gottenNoxuInstance
.
GetDeletionTimestamp
())
// Trying to delete it again to confirm it will not remove the object because finalizer is still there.
err
=
noxuResourceClient
.
Delete
(
name
,
&
metav1
.
DeleteOptions
{
Preconditions
:
&
metav1
.
Preconditions
{
UID
:
&
uid
,
},
})
require
.
NoError
(
t
,
err
)
// Removing the finalizers to allow the following delete remove the object.
// This step will fail if previous delete wrongly removed the object.
for
{
gottenNoxuInstance
.
SetFinalizers
(
nil
)
_
,
err
=
noxuResourceClient
.
Update
(
gottenNoxuInstance
)
if
err
==
nil
{
break
}
if
!
errors
.
IsConflict
(
err
)
{
require
.
NoError
(
t
,
err
)
// Fail on unexpected error
}
gottenNoxuInstance
,
err
=
noxuResourceClient
.
Get
(
name
)
require
.
NoError
(
t
,
err
)
}
// Now when finalizer is not there it should be possible to actually remove the object from the server.
err
=
noxuResourceClient
.
Delete
(
name
,
&
metav1
.
DeleteOptions
{
Preconditions
:
&
metav1
.
Preconditions
{
UID
:
&
uid
,
},
})
require
.
NoError
(
t
,
err
)
// Check that the object is actually gone.
_
,
err
=
noxuResourceClient
.
Get
(
name
)
require
.
Error
(
t
,
err
)
require
.
True
(
t
,
errors
.
IsNotFound
(
err
),
"%#v"
,
err
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment