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
1ba644ef
Commit
1ba644ef
authored
Sep 25, 2018
by
jennybuckley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add e2e test for mutating webhooks affecting webhook-config objects
parent
bc6cb908
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
2 deletions
+68
-2
webhook.go
test/e2e/apimachinery/webhook.go
+0
-0
BUILD
test/images/webhook/BUILD
+1
-0
VERSION
test/images/webhook/VERSION
+1
-1
addlabel.go
test/images/webhook/addlabel.go
+60
-0
main.go
test/images/webhook/main.go
+5
-0
manifest.go
test/utils/image/manifest.go
+1
-1
No files found.
test/e2e/apimachinery/webhook.go
View file @
1ba644ef
This diff is collapsed.
Click to expand it.
test/images/webhook/BUILD
View file @
1ba644ef
...
...
@@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"addlabel.go",
"alwaysdeny.go",
"config.go",
"configmap.go",
...
...
test/images/webhook/VERSION
View file @
1ba644ef
1.1
2v2
1.1
3v1
test/images/webhook/addlabel.go
0 → 100644
View file @
1ba644ef
/*
Copyright 2018 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
main
import
(
"encoding/json"
"github.com/golang/glog"
"k8s.io/api/admission/v1beta1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
)
const
(
addFirstLabelPatch
string
=
`[
{ "op": "add", "path": "/metadata/labels", "value": {"added-label": "yes"}}
]`
addAdditionalLabelPatch
string
=
`[
{ "op": "add", "path": "/metadata/labels/added-label", "value": "yes" }
]`
)
// Add a label {"added-label": "yes"} to the object
func
addLabel
(
ar
v1beta1
.
AdmissionReview
)
*
v1beta1
.
AdmissionResponse
{
glog
.
V
(
2
)
.
Info
(
"calling add-label"
)
obj
:=
struct
{
metav1
.
ObjectMeta
Data
map
[
string
]
string
}{}
raw
:=
ar
.
Request
.
Object
.
Raw
err
:=
json
.
Unmarshal
(
raw
,
&
obj
)
if
err
!=
nil
{
glog
.
Error
(
err
)
return
toAdmissionResponse
(
err
)
}
reviewResponse
:=
v1beta1
.
AdmissionResponse
{}
reviewResponse
.
Allowed
=
true
if
len
(
obj
.
ObjectMeta
.
Labels
)
==
0
{
reviewResponse
.
Patch
=
[]
byte
(
addFirstLabelPatch
)
}
else
{
reviewResponse
.
Patch
=
[]
byte
(
addAdditionalLabelPatch
)
}
pt
:=
v1beta1
.
PatchTypeJSONPatch
reviewResponse
.
PatchType
=
&
pt
return
&
reviewResponse
}
test/images/webhook/main.go
View file @
1ba644ef
...
...
@@ -95,6 +95,10 @@ func serveAlwaysDeny(w http.ResponseWriter, r *http.Request) {
serve
(
w
,
r
,
alwaysDeny
)
}
func
serveAddLabel
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
serve
(
w
,
r
,
addLabel
)
}
func
servePods
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
serve
(
w
,
r
,
admitPods
)
}
...
...
@@ -133,6 +137,7 @@ func main() {
flag
.
Parse
()
http
.
HandleFunc
(
"/always-deny"
,
serveAlwaysDeny
)
http
.
HandleFunc
(
"/add-label"
,
serveAddLabel
)
http
.
HandleFunc
(
"/pods"
,
servePods
)
http
.
HandleFunc
(
"/pods/attach"
,
serveAttachingPods
)
http
.
HandleFunc
(
"/mutating-pods"
,
serveMutatePods
)
...
...
test/utils/image/manifest.go
View file @
1ba644ef
...
...
@@ -82,7 +82,7 @@ var (
PrivateRegistry
=
registry
.
PrivateRegistry
sampleRegistry
=
registry
.
SampleRegistry
AdmissionWebhook
=
ImageConfig
{
e2eRegistry
,
"webhook"
,
"1.1
2v2
"
}
AdmissionWebhook
=
ImageConfig
{
e2eRegistry
,
"webhook"
,
"1.1
3v1
"
}
APIServer
=
ImageConfig
{
e2eRegistry
,
"sample-apiserver"
,
"1.0"
}
AppArmorLoader
=
ImageConfig
{
e2eRegistry
,
"apparmor-loader"
,
"1.0"
}
BusyBox
=
ImageConfig
{
dockerLibraryRegistry
,
"busybox"
,
"1.29"
}
...
...
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