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
d3c07657
Commit
d3c07657
authored
Nov 17, 2017
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename GenericAdmissionWebhook to ValidatingAdmissionWebhook
parent
920a5b31
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
30 deletions
+30
-30
config-test.sh
cluster/gce/config-test.sh
+1
-1
options_test.go
cmd/kube-apiserver/app/options/options_test.go
+2
-2
local-up-cluster.sh
hack/local-up-cluster.sh
+1
-1
admission.go
...rver/pkg/admission/plugin/webhook/validating/admission.go
+22
-22
admission_test.go
...pkg/admission/plugin/webhook/validating/admission_test.go
+4
-4
No files found.
cluster/gce/config-test.sh
View file @
d3c07657
...
...
@@ -321,7 +321,7 @@ if [[ -z "${KUBE_ADMISSION_CONTROL:-}" ]]; then
ADMISSION_CONTROL
=
"
${
ADMISSION_CONTROL
}
,PodSecurityPolicy"
fi
# ResourceQuota must come last, or a creation is recorded, but the pod may be forbidden.
ADMISSION_CONTROL
=
"
${
ADMISSION_CONTROL
}
,
Generic
AdmissionWebhook,ResourceQuota"
ADMISSION_CONTROL
=
"
${
ADMISSION_CONTROL
}
,
Validating
AdmissionWebhook,ResourceQuota"
else
ADMISSION_CONTROL
=
${
KUBE_ADMISSION_CONTROL
}
fi
...
...
cmd/kube-apiserver/app/options/options_test.go
View file @
d3c07657
...
...
@@ -104,8 +104,8 @@ func TestAddFlags(t *testing.T) {
MinRequestTimeout
:
1800
,
},
Admission
:
&
apiserveroptions
.
AdmissionOptions
{
RecommendedPluginOrder
:
[]
string
{
"MutatingAdmissionWebhook"
,
"NamespaceLifecycle"
,
"Initializers"
,
"
Generic
AdmissionWebhook"
},
DefaultOffPlugins
:
[]
string
{
"MutatingAdmissionWebhook"
,
"Initializers"
,
"
Generic
AdmissionWebhook"
},
RecommendedPluginOrder
:
[]
string
{
"MutatingAdmissionWebhook"
,
"NamespaceLifecycle"
,
"Initializers"
,
"
Validating
AdmissionWebhook"
},
DefaultOffPlugins
:
[]
string
{
"MutatingAdmissionWebhook"
,
"Initializers"
,
"
Validating
AdmissionWebhook"
},
PluginNames
:
[]
string
{
"AlwaysDeny"
},
ConfigFile
:
"/admission-control-config"
,
Plugins
:
s
.
Admission
.
Plugins
,
...
...
hack/local-up-cluster.sh
View file @
d3c07657
...
...
@@ -419,7 +419,7 @@ function start_apiserver {
fi
# Admission Controllers to invoke prior to persisting objects in cluster
ADMISSION_CONTROL
=
MutatingAdmissionWebhook,Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount
${
security_admission
}
,DefaultStorageClass,DefaultTolerationSeconds,
Generic
AdmissionWebhook,ResourceQuota
ADMISSION_CONTROL
=
MutatingAdmissionWebhook,Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount
${
security_admission
}
,DefaultStorageClass,DefaultTolerationSeconds,
Validating
AdmissionWebhook,ResourceQuota
# This is the default dir and filename where the apiserver will generate a self-signed cert
# which should be able to be used as the CA to verify itself
...
...
staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/validating/admission.go
View file @
d3c07657
...
...
@@ -50,13 +50,13 @@ import (
const
(
// Name of admission plug-in
PluginName
=
"
Generic
AdmissionWebhook"
PluginName
=
"
Validating
AdmissionWebhook"
)
// Register registers a plugin
func
Register
(
plugins
*
admission
.
Plugins
)
{
plugins
.
Register
(
PluginName
,
func
(
configFile
io
.
Reader
)
(
admission
.
Interface
,
error
)
{
plugin
,
err
:=
New
Generic
AdmissionWebhook
(
configFile
)
plugin
,
err
:=
New
Validating
AdmissionWebhook
(
configFile
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -71,8 +71,8 @@ type WebhookSource interface {
Webhooks
()
(
*
v1alpha1
.
ValidatingWebhookConfiguration
,
error
)
}
// New
Generic
AdmissionWebhook returns a generic admission webhook plugin.
func
New
GenericAdmissionWebhook
(
configFile
io
.
Reader
)
(
*
Generic
AdmissionWebhook
,
error
)
{
// New
Validating
AdmissionWebhook returns a generic admission webhook plugin.
func
New
ValidatingAdmissionWebhook
(
configFile
io
.
Reader
)
(
*
Validating
AdmissionWebhook
,
error
)
{
kubeconfigFile
,
err
:=
config
.
LoadConfig
(
configFile
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -90,7 +90,7 @@ func NewGenericAdmissionWebhook(configFile io.Reader) (*GenericAdmissionWebhook,
cm
.
SetAuthenticationInfoResolver
(
authInfoResolver
)
cm
.
SetServiceResolver
(
config
.
NewDefaultServiceResolver
())
return
&
Generic
AdmissionWebhook
{
return
&
Validating
AdmissionWebhook
{
Handler
:
admission
.
NewHandler
(
admission
.
Connect
,
admission
.
Create
,
...
...
@@ -101,8 +101,8 @@ func NewGenericAdmissionWebhook(configFile io.Reader) (*GenericAdmissionWebhook,
},
nil
}
//
Generic
AdmissionWebhook is an implementation of admission.Interface.
type
Generic
AdmissionWebhook
struct
{
//
Validating
AdmissionWebhook is an implementation of admission.Interface.
type
Validating
AdmissionWebhook
struct
{
*
admission
.
Handler
hookSource
WebhookSource
namespaceMatcher
namespace
.
Matcher
...
...
@@ -111,22 +111,22 @@ type GenericAdmissionWebhook struct {
}
var
(
_
=
genericadmissioninit
.
WantsExternalKubeClientSet
(
&
Generic
AdmissionWebhook
{})
_
=
genericadmissioninit
.
WantsExternalKubeClientSet
(
&
Validating
AdmissionWebhook
{})
)
// TODO find a better way wire this, but keep this pull small for now.
func
(
a
*
Generic
AdmissionWebhook
)
SetAuthenticationInfoResolverWrapper
(
wrapper
config
.
AuthenticationInfoResolverWrapper
)
{
func
(
a
*
Validating
AdmissionWebhook
)
SetAuthenticationInfoResolverWrapper
(
wrapper
config
.
AuthenticationInfoResolverWrapper
)
{
a
.
clientManager
.
SetAuthenticationInfoResolverWrapper
(
wrapper
)
}
// SetServiceResolver sets a service resolver for the webhook admission plugin.
// Passing a nil resolver does not have an effect, instead a default one will be used.
func
(
a
*
Generic
AdmissionWebhook
)
SetServiceResolver
(
sr
config
.
ServiceResolver
)
{
func
(
a
*
Validating
AdmissionWebhook
)
SetServiceResolver
(
sr
config
.
ServiceResolver
)
{
a
.
clientManager
.
SetServiceResolver
(
sr
)
}
// SetScheme sets a serializer(NegotiatedSerializer) which is derived from the scheme
func
(
a
*
Generic
AdmissionWebhook
)
SetScheme
(
scheme
*
runtime
.
Scheme
)
{
func
(
a
*
Validating
AdmissionWebhook
)
SetScheme
(
scheme
*
runtime
.
Scheme
)
{
if
scheme
!=
nil
{
a
.
clientManager
.
SetNegotiatedSerializer
(
serializer
.
NegotiatedSerializerWrapper
(
runtime
.
SerializerInfo
{
Serializer
:
serializer
.
NewCodecFactory
(
scheme
)
.
LegacyCodec
(
admissionv1alpha1
.
SchemeGroupVersion
),
...
...
@@ -136,37 +136,37 @@ func (a *GenericAdmissionWebhook) SetScheme(scheme *runtime.Scheme) {
}
// WantsExternalKubeClientSet defines a function which sets external ClientSet for admission plugins that need it
func
(
a
*
Generic
AdmissionWebhook
)
SetExternalKubeClientSet
(
client
clientset
.
Interface
)
{
func
(
a
*
Validating
AdmissionWebhook
)
SetExternalKubeClientSet
(
client
clientset
.
Interface
)
{
a
.
namespaceMatcher
.
Client
=
client
a
.
hookSource
=
configuration
.
NewValidatingWebhookConfigurationManager
(
client
.
AdmissionregistrationV1alpha1
()
.
ValidatingWebhookConfigurations
())
}
// SetExternalKubeInformerFactory implements the WantsExternalKubeInformerFactory interface.
func
(
a
*
Generic
AdmissionWebhook
)
SetExternalKubeInformerFactory
(
f
informers
.
SharedInformerFactory
)
{
func
(
a
*
Validating
AdmissionWebhook
)
SetExternalKubeInformerFactory
(
f
informers
.
SharedInformerFactory
)
{
namespaceInformer
:=
f
.
Core
()
.
V1
()
.
Namespaces
()
a
.
namespaceMatcher
.
NamespaceLister
=
namespaceInformer
.
Lister
()
a
.
SetReadyFunc
(
namespaceInformer
.
Informer
()
.
HasSynced
)
}
// ValidateInitialization implements the InitializationValidator interface.
func
(
a
*
Generic
AdmissionWebhook
)
ValidateInitialization
()
error
{
func
(
a
*
Validating
AdmissionWebhook
)
ValidateInitialization
()
error
{
if
a
.
hookSource
==
nil
{
return
fmt
.
Errorf
(
"
Generic
AdmissionWebhook admission plugin requires a Kubernetes client to be provided"
)
return
fmt
.
Errorf
(
"
Validating
AdmissionWebhook admission plugin requires a Kubernetes client to be provided"
)
}
if
err
:=
a
.
namespaceMatcher
.
Validate
();
err
!=
nil
{
return
fmt
.
Errorf
(
"
Generic
AdmissionWebhook.namespaceMatcher is not properly setup: %v"
,
err
)
return
fmt
.
Errorf
(
"
Validating
AdmissionWebhook.namespaceMatcher is not properly setup: %v"
,
err
)
}
if
err
:=
a
.
clientManager
.
Validate
();
err
!=
nil
{
return
fmt
.
Errorf
(
"
Generic
AdmissionWebhook.clientManager is not properly setup: %v"
,
err
)
return
fmt
.
Errorf
(
"
Validating
AdmissionWebhook.clientManager is not properly setup: %v"
,
err
)
}
if
err
:=
a
.
convertor
.
Validate
();
err
!=
nil
{
return
fmt
.
Errorf
(
"
Generic
AdmissionWebhook.convertor is not properly setup: %v"
,
err
)
return
fmt
.
Errorf
(
"
Validating
AdmissionWebhook.convertor is not properly setup: %v"
,
err
)
}
go
a
.
hookSource
.
Run
(
wait
.
NeverStop
)
return
nil
}
func
(
a
*
Generic
AdmissionWebhook
)
loadConfiguration
(
attr
admission
.
Attributes
)
(
*
v1alpha1
.
ValidatingWebhookConfiguration
,
error
)
{
func
(
a
*
Validating
AdmissionWebhook
)
loadConfiguration
(
attr
admission
.
Attributes
)
(
*
v1alpha1
.
ValidatingWebhookConfiguration
,
error
)
{
hookConfig
,
err
:=
a
.
hookSource
.
Webhooks
()
// if Webhook configuration is disabled, fail open
if
err
==
configuration
.
ErrDisabled
{
...
...
@@ -186,7 +186,7 @@ func (a *GenericAdmissionWebhook) loadConfiguration(attr admission.Attributes) (
}
// Admit makes an admission decision based on the request attributes.
func
(
a
*
Generic
AdmissionWebhook
)
Admit
(
attr
admission
.
Attributes
)
error
{
func
(
a
*
Validating
AdmissionWebhook
)
Admit
(
attr
admission
.
Attributes
)
error
{
hookConfig
,
err
:=
a
.
loadConfiguration
(
attr
)
if
err
!=
nil
{
return
err
...
...
@@ -280,7 +280,7 @@ func (a *GenericAdmissionWebhook) Admit(attr admission.Attributes) error {
}
// TODO: factor into a common place along with the validating webhook version.
func
(
a
*
Generic
AdmissionWebhook
)
shouldCallHook
(
h
*
v1alpha1
.
Webhook
,
attr
admission
.
Attributes
)
(
bool
,
*
apierrors
.
StatusError
)
{
func
(
a
*
Validating
AdmissionWebhook
)
shouldCallHook
(
h
*
v1alpha1
.
Webhook
,
attr
admission
.
Attributes
)
(
bool
,
*
apierrors
.
StatusError
)
{
var
matches
bool
for
_
,
r
:=
range
h
.
Rules
{
m
:=
rules
.
Matcher
{
Rule
:
r
,
Attr
:
attr
}
...
...
@@ -296,7 +296,7 @@ func (a *GenericAdmissionWebhook) shouldCallHook(h *v1alpha1.Webhook, attr admis
return
a
.
namespaceMatcher
.
MatchNamespaceSelector
(
h
,
attr
)
}
func
(
a
*
Generic
AdmissionWebhook
)
callHook
(
ctx
context
.
Context
,
h
*
v1alpha1
.
Webhook
,
attr
admission
.
Attributes
)
error
{
func
(
a
*
Validating
AdmissionWebhook
)
callHook
(
ctx
context
.
Context
,
h
*
v1alpha1
.
Webhook
,
attr
admission
.
Attributes
)
error
{
// Make the webhook request
request
:=
request
.
CreateAdmissionReview
(
attr
)
client
,
err
:=
a
.
clientManager
.
HookClient
(
h
)
...
...
staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/validating/admission_test.go
View file @
d3c07657
...
...
@@ -116,7 +116,7 @@ func (c urlConfigGenerator) ccfgURL(urlPath string) registrationv1alpha1.Webhook
}
}
// TestAdmit tests that
Generic
AdmissionWebhook#Admit works as expected
// TestAdmit tests that
Validating
AdmissionWebhook#Admit works as expected
func
TestAdmit
(
t
*
testing
.
T
)
{
scheme
:=
runtime
.
NewScheme
()
v1alpha1
.
AddToScheme
(
scheme
)
...
...
@@ -129,7 +129,7 @@ func TestAdmit(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"this should never happen? %v"
,
err
)
}
wh
,
err
:=
New
Generic
AdmissionWebhook
(
nil
)
wh
,
err
:=
New
Validating
AdmissionWebhook
(
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -410,7 +410,7 @@ func TestAdmit(t *testing.T) {
}
}
// TestAdmitCachedClient tests that
Generic
AdmissionWebhook#Admit should cache restClient
// TestAdmitCachedClient tests that
Validating
AdmissionWebhook#Admit should cache restClient
func
TestAdmitCachedClient
(
t
*
testing
.
T
)
{
scheme
:=
runtime
.
NewScheme
()
v1alpha1
.
AddToScheme
(
scheme
)
...
...
@@ -423,7 +423,7 @@ func TestAdmitCachedClient(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"this should never happen? %v"
,
err
)
}
wh
,
err
:=
New
Generic
AdmissionWebhook
(
nil
)
wh
,
err
:=
New
Validating
AdmissionWebhook
(
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
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