forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.go
140 lines (124 loc) · 5.37 KB
/
register.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package admission
import (
"io"
"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apiserver/pkg/admission"
genericapiserver "k8s.io/apiserver/pkg/server"
kubeapiserver "k8s.io/kubernetes/cmd/kube-apiserver/app"
// Admission control plug-ins used by OpenShift
authorizationrestrictusers "github.com/openshift/origin/pkg/authorization/admission/restrictusers"
buildjenkinsbootstrapper "github.com/openshift/origin/pkg/build/admission/jenkinsbootstrapper"
buildsecretinjector "github.com/openshift/origin/pkg/build/admission/secretinjector"
buildstrategyrestrictions "github.com/openshift/origin/pkg/build/admission/strategyrestrictions"
imageadmission "github.com/openshift/origin/pkg/image/admission"
imagepolicy "github.com/openshift/origin/pkg/image/admission/imagepolicy"
ingressadmission "github.com/openshift/origin/pkg/ingress/admission"
projectlifecycle "github.com/openshift/origin/pkg/project/admission/lifecycle"
projectnodeenv "github.com/openshift/origin/pkg/project/admission/nodeenv"
projectrequestlimit "github.com/openshift/origin/pkg/project/admission/requestlimit"
quotaclusterresourceoverride "github.com/openshift/origin/pkg/quota/admission/clusterresourceoverride"
quotaclusterresourcequota "github.com/openshift/origin/pkg/quota/admission/clusterresourcequota"
quotarunonceduration "github.com/openshift/origin/pkg/quota/admission/runonceduration"
schedulerpodnodeconstraints "github.com/openshift/origin/pkg/scheduler/admission/podnodeconstraints"
securityadmission "github.com/openshift/origin/pkg/security/admission"
serviceadmit "github.com/openshift/origin/pkg/service/admission"
"k8s.io/kubernetes/plugin/pkg/admission/noderestriction"
storageclassdefaultadmission "k8s.io/kubernetes/plugin/pkg/admission/storageclass/setdefault"
imagepolicyapi "github.com/openshift/origin/pkg/image/admission/imagepolicy/api"
overrideapi "github.com/openshift/origin/pkg/quota/admission/clusterresourceoverride/api"
"k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle"
configlatest "github.com/openshift/origin/pkg/cmd/server/api/latest"
)
// TODO register this per apiserver or at least per process
var OriginAdmissionPlugins = &admission.Plugins{}
func init() {
RegisterAllAdmissionPlugins(OriginAdmissionPlugins)
}
// RegisterAllAdmissionPlugins registers all admission plugins
func RegisterAllAdmissionPlugins(plugins *admission.Plugins) {
kubeapiserver.RegisterAllAdmissionPlugins(plugins)
genericapiserver.RegisterAllAdmissionPlugins(plugins)
authorizationrestrictusers.Register(plugins)
buildjenkinsbootstrapper.Register(plugins)
buildsecretinjector.Register(plugins)
buildstrategyrestrictions.Register(plugins)
imageadmission.Register(plugins)
imagepolicy.Register(plugins)
ingressadmission.Register(plugins)
projectlifecycle.Register(plugins)
projectnodeenv.Register(plugins)
projectrequestlimit.Register(plugins)
quotaclusterresourceoverride.Register(plugins)
quotaclusterresourcequota.Register(plugins)
quotarunonceduration.Register(plugins)
schedulerpodnodeconstraints.Register(plugins)
securityadmission.Register(plugins)
securityadmission.RegisterSCCExecRestrictions(plugins)
serviceadmit.RegisterExternalIP(plugins)
serviceadmit.RegisterRestrictedEndpoints(plugins)
}
var (
DefaultOnPlugins = sets.NewString(
"OriginNamespaceLifecycle",
"openshift.io/JenkinsBootstrapper",
"openshift.io/BuildConfigSecretInjector",
"BuildByStrategy",
storageclassdefaultadmission.PluginName,
imageadmission.PluginName,
lifecycle.PluginName,
"OriginPodNodeEnvironment",
"PodNodeSelector",
serviceadmit.ExternalIPPluginName,
serviceadmit.RestrictedEndpointsPluginName,
"LimitRanger",
"ServiceAccount",
noderestriction.PluginName,
"SecurityContextConstraint",
"SCCExecRestrictions",
"PersistentVolumeLabel",
"DefaultStorageClass",
"OwnerReferencesPermissionEnforcement",
"ResourceQuota",
"openshift.io/ClusterResourceQuota",
"openshift.io/IngressAdmission",
)
// DefaultOffPlugins includes plugins which require explicit configuration to run
// if you wire them incorrectly, they may prevent the server from starting
DefaultOffPlugins = sets.NewString(
"ProjectRequestLimit",
"RunOnceDuration",
"PodNodeConstraints",
overrideapi.PluginName,
imagepolicyapi.PluginName,
"AlwaysPullImages",
"ImagePolicyWebhook",
"openshift.io/RestrictSubjectBindings",
"LimitPodHardAntiAffinityTopology",
"DefaultTolerationSeconds",
"PodPreset", // default to off while PodPreset is alpha
// these are new, reassess post-rebase
"Initializers",
"GenericAdmissionWebhook",
"PodTolerationRestriction",
)
)
func init() {
admission.PluginEnabledFn = IsAdmissionPluginActivated
}
func IsAdmissionPluginActivated(name string, config io.Reader) bool {
// only intercept if we have an explicit enable or disable. If the check fails in any way,
// assume that the config was a different type and let the actual admission plugin check it
if DefaultOnPlugins.Has(name) {
if enabled, err := configlatest.IsAdmissionPluginActivated(config, true); err == nil && !enabled {
glog.V(2).Infof("Admission plugin %v is disabled. It will not be started.", name)
return false
}
} else if DefaultOffPlugins.Has(name) {
if enabled, err := configlatest.IsAdmissionPluginActivated(config, false); err == nil && !enabled {
glog.V(2).Infof("Admission plugin %v is not enabled. It will not be started.", name)
return false
}
}
return true
}