Skip to content

Commit

Permalink
allow --config option to load configmaps as well
Browse files Browse the repository at this point in the history
  • Loading branch information
theganyo committed Apr 15, 2020
1 parent 7591ef2 commit 3f26980
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ type RootArgs struct {
// Resolve is used to populate shared args, it's automatically called prior when creating the root command
func (r *RootArgs) Resolve(skipAuth, requireRuntime bool) error {

r.loadConfig()
if err := r.loadConfig(); err != nil {
return err
}

if r.IsLegacySaaS && r.IsOPDK {
return errors.New("--legacy and --opdk options are exclusive")
Expand Down Expand Up @@ -199,10 +201,22 @@ func (r *RootArgs) loadConfig() error {
if r.ConfigPath == "" {
return nil
}
c := &server.Config{}

yamlFile, err := ioutil.ReadFile(r.ConfigPath)
if err != nil {
return err
}

// load as either CRD or raw config
cm := &KubernetesCRD{}
c := &server.Config{}
err = yaml.Unmarshal(yamlFile, cm)
if err == nil {
err = yaml.Unmarshal(yamlFile, c)
if cm.Data == nil {
err = yaml.Unmarshal(yamlFile, c)
} else {
err = yaml.Unmarshal([]byte(cm.Data["config.yaml"]), c)
}
}
if err != nil {
return err
Expand Down

0 comments on commit 3f26980

Please sign in to comment.