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
2fdc7e1f
Commit
2fdc7e1f
authored
Mar 07, 2019
by
jennybuckley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test to verify fix
parent
f9e57744
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
0 deletions
+105
-0
BUILD
test/integration/apiserver/apply/BUILD
+1
-0
apply_test.go
test/integration/apiserver/apply/apply_test.go
+104
-0
No files found.
test/integration/apiserver/apply/BUILD
View file @
2fdc7e1f
...
...
@@ -15,6 +15,7 @@ go_test(
"//pkg/master:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/features:go_default_library",
...
...
test/integration/apiserver/apply/apply_test.go
View file @
2fdc7e1f
...
...
@@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
genericfeatures
"k8s.io/apiserver/pkg/features"
...
...
@@ -438,3 +439,106 @@ func TestApplyRequiresFieldManager(t *testing.T) {
t
.
Fatalf
(
"Apply failed to create with fieldManager: %v"
,
err
)
}
}
// TestApplyRemoveContainerPort removes a container port from a deployment
func
TestApplyRemoveContainerPort
(
t
*
testing
.
T
)
{
defer
utilfeaturetesting
.
SetFeatureGateDuringTest
(
t
,
utilfeature
.
DefaultFeatureGate
,
genericfeatures
.
ServerSideApply
,
true
)()
_
,
client
,
closeFn
:=
setup
(
t
)
defer
closeFn
()
obj
:=
[]
byte
(
`{
"apiVersion": "extensions/v1beta1",
"kind": "Deployment",
"metadata": {
"name": "deployment",
"labels": {"app": "nginx"}
},
"spec": {
"replicas": 3,
"selector": {
"matchLabels": {
"app": "nginx"
}
},
"template": {
"metadata": {
"labels": {
"app": "nginx"
}
},
"spec": {
"containers": [{
"name": "nginx",
"image": "nginx:latest",
"ports": [{
"containerPort": 80,
"protocol": "TCP"
}]
}]
}
}
}
}`
)
_
,
err
:=
client
.
CoreV1
()
.
RESTClient
()
.
Patch
(
types
.
ApplyPatchType
)
.
AbsPath
(
"/apis/extensions/v1beta1"
)
.
Namespace
(
"default"
)
.
Resource
(
"deployments"
)
.
Name
(
"deployment"
)
.
Param
(
"fieldManager"
,
"apply_test"
)
.
Body
(
obj
)
.
Do
()
.
Get
()
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create object using Apply patch: %v"
,
err
)
}
obj
=
[]
byte
(
`{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "deployment",
"labels": {"app": "nginx"}
},
"spec": {
"replicas": 3,
"selector": {
"matchLabels": {
"app": "nginx"
}
},
"template": {
"metadata": {
"labels": {
"app": "nginx"
}
},
"spec": {
"containers": [{
"name": "nginx",
"image": "nginx:latest"
}]
}
}
}
}`
)
_
,
err
=
client
.
CoreV1
()
.
RESTClient
()
.
Patch
(
types
.
ApplyPatchType
)
.
AbsPath
(
"/apis/apps/v1"
)
.
Namespace
(
"default"
)
.
Resource
(
"deployments"
)
.
Name
(
"deployment"
)
.
Param
(
"fieldManager"
,
"apply_test"
)
.
Body
(
obj
)
.
Do
()
.
Get
()
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to remove container port using Apply patch: %v"
,
err
)
}
deployment
,
err
:=
client
.
AppsV1
()
.
Deployments
(
"default"
)
.
Get
(
"deployment"
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to retrieve object: %v"
,
err
)
}
if
len
(
deployment
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Ports
)
>
0
{
t
.
Fatalf
(
"Expected no container ports but got: %v"
,
deployment
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Ports
)
}
}
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