Skip to content

Commit

Permalink
Added option to specify context (ericchiang#17)
Browse files Browse the repository at this point in the history
* Added option to specify context
  • Loading branch information
lnr0626 authored and ericchiang committed Sep 18, 2018
1 parent e959986 commit 6a55723
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type config struct {
kubeconfig string
kubeconfigContent string
kubeconfigContext string
}

func main() {
Expand All @@ -33,6 +34,10 @@ func main() {
Type: schema.TypeString,
Optional: true,
},
"kubeconfig_context": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
ResourcesMap: map[string]*schema.Resource{
"k8s_manifest": resourceManifest(),
Expand All @@ -41,6 +46,7 @@ func main() {
return &config{
kubeconfig: d.Get("kubeconfig").(string),
kubeconfigContent: d.Get("kubeconfig_content").(string),
kubeconfigContext: d.Get("kubeconfig_context").(string),
}, nil
},
}
Expand Down Expand Up @@ -119,6 +125,11 @@ func kubectl(m interface{}, kubeconfig string, args ...string) *exec.Cmd {
args = append([]string{"--kubeconfig", kubeconfig}, args...)
}

context := m.(*config).kubeconfigContext
if context != "" {
args = append([]string{"--context", context}, args...)
}

return exec.Command("kubectl", args...)
}

Expand Down

0 comments on commit 6a55723

Please sign in to comment.