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
fcd646d8
Commit
fcd646d8
authored
Aug 21, 2017
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let the initializer admission plugin set the metadata.intializers to nil
if an update makes the pendings and the result both nil
parent
f2993b81
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
+26
-3
initialization.go
plugin/pkg/admission/initialization/initialization.go
+3
-0
objectmeta.go
.../src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
+0
-3
initializers.go
test/e2e/apimachinery/initializers.go
+23
-0
No files found.
plugin/pkg/admission/initialization/initialization.go
View file @
fcd646d8
...
@@ -208,6 +208,9 @@ func (i *initializer) Admit(a admission.Attributes) (err error) {
...
@@ -208,6 +208,9 @@ func (i *initializer) Admit(a admission.Attributes) (err error) {
glog
.
V
(
5
)
.
Infof
(
"Modifying uninitialized resource %s"
,
a
.
GetResource
())
glog
.
V
(
5
)
.
Infof
(
"Modifying uninitialized resource %s"
,
a
.
GetResource
())
if
updated
!=
nil
&&
len
(
updated
.
Pending
)
==
0
&&
updated
.
Result
==
nil
{
accessor
.
SetInitializers
(
nil
)
}
// because we are called before validation, we need to ensure the update transition is valid.
// because we are called before validation, we need to ensure the update transition is valid.
if
errs
:=
validation
.
ValidateInitializersUpdate
(
updated
,
existing
,
initializerFieldPath
);
len
(
errs
)
>
0
{
if
errs
:=
validation
.
ValidateInitializersUpdate
(
updated
,
existing
,
initializerFieldPath
);
len
(
errs
)
>
0
{
return
errors
.
NewInvalid
(
a
.
GetKind
()
.
GroupKind
(),
a
.
GetName
(),
errs
)
return
errors
.
NewInvalid
(
a
.
GetKind
()
.
GroupKind
(),
a
.
GetName
(),
errs
)
...
...
staging/src/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
View file @
fcd646d8
...
@@ -200,9 +200,6 @@ func ValidateInitializers(initializers *metav1.Initializers, fldPath *field.Path
...
@@ -200,9 +200,6 @@ func ValidateInitializers(initializers *metav1.Initializers, fldPath *field.Path
}
}
}
}
allErrs
=
append
(
allErrs
,
validateInitializersResult
(
initializers
.
Result
,
fldPath
.
Child
(
"result"
))
...
)
allErrs
=
append
(
allErrs
,
validateInitializersResult
(
initializers
.
Result
,
fldPath
.
Child
(
"result"
))
...
)
if
len
(
initializers
.
Pending
)
==
0
&&
initializers
.
Result
==
nil
{
allErrs
=
append
(
allErrs
,
field
.
Invalid
(
fldPath
.
Child
(
"pending"
),
nil
,
"must be non-empty when result is not set"
))
}
return
allErrs
return
allErrs
}
}
...
...
test/e2e/apimachinery/initializers.go
View file @
fcd646d8
...
@@ -262,6 +262,29 @@ var _ = SIGDescribe("Initializers", func() {
...
@@ -262,6 +262,29 @@ var _ = SIGDescribe("Initializers", func() {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
len
(
pods
.
Items
))
.
Should
(
Equal
(
1
))
Expect
(
len
(
pods
.
Items
))
.
Should
(
Equal
(
1
))
})
})
It
(
"will be set to nil if a patch removes the last pending initializer"
,
func
()
{
ns
:=
f
.
Namespace
.
Name
c
:=
f
.
ClientSet
podName
:=
"to-be-patch-initialized-pod"
framework
.
Logf
(
"Creating pod %s"
,
podName
)
// TODO: lower the timeout so that the server responds faster.
_
,
err
:=
c
.
CoreV1
()
.
Pods
(
ns
)
.
Create
(
newUninitializedPod
(
podName
))
if
err
!=
nil
&&
!
errors
.
IsTimeout
(
err
)
{
framework
.
Failf
(
"expect err to be timeout error, got %v"
,
err
)
}
uninitializedPod
,
err
:=
c
.
CoreV1
()
.
Pods
(
ns
)
.
Get
(
podName
,
metav1
.
GetOptions
{})
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
uninitializedPod
.
Initializers
)
.
NotTo
(
BeNil
())
Expect
(
len
(
uninitializedPod
.
Initializers
.
Pending
))
.
Should
(
Equal
(
1
))
patch
:=
fmt
.
Sprintf
(
`{"metadata":{"initializers":{"pending":[{"$patch":"delete","name":"%s"}]}}}`
,
uninitializedPod
.
Initializers
.
Pending
[
0
]
.
Name
)
patchedPod
,
err
:=
c
.
CoreV1
()
.
Pods
(
ns
)
.
Patch
(
uninitializedPod
.
Name
,
types
.
StrategicMergePatchType
,
[]
byte
(
patch
))
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
patchedPod
.
Initializers
)
.
To
(
BeNil
())
})
})
})
func
newUninitializedPod
(
podName
string
)
*
v1
.
Pod
{
func
newUninitializedPod
(
podName
string
)
*
v1
.
Pod
{
...
...
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