// ReadPluginConfig will read a plugin configuration object from a reader stream func ReadPluginConfig(reader io.Reader, config runtime.Object) error { if reader == nil || reflect.ValueOf(reader).IsNil() { return nil } configBytes, err := ioutil.ReadAll(reader) if err != nil { return err } err = configlatest.ReadYAMLInto(configBytes, config) if err != nil { return err } return nil }
func GetConfigFromContainer(client *docker.Client) (*configapi.MasterConfig, error) { r, err := dockerhelper.StreamFileFromContainer(client, OpenShiftContainer, serverMasterConfig) if err != nil { return nil, err } defer r.Close() data, err := ioutil.ReadAll(r) if err != nil { return nil, err } config := &configapi.MasterConfig{} err = configapilatest.ReadYAMLInto(data, config) if err != nil { return nil, err } return config, nil }
func TestReadNodeConfigLocalVolumeDirQuota(t *testing.T) { tests := map[string]struct { config string expected string }{ "null quota": { config: ` apiVersion: v1 volumeConfig: localQuota: perFSGroup: null `, expected: "", }, "missing quota": { config: ` apiVersion: v1 volumeConfig: localQuota: `, expected: "", }, "missing localQuota": { config: ` apiVersion: v1 volumeConfig: `, expected: "", }, "missing volumeConfig": { config: ` apiVersion: v1 `, expected: "", }, "no unit (bytes) quota": { config: ` apiVersion: v1 volumeConfig: localQuota: perFSGroup: 200000 `, expected: "200k", }, "Kb quota": { config: ` apiVersion: v1 volumeConfig: localQuota: perFSGroup: 200Ki `, expected: "200Ki", }, "Mb quota": { config: ` apiVersion: v1 volumeConfig: localQuota: perFSGroup: 512Mi `, expected: "512Mi", }, "Gb quota": { config: ` apiVersion: v1 volumeConfig: localQuota: perFSGroup: 2Gi `, expected: "2Gi", }, "Tb quota": { config: ` apiVersion: v1 volumeConfig: localQuota: perFSGroup: 2Ti `, expected: "2Ti", }, // This is invalid config, would be caught by validation but just // testing it parses ok: "negative quota": { config: ` apiVersion: v1 volumeConfig: localQuota: perFSGroup: -512Mi `, expected: "-512Mi", }, "zero quota": { config: ` apiVersion: v1 volumeConfig: localQuota: perFSGroup: 0 `, expected: "0", }, } for name, test := range tests { t.Logf("Running test: %s", name) nodeConfig := &internal.NodeConfig{} if err := latest.ReadYAMLInto([]byte(test.config), nodeConfig); err != nil { t.Errorf("Error reading yaml: %s", err.Error()) } if test.expected == "" && nodeConfig.VolumeConfig.LocalQuota.PerFSGroup != nil { t.Errorf("Expected empty quota but got: %v", nodeConfig.VolumeConfig.LocalQuota.PerFSGroup) } if test.expected != "" { if nodeConfig.VolumeConfig.LocalQuota.PerFSGroup == nil { t.Errorf("Expected quota: %s, got: nil", test.expected) } else { amount := nodeConfig.VolumeConfig.LocalQuota.PerFSGroup t.Logf("%s", amount.String()) if test.expected != amount.String() { t.Errorf("Expected quota: %s, got: %s", test.expected, amount.String()) } } } } }