Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter out 'turn this on' config structs for admission #16639

Merged
merged 2 commits into from
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions pkg/cmd/server/origin/admission/chain_builder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package admission

import (
"bytes"
"io"
"io/ioutil"
"net"
"reflect"
"strings"
Expand All @@ -16,6 +19,7 @@ import (

oadmission "github.com/openshift/origin/pkg/cmd/server/admission"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
configlatest "github.com/openshift/origin/pkg/cmd/server/api/latest"
"github.com/openshift/origin/pkg/cmd/util/pluginconfig"
imageadmission "github.com/openshift/origin/pkg/image/admission"
imagepolicy "github.com/openshift/origin/pkg/image/admission/imagepolicy/api"
Expand Down Expand Up @@ -351,3 +355,50 @@ func dedupe(input []string) []string {
}
return result
}

func init() {
// add a filter that will remove DefaultAdmissionConfig
admission.FactoryFilterFn = filterEnableAdmissionConfigs
}

func filterEnableAdmissionConfigs(delegate admission.Factory) admission.Factory {
return func(config io.Reader) (admission.Interface, error) {
config1, config2, err := splitStream(config)
if err != nil {
return nil, err
}
// if the config isn't a DefaultAdmissionConfig, then assume we're enabled (we were called after all)
// if the config *is* a DefaultAdmissionConfig and it explicitly said
obj, err := configlatest.ReadYAML(config1)
// if we can't read it, let the plugin deal with it
if err != nil {
return delegate(config2)
}
// if nothing was there, let the plugin deal with it
if obj == nil {
return delegate(config2)
}
// if it wasn't a DefaultAdmissionConfig object, let the plugin deal with it
if _, ok := obj.(*configapi.DefaultAdmissionConfig); !ok {
return delegate(config2)
}

// if it was a DefaultAdmissionConfig, then it must have said "enabled" and it wasn't really meant for the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it say "enabled"? it can be disabled too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it say "enabled"? it can be disabled too.

Not if you get here, right? It will have already run the "ispluginenabled" check by the time this method is called.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deads2k agree, noticed later.

// admission plugin
return delegate(nil)
}
}

// splitStream reads the stream bytes and constructs two copies of it.
func splitStream(config io.Reader) (io.Reader, io.Reader, error) {
if config == nil || reflect.ValueOf(config).IsNil() {
return nil, nil, nil
}

configBytes, err := ioutil.ReadAll(config)
if err != nil {
return nil, nil, err
}

return bytes.NewBuffer(configBytes), bytes.NewBuffer(configBytes), nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.