func TestGetPluginConfig(t *testing.T) { configapi.Scheme.AddKnownTypes(oapi.SchemeGroupVersion, &TestConfig{}) configapi.Scheme.AddKnownTypeWithName(latest.Version.WithKind("TestConfig"), &TestConfigV1{}) testConfig := &TestConfig{ Item1: "item1value", Item2: []string{"element1", "element2"}, } cfg := configapi.AdmissionPluginConfig{ Location: "/path/to/my/config", Configuration: testConfig, } fileName, err := GetPluginConfig(cfg) if err != nil { t.Fatalf("unexpected error: %v", err) } resultConfig := &TestConfig{} if err = latest.ReadYAMLFileInto(fileName, resultConfig); err != nil { t.Fatalf("error reading config file: %v", err) } if !reflect.DeepEqual(testConfig, resultConfig) { t.Errorf("Unexpected config. Expected: %#v. Got: %#v", testConfig, resultConfig) } }
// ReadPluginConfig will read a plugin configuration object from a reader stream func ReadPluginConfig(pluginConfig map[string]configapi.AdmissionPluginConfig, name string, config runtime.Object) error { configFilePath, err := pluginconfig.GetPluginConfigFile(pluginConfig, name, "") if configFilePath == "" { return nil } err = configlatest.ReadYAMLFileInto(configFilePath, config) if err != nil { glog.Errorf("couldn't open plugin configuration %s: %#v", configFilePath, err) return err } return nil }