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
a38c2b4c
Commit
a38c2b4c
authored
May 22, 2017
by
Quintin Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add annotation for image policy webhook fail open.
parent
7043372d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
6 deletions
+28
-6
annotation_key_constants.go
pkg/api/annotation_key_constants.go
+4
-0
annotation_key_constants.go
pkg/api/v1/annotation_key_constants.go
+4
-0
admission.go
plugin/pkg/admission/imagepolicy/admission.go
+12
-6
annotation_key_constants.go
.../src/k8s.io/client-go/pkg/api/annotation_key_constants.go
+4
-0
annotation_key_constants.go
...c/k8s.io/client-go/pkg/api/v1/annotation_key_constants.go
+4
-0
No files found.
pkg/api/annotation_key_constants.go
View file @
a38c2b4c
...
...
@@ -19,6 +19,10 @@ limitations under the License.
package
api
const
(
// ImagePolicyFailedOpenKey is added to pods created by failing open when the image policy
// webhook backend fails.
ImagePolicyFailedOpenKey
string
=
"alpha.image-policy.k8s.io/failed-open"
// MirrorAnnotationKey represents the annotation key set by kubelets when creating mirror pods
MirrorPodAnnotationKey
string
=
"kubernetes.io/config.mirror"
...
...
pkg/api/v1/annotation_key_constants.go
View file @
a38c2b4c
...
...
@@ -19,6 +19,10 @@ limitations under the License.
package
v1
const
(
// ImagePolicyFailedOpenKey is added to pods created by failing open when the image policy
// webhook backend fails.
ImagePolicyFailedOpenKey
string
=
"alpha.image-policy.k8s.io/failed-open"
// MirrorAnnotationKey represents the annotation key set by kubelets when creating mirror pods
MirrorPodAnnotationKey
string
=
"kubernetes.io/config.mirror"
...
...
plugin/pkg/admission/imagepolicy/admission.go
View file @
a38c2b4c
...
...
@@ -89,10 +89,16 @@ func (a *imagePolicyWebhook) filterAnnotations(allAnnotations map[string]string)
}
// Function to call on webhook failure; behavior determined by defaultAllow flag
func
(
a
*
imagePolicyWebhook
)
webhookError
(
attributes
admission
.
Attributes
,
err
error
)
error
{
func
(
a
*
imagePolicyWebhook
)
webhookError
(
pod
*
api
.
Pod
,
attributes
admission
.
Attributes
,
err
error
)
error
{
if
err
!=
nil
{
glog
.
V
(
2
)
.
Infof
(
"error contacting webhook backend: %s"
,
err
)
if
a
.
defaultAllow
{
annotations
:=
pod
.
GetAnnotations
()
if
annotations
==
nil
{
annotations
=
make
(
map
[
string
]
string
)
}
annotations
[
api
.
ImagePolicyFailedOpenKey
]
=
"true"
pod
.
ObjectMeta
.
SetAnnotations
(
annotations
)
glog
.
V
(
2
)
.
Infof
(
"resource allowed in spite of webhook backend failure"
)
return
nil
}
...
...
@@ -134,13 +140,13 @@ func (a *imagePolicyWebhook) Admit(attributes admission.Attributes) (err error)
Namespace
:
attributes
.
GetNamespace
(),
},
}
if
err
:=
a
.
admitPod
(
attributes
,
&
imageReview
);
err
!=
nil
{
if
err
:=
a
.
admitPod
(
pod
,
attributes
,
&
imageReview
);
err
!=
nil
{
return
admission
.
NewForbidden
(
attributes
,
err
)
}
return
nil
}
func
(
a
*
imagePolicyWebhook
)
admitPod
(
attributes
admission
.
Attributes
,
review
*
v1alpha1
.
ImageReview
)
error
{
func
(
a
*
imagePolicyWebhook
)
admitPod
(
pod
*
api
.
Pod
,
attributes
admission
.
Attributes
,
review
*
v1alpha1
.
ImageReview
)
error
{
cacheKey
,
err
:=
json
.
Marshal
(
review
.
Spec
)
if
err
!=
nil
{
return
err
...
...
@@ -153,15 +159,15 @@ func (a *imagePolicyWebhook) admitPod(attributes admission.Attributes, review *v
})
if
err
:=
result
.
Error
();
err
!=
nil
{
return
a
.
webhookError
(
attributes
,
err
)
return
a
.
webhookError
(
pod
,
attributes
,
err
)
}
var
statusCode
int
if
result
.
StatusCode
(
&
statusCode
);
statusCode
<
200
||
statusCode
>=
300
{
return
a
.
webhookError
(
attributes
,
fmt
.
Errorf
(
"Error contacting webhook: %d"
,
statusCode
))
return
a
.
webhookError
(
pod
,
attributes
,
fmt
.
Errorf
(
"Error contacting webhook: %d"
,
statusCode
))
}
if
err
:=
result
.
Into
(
review
);
err
!=
nil
{
return
a
.
webhookError
(
attributes
,
err
)
return
a
.
webhookError
(
pod
,
attributes
,
err
)
}
a
.
responseCache
.
Add
(
string
(
cacheKey
),
review
.
Status
,
a
.
statusTTL
(
review
.
Status
))
...
...
staging/src/k8s.io/client-go/pkg/api/annotation_key_constants.go
View file @
a38c2b4c
...
...
@@ -19,6 +19,10 @@ limitations under the License.
package
api
const
(
// ImagePolicyFailedOpenKey is added to pods created by failing open when the image policy
// webhook backend fails.
ImagePolicyFailedOpenKey
string
=
"alpha.image-policy.k8s.io/failed-open"
// MirrorAnnotationKey represents the annotation key set by kubelets when creating mirror pods
MirrorPodAnnotationKey
string
=
"kubernetes.io/config.mirror"
...
...
staging/src/k8s.io/client-go/pkg/api/v1/annotation_key_constants.go
View file @
a38c2b4c
...
...
@@ -19,6 +19,10 @@ limitations under the License.
package
v1
const
(
// ImagePolicyFailedOpenKey is added to pods created by failing open when the image policy
// webhook backend fails.
ImagePolicyFailedOpenKey
string
=
"alpha.image-policy.k8s.io/failed-open"
// MirrorAnnotationKey represents the annotation key set by kubelets when creating mirror pods
MirrorPodAnnotationKey
string
=
"kubernetes.io/config.mirror"
...
...
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