Skip to content

Commit 14778b7

Browse files
authored
Merge pull request #12066 from liggitt/lifecycle-admission-1.3
Only pay attention to origin types in project lifecycle admission - 1.3.x
2 parents cb227ce + f5b0c61 commit 14778b7

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

pkg/cmd/server/origin/master_config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ var (
322322

323323
// KubeAdmissionPlugins gives the in-order default admission chain for kube resources.
324324
KubeAdmissionPlugins = []string{
325-
"RunOnceDuration",
326325
lifecycle.PluginName,
326+
"RunOnceDuration",
327327
"PodNodeConstraints",
328328
"OriginPodNodeEnvironment",
329329
overrideapi.PluginName,
@@ -350,14 +350,14 @@ var (
350350
// When possible, this list is used. The set of openshift+kube chains must exactly match this set. In addition,
351351
// the order specified in the openshift and kube chains must match the order here.
352352
CombinedAdmissionControlPlugins = []string{
353+
lifecycle.PluginName,
353354
"ProjectRequestLimit",
354355
"OriginNamespaceLifecycle",
355356
"PodNodeConstraints",
356357
"openshift.io/JenkinsBootstrapper",
357358
"BuildByStrategy",
358359
imageadmission.PluginName,
359360
"RunOnceDuration",
360-
lifecycle.PluginName,
361361
"PodNodeConstraints",
362362
"OriginPodNodeEnvironment",
363363
overrideapi.PluginName,

pkg/project/admission/lifecycle/admission.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"k8s.io/kubernetes/pkg/util/sets"
1616

1717
"github.com/openshift/origin/pkg/api"
18+
"github.com/openshift/origin/pkg/api/latest"
1819
oadmission "github.com/openshift/origin/pkg/cmd/server/admission"
1920
"github.com/openshift/origin/pkg/project/cache"
2021
projectutil "github.com/openshift/origin/pkg/project/util"
@@ -40,12 +41,15 @@ var recommendedCreatableResources = sets.NewString("resourceaccessreviews", "loc
4041
var _ = oadmission.WantsProjectCache(&lifecycle{})
4142
var _ = oadmission.Validator(&lifecycle{})
4243

43-
// Admit enforces that a namespace must exist in order to associate content with it.
44-
// Admit enforces that a namespace that is terminating cannot accept new content being associated with it.
44+
// Admit enforces that a namespace must have the openshift finalizer associated with it in order to create origin API objects within it
4545
func (e *lifecycle) Admit(a admission.Attributes) (err error) {
4646
if len(a.GetNamespace()) == 0 {
4747
return nil
4848
}
49+
// only pay attention to origin resources
50+
if !latest.OriginKind(a.GetKind()) {
51+
return nil
52+
}
4953
// always allow a SAR request through, the SAR will return information about
5054
// the ability to take action on the object, no need to verify it here.
5155
if isSubjectAccessReview(a) {

pkg/project/admission/lifecycle/admission_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestAdmissionExists(t *testing.T) {
7373
Phase: buildapi.BuildPhaseNew,
7474
},
7575
}
76-
err := handler.Admit(admission.NewAttributesRecord(build, nil, kapi.Kind("Build").WithVersion("version"), "namespace", "name", kapi.Resource("builds").WithVersion("version"), "", "CREATE", nil))
76+
err := handler.Admit(admission.NewAttributesRecord(build, nil, kapi.Kind("Build").WithVersion("v1"), "namespace", "name", kapi.Resource("builds").WithVersion("v1"), "", "CREATE", nil))
7777
if err == nil {
7878
t.Errorf("Expected an error because namespace does not exist")
7979
}
@@ -106,7 +106,7 @@ func TestSAR(t *testing.T) {
106106
}
107107

108108
for k, v := range tests {
109-
err := handler.Admit(admission.NewAttributesRecord(nil, nil, kapi.Kind(v.kind).WithVersion("version"), "foo", "name", kapi.Resource(v.resource).WithVersion("version"), "", "CREATE", nil))
109+
err := handler.Admit(admission.NewAttributesRecord(nil, nil, kapi.Kind(v.kind).WithVersion("v1"), "foo", "name", kapi.Resource(v.resource).WithVersion("v1"), "", "CREATE", nil))
110110
if err != nil {
111111
t.Errorf("Unexpected error for %s returned from admission handler: %v", k, err)
112112
}

0 commit comments

Comments
 (0)