Skip to content

Commit 9e88910

Browse files
committed
Only pay attention to origin types in project lifecycle admission
1 parent d200e8a commit 9e88910

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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)