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
ea54a0c5
Commit
ea54a0c5
authored
Aug 15, 2018
by
Mehdy Bohlool
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
E2E Test
parent
8235e389
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
26 deletions
+70
-26
crd_conversion_webhook.go
test/e2e/apimachinery/crd_conversion_webhook.go
+0
-0
webhook.go
test/e2e/apimachinery/webhook.go
+18
-12
crd_util.go
test/e2e/framework/crd_util.go
+51
-14
manifest.go
test/utils/image/manifest.go
+1
-0
No files found.
test/e2e/apimachinery/crd_conversion_webhook.go
0 → 100644
View file @
ea54a0c5
This diff is collapsed.
Click to expand it.
test/e2e/apimachinery/webhook.go
View file @
ea54a0c5
...
@@ -136,7 +136,7 @@ var _ = SIGDescribe("AdmissionWebhook", func() {
...
@@ -136,7 +136,7 @@ var _ = SIGDescribe("AdmissionWebhook", func() {
defer
testcrd
.
CleanUp
()
defer
testcrd
.
CleanUp
()
webhookCleanup
:=
registerWebhookForCustomResource
(
f
,
context
,
testcrd
)
webhookCleanup
:=
registerWebhookForCustomResource
(
f
,
context
,
testcrd
)
defer
webhookCleanup
()
defer
webhookCleanup
()
testCustomResourceWebhook
(
f
,
testcrd
.
Crd
,
testcrd
.
DynamicClient
)
testCustomResourceWebhook
(
f
,
testcrd
.
Crd
,
testcrd
.
GetV1DynamicClient
()
)
})
})
It
(
"Should unconditionally reject operations on fail closed webhook"
,
func
()
{
It
(
"Should unconditionally reject operations on fail closed webhook"
,
func
()
{
...
@@ -173,7 +173,7 @@ var _ = SIGDescribe("AdmissionWebhook", func() {
...
@@ -173,7 +173,7 @@ var _ = SIGDescribe("AdmissionWebhook", func() {
defer
testcrd
.
CleanUp
()
defer
testcrd
.
CleanUp
()
webhookCleanup
:=
registerMutatingWebhookForCustomResource
(
f
,
context
,
testcrd
)
webhookCleanup
:=
registerMutatingWebhookForCustomResource
(
f
,
context
,
testcrd
)
defer
webhookCleanup
()
defer
webhookCleanup
()
testMutatingCustomResourceWebhook
(
f
,
testcrd
.
Crd
,
testcrd
.
DynamicClient
)
testMutatingCustomResourceWebhook
(
f
,
testcrd
.
Crd
,
testcrd
.
GetV1DynamicClient
()
)
})
})
It
(
"Should deny crd creation"
,
func
()
{
It
(
"Should deny crd creation"
,
func
()
{
...
@@ -1157,7 +1157,7 @@ func registerWebhookForCustomResource(f *framework.Framework, context *certConte
...
@@ -1157,7 +1157,7 @@ func registerWebhookForCustomResource(f *framework.Framework, context *certConte
Operations
:
[]
v1beta1
.
OperationType
{
v1beta1
.
Create
},
Operations
:
[]
v1beta1
.
OperationType
{
v1beta1
.
Create
},
Rule
:
v1beta1
.
Rule
{
Rule
:
v1beta1
.
Rule
{
APIGroups
:
[]
string
{
testcrd
.
ApiGroup
},
APIGroups
:
[]
string
{
testcrd
.
ApiGroup
},
APIVersions
:
[]
string
{
testcrd
.
ApiVersion
}
,
APIVersions
:
testcrd
.
GetAPIVersions
()
,
Resources
:
[]
string
{
testcrd
.
GetPluralName
()},
Resources
:
[]
string
{
testcrd
.
GetPluralName
()},
},
},
}},
}},
...
@@ -1198,7 +1198,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c
...
@@ -1198,7 +1198,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c
Operations
:
[]
v1beta1
.
OperationType
{
v1beta1
.
Create
},
Operations
:
[]
v1beta1
.
OperationType
{
v1beta1
.
Create
},
Rule
:
v1beta1
.
Rule
{
Rule
:
v1beta1
.
Rule
{
APIGroups
:
[]
string
{
testcrd
.
ApiGroup
},
APIGroups
:
[]
string
{
testcrd
.
ApiGroup
},
APIVersions
:
[]
string
{
testcrd
.
ApiVersion
}
,
APIVersions
:
testcrd
.
GetAPIVersions
()
,
Resources
:
[]
string
{
testcrd
.
GetPluralName
()},
Resources
:
[]
string
{
testcrd
.
GetPluralName
()},
},
},
}},
}},
...
@@ -1217,7 +1217,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c
...
@@ -1217,7 +1217,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c
Operations
:
[]
v1beta1
.
OperationType
{
v1beta1
.
Create
},
Operations
:
[]
v1beta1
.
OperationType
{
v1beta1
.
Create
},
Rule
:
v1beta1
.
Rule
{
Rule
:
v1beta1
.
Rule
{
APIGroups
:
[]
string
{
testcrd
.
ApiGroup
},
APIGroups
:
[]
string
{
testcrd
.
ApiGroup
},
APIVersions
:
[]
string
{
testcrd
.
ApiVersion
}
,
APIVersions
:
testcrd
.
GetAPIVersions
()
,
Resources
:
[]
string
{
testcrd
.
GetPluralName
()},
Resources
:
[]
string
{
testcrd
.
GetPluralName
()},
},
},
}},
}},
...
@@ -1343,12 +1343,18 @@ func testCRDDenyWebhook(f *framework.Framework) {
...
@@ -1343,12 +1343,18 @@ func testCRDDenyWebhook(f *framework.Framework) {
name
:=
fmt
.
Sprintf
(
"e2e-test-%s-%s-crd"
,
f
.
BaseName
,
"deny"
)
name
:=
fmt
.
Sprintf
(
"e2e-test-%s-%s-crd"
,
f
.
BaseName
,
"deny"
)
kind
:=
fmt
.
Sprintf
(
"E2e-test-%s-%s-crd"
,
f
.
BaseName
,
"deny"
)
kind
:=
fmt
.
Sprintf
(
"E2e-test-%s-%s-crd"
,
f
.
BaseName
,
"deny"
)
group
:=
fmt
.
Sprintf
(
"%s-crd-test.k8s.io"
,
f
.
BaseName
)
group
:=
fmt
.
Sprintf
(
"%s-crd-test.k8s.io"
,
f
.
BaseName
)
apiVersion
:=
"v1"
apiVersions
:=
[]
apiextensionsv1beta1
.
CustomResourceDefinitionVersion
{
{
Name
:
"v1"
,
Served
:
true
,
Storage
:
true
,
},
}
testcrd
:=
&
framework
.
TestCrd
{
testcrd
:=
&
framework
.
TestCrd
{
Name
:
name
,
Name
:
name
,
Kind
:
kind
,
Kind
:
kind
,
ApiGroup
:
group
,
ApiGroup
:
group
,
ApiVersion
:
apiVersion
,
Versions
:
apiVersions
,
}
}
// Creating a custom resource definition for use by assorted tests.
// Creating a custom resource definition for use by assorted tests.
...
@@ -1370,8 +1376,8 @@ func testCRDDenyWebhook(f *framework.Framework) {
...
@@ -1370,8 +1376,8 @@ func testCRDDenyWebhook(f *framework.Framework) {
},
},
},
},
Spec
:
apiextensionsv1beta1
.
CustomResourceDefinitionSpec
{
Spec
:
apiextensionsv1beta1
.
CustomResourceDefinitionSpec
{
Group
:
testcrd
.
ApiGroup
,
Group
:
testcrd
.
ApiGroup
,
Version
:
testcrd
.
ApiVersion
,
Version
s
:
testcrd
.
Versions
,
Names
:
apiextensionsv1beta1
.
CustomResourceDefinitionNames
{
Names
:
apiextensionsv1beta1
.
CustomResourceDefinitionNames
{
Plural
:
testcrd
.
GetPluralName
(),
Plural
:
testcrd
.
GetPluralName
(),
Singular
:
testcrd
.
Name
,
Singular
:
testcrd
.
Name
,
...
...
test/e2e/framework/crd_util.go
View file @
ea54a0c5
...
@@ -35,25 +35,23 @@ type TestCrd struct {
...
@@ -35,25 +35,23 @@ type TestCrd struct {
Name
string
Name
string
Kind
string
Kind
string
ApiGroup
string
ApiGroup
string
ApiVersion
string
Versions
[]
apiextensionsv1beta1
.
CustomResourceDefinitionVersion
ApiExtensionClient
*
crdclientset
.
Clientset
ApiExtensionClient
*
crdclientset
.
Clientset
Crd
*
apiextensionsv1beta1
.
CustomResourceDefinition
Crd
*
apiextensionsv1beta1
.
CustomResourceDefinition
DynamicClient
dynamic
.
ResourceInterface
DynamicClient
s
map
[
string
]
dynamic
.
ResourceInterface
CleanUp
CleanCrdFn
CleanUp
CleanCrdFn
}
}
// CreateTestCRD creates a new CRD specifically for the calling test.
// CreateTestCRD creates a new CRD specifically for the calling test.
func
Create
TestCRD
(
f
*
Framework
)
(
*
TestCrd
,
error
)
{
func
Create
MultiVersionTestCRD
(
f
*
Framework
,
group
string
,
apiVersions
[]
apiextensionsv1beta1
.
CustomResourceDefinitionVersion
,
conversionWebhook
*
apiextensionsv1beta1
.
WebhookClientConfig
)
(
*
TestCrd
,
error
)
{
suffix
:=
randomSuffix
()
suffix
:=
randomSuffix
()
name
:=
fmt
.
Sprintf
(
"e2e-test-%s-%s-crd"
,
f
.
BaseName
,
suffix
)
name
:=
fmt
.
Sprintf
(
"e2e-test-%s-%s-crd"
,
f
.
BaseName
,
suffix
)
kind
:=
fmt
.
Sprintf
(
"E2e-test-%s-%s-crd"
,
f
.
BaseName
,
suffix
)
kind
:=
fmt
.
Sprintf
(
"E2e-test-%s-%s-crd"
,
f
.
BaseName
,
suffix
)
group
:=
fmt
.
Sprintf
(
"%s-crd-test.k8s.io"
,
f
.
BaseName
)
apiVersion
:=
"v1"
testcrd
:=
&
TestCrd
{
testcrd
:=
&
TestCrd
{
Name
:
name
,
Name
:
name
,
Kind
:
kind
,
Kind
:
kind
,
ApiGroup
:
group
,
ApiGroup
:
group
,
ApiVersion
:
apiVersion
,
Versions
:
apiVersions
,
}
}
// Creating a custom resource definition for use by assorted tests.
// Creating a custom resource definition for use by assorted tests.
...
@@ -75,6 +73,13 @@ func CreateTestCRD(f *Framework) (*TestCrd, error) {
...
@@ -75,6 +73,13 @@ func CreateTestCRD(f *Framework) (*TestCrd, error) {
crd
:=
newCRDForTest
(
testcrd
)
crd
:=
newCRDForTest
(
testcrd
)
if
conversionWebhook
!=
nil
{
crd
.
Spec
.
Conversion
=
&
apiextensionsv1beta1
.
CustomResourceConversion
{
Strategy
:
"Webhook"
,
WebhookClientConfig
:
conversionWebhook
,
}
}
//create CRD and waits for the resource to be recognized and available.
//create CRD and waits for the resource to be recognized and available.
crd
,
err
=
fixtures
.
CreateNewCustomResourceDefinitionWatchUnsafe
(
crd
,
apiExtensionClient
)
crd
,
err
=
fixtures
.
CreateNewCustomResourceDefinitionWatchUnsafe
(
crd
,
apiExtensionClient
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -82,12 +87,17 @@ func CreateTestCRD(f *Framework) (*TestCrd, error) {
...
@@ -82,12 +87,17 @@ func CreateTestCRD(f *Framework) (*TestCrd, error) {
return
nil
,
err
return
nil
,
err
}
}
gvr
:=
schema
.
GroupVersionResource
{
Group
:
crd
.
Spec
.
Group
,
Version
:
crd
.
Spec
.
Version
,
Resource
:
crd
.
Spec
.
Names
.
Plural
}
resourceClients
:=
map
[
string
]
dynamic
.
ResourceInterface
{}
resourceClient
:=
dynamicClient
.
Resource
(
gvr
)
.
Namespace
(
f
.
Namespace
.
Name
)
for
_
,
v
:=
range
crd
.
Spec
.
Versions
{
if
v
.
Served
{
gvr
:=
schema
.
GroupVersionResource
{
Group
:
crd
.
Spec
.
Group
,
Version
:
v
.
Name
,
Resource
:
crd
.
Spec
.
Names
.
Plural
}
resourceClients
[
v
.
Name
]
=
dynamicClient
.
Resource
(
gvr
)
.
Namespace
(
f
.
Namespace
.
Name
)
}
}
testcrd
.
ApiExtensionClient
=
apiExtensionClient
testcrd
.
ApiExtensionClient
=
apiExtensionClient
testcrd
.
Crd
=
crd
testcrd
.
Crd
=
crd
testcrd
.
DynamicClient
=
resourceClient
testcrd
.
DynamicClient
s
=
resourceClients
testcrd
.
CleanUp
=
func
()
error
{
testcrd
.
CleanUp
=
func
()
error
{
err
:=
fixtures
.
DeleteCustomResourceDefinition
(
crd
,
apiExtensionClient
)
err
:=
fixtures
.
DeleteCustomResourceDefinition
(
crd
,
apiExtensionClient
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -98,13 +108,26 @@ func CreateTestCRD(f *Framework) (*TestCrd, error) {
...
@@ -98,13 +108,26 @@ func CreateTestCRD(f *Framework) (*TestCrd, error) {
return
testcrd
,
nil
return
testcrd
,
nil
}
}
// CreateTestCRD creates a new CRD specifically for the calling test.
func
CreateTestCRD
(
f
*
Framework
)
(
*
TestCrd
,
error
)
{
group
:=
fmt
.
Sprintf
(
"%s-crd-test.k8s.io"
,
f
.
BaseName
)
apiVersions
:=
[]
apiextensionsv1beta1
.
CustomResourceDefinitionVersion
{
{
Name
:
"v1"
,
Served
:
true
,
Storage
:
true
,
},
}
return
CreateMultiVersionTestCRD
(
f
,
group
,
apiVersions
,
nil
)
}
// newCRDForTest generates a CRD definition for the test
// newCRDForTest generates a CRD definition for the test
func
newCRDForTest
(
testcrd
*
TestCrd
)
*
apiextensionsv1beta1
.
CustomResourceDefinition
{
func
newCRDForTest
(
testcrd
*
TestCrd
)
*
apiextensionsv1beta1
.
CustomResourceDefinition
{
return
&
apiextensionsv1beta1
.
CustomResourceDefinition
{
return
&
apiextensionsv1beta1
.
CustomResourceDefinition
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
testcrd
.
GetMetaName
()},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
testcrd
.
GetMetaName
()},
Spec
:
apiextensionsv1beta1
.
CustomResourceDefinitionSpec
{
Spec
:
apiextensionsv1beta1
.
CustomResourceDefinitionSpec
{
Group
:
testcrd
.
ApiGroup
,
Group
:
testcrd
.
ApiGroup
,
Version
:
testcrd
.
ApiVersion
,
Version
s
:
testcrd
.
Versions
,
Names
:
apiextensionsv1beta1
.
CustomResourceDefinitionNames
{
Names
:
apiextensionsv1beta1
.
CustomResourceDefinitionNames
{
Plural
:
testcrd
.
GetPluralName
(),
Plural
:
testcrd
.
GetPluralName
(),
Singular
:
testcrd
.
Name
,
Singular
:
testcrd
.
Name
,
...
@@ -130,3 +153,17 @@ func (c *TestCrd) GetPluralName() string {
...
@@ -130,3 +153,17 @@ func (c *TestCrd) GetPluralName() string {
func
(
c
*
TestCrd
)
GetListName
()
string
{
func
(
c
*
TestCrd
)
GetListName
()
string
{
return
c
.
Name
+
"List"
return
c
.
Name
+
"List"
}
}
func
(
c
*
TestCrd
)
GetAPIVersions
()
[]
string
{
ret
:=
[]
string
{}
for
_
,
v
:=
range
c
.
Versions
{
if
v
.
Served
{
ret
=
append
(
ret
,
v
.
Name
)
}
}
return
ret
}
func
(
c
*
TestCrd
)
GetV1DynamicClient
()
dynamic
.
ResourceInterface
{
return
c
.
DynamicClients
[
"v1"
]
}
test/utils/image/manifest.go
View file @
ea54a0c5
...
@@ -92,6 +92,7 @@ var (
...
@@ -92,6 +92,7 @@ var (
// Preconfigured image configs
// Preconfigured image configs
var
(
var
(
CRDConversionWebhook
=
Config
{
e2eRegistry
,
"crd-conversion-webhook"
,
"1.13rev2"
}
AdmissionWebhook
=
Config
{
e2eRegistry
,
"webhook"
,
"1.13v1"
}
AdmissionWebhook
=
Config
{
e2eRegistry
,
"webhook"
,
"1.13v1"
}
APIServer
=
Config
{
e2eRegistry
,
"sample-apiserver"
,
"1.10"
}
APIServer
=
Config
{
e2eRegistry
,
"sample-apiserver"
,
"1.10"
}
AppArmorLoader
=
Config
{
e2eRegistry
,
"apparmor-loader"
,
"1.0"
}
AppArmorLoader
=
Config
{
e2eRegistry
,
"apparmor-loader"
,
"1.0"
}
...
...
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