Skip to content

Commit 105055e

Browse files
Merge pull request #16639 from deads2k/server-46-admission
Automatic merge from submit-queue (batch tested with PRs 16657, 16607, 16647, 16639, 16655). filter out 'turn this on' config structs for admission Alternative to #16505 to allow our enablement of config. I think this aligns more closely with a goal of calling the "normal" https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/server/options/admission.go#L78 path.
2 parents 18fad10 + e357b7d commit 105055e

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

pkg/cmd/server/origin/admission/chain_builder.go

+51
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package admission
22

33
import (
4+
"bytes"
5+
"io"
6+
"io/ioutil"
47
"net"
58
"reflect"
69
"strings"
@@ -16,6 +19,7 @@ import (
1619

1720
oadmission "github.com/openshift/origin/pkg/cmd/server/admission"
1821
configapi "github.com/openshift/origin/pkg/cmd/server/api"
22+
configlatest "github.com/openshift/origin/pkg/cmd/server/api/latest"
1923
"github.com/openshift/origin/pkg/cmd/util/pluginconfig"
2024
imageadmission "github.com/openshift/origin/pkg/image/admission"
2125
imagepolicy "github.com/openshift/origin/pkg/image/admission/imagepolicy/api"
@@ -351,3 +355,50 @@ func dedupe(input []string) []string {
351355
}
352356
return result
353357
}
358+
359+
func init() {
360+
// add a filter that will remove DefaultAdmissionConfig
361+
admission.FactoryFilterFn = filterEnableAdmissionConfigs
362+
}
363+
364+
func filterEnableAdmissionConfigs(delegate admission.Factory) admission.Factory {
365+
return func(config io.Reader) (admission.Interface, error) {
366+
config1, config2, err := splitStream(config)
367+
if err != nil {
368+
return nil, err
369+
}
370+
// if the config isn't a DefaultAdmissionConfig, then assume we're enabled (we were called after all)
371+
// if the config *is* a DefaultAdmissionConfig and it explicitly said
372+
obj, err := configlatest.ReadYAML(config1)
373+
// if we can't read it, let the plugin deal with it
374+
if err != nil {
375+
return delegate(config2)
376+
}
377+
// if nothing was there, let the plugin deal with it
378+
if obj == nil {
379+
return delegate(config2)
380+
}
381+
// if it wasn't a DefaultAdmissionConfig object, let the plugin deal with it
382+
if _, ok := obj.(*configapi.DefaultAdmissionConfig); !ok {
383+
return delegate(config2)
384+
}
385+
386+
// if it was a DefaultAdmissionConfig, then it must have said "enabled" and it wasn't really meant for the
387+
// admission plugin
388+
return delegate(nil)
389+
}
390+
}
391+
392+
// splitStream reads the stream bytes and constructs two copies of it.
393+
func splitStream(config io.Reader) (io.Reader, io.Reader, error) {
394+
if config == nil || reflect.ValueOf(config).IsNil() {
395+
return nil, nil, nil
396+
}
397+
398+
configBytes, err := ioutil.ReadAll(config)
399+
if err != nil {
400+
return nil, nil, err
401+
}
402+
403+
return bytes.NewBuffer(configBytes), bytes.NewBuffer(configBytes), nil
404+
}

vendor/k8s.io/kubernetes/staging/src/k8s.io/apiserver/pkg/admission/patch.go

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/k8s.io/kubernetes/staging/src/k8s.io/apiserver/pkg/admission/plugins.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)