Allow specifying a default namespace used across all the releases (#39)
* Allow specifying a default namespace used across all the releases Omit `namespace` in `charts[].namespace` of charts.yaml and then run `helmfile sync -n yourns` to install your charts into `yourns`. Resolves #31
This commit is contained in:
		
							parent
							
								
									f02790d566
								
							
						
					
					
						commit
						efdede1658
					
				
							
								
								
									
										12
									
								
								main.go
								
								
								
								
							
							
						
						
									
										12
									
								
								main.go
								
								
								
								
							|  | @ -38,6 +38,10 @@ func main() { | ||||||
| 			Name:  "kube-context", | 			Name:  "kube-context", | ||||||
| 			Usage: "Set kubectl context. Uses current context by default", | 			Usage: "Set kubectl context. Uses current context by default", | ||||||
| 		}, | 		}, | ||||||
|  | 		cli.StringFlag{ | ||||||
|  | 			Name:  "namespace, n", | ||||||
|  | 			Usage: "Set namespace. Uses the namespace set in the context by default", | ||||||
|  | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	app.Commands = []cli.Command{ | 	app.Commands = []cli.Command{ | ||||||
|  | @ -232,6 +236,7 @@ func before(c *cli.Context) (*state.HelmState, helmexec.Interface, error) { | ||||||
| 	file := c.GlobalString("file") | 	file := c.GlobalString("file") | ||||||
| 	quiet := c.GlobalBool("quiet") | 	quiet := c.GlobalBool("quiet") | ||||||
| 	kubeContext := c.GlobalString("kube-context") | 	kubeContext := c.GlobalString("kube-context") | ||||||
|  | 	namespace := c.GlobalString("namespace") | ||||||
| 
 | 
 | ||||||
| 	state, err := state.ReadFromFile(file) | 	state, err := state.ReadFromFile(file) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | @ -244,6 +249,13 @@ func before(c *cli.Context) (*state.HelmState, helmexec.Interface, error) { | ||||||
| 		} | 		} | ||||||
| 		kubeContext = state.Context | 		kubeContext = state.Context | ||||||
| 	} | 	} | ||||||
|  | 	if namespace != "" { | ||||||
|  | 		if state.Namespace != "" { | ||||||
|  | 			log.Printf("err: Cannot use option --namespace and set attribute namespace.") | ||||||
|  | 			os.Exit(1) | ||||||
|  | 		} | ||||||
|  | 		state.Namespace = namespace | ||||||
|  | 	} | ||||||
| 	var writer io.Writer | 	var writer io.Writer | ||||||
| 	if !quiet { | 	if !quiet { | ||||||
| 		writer = os.Stdout | 		writer = os.Stdout | ||||||
|  |  | ||||||
|  | @ -21,6 +21,7 @@ import ( | ||||||
| type HelmState struct { | type HelmState struct { | ||||||
| 	BaseChartPath string | 	BaseChartPath string | ||||||
| 	Context       string           `yaml:"context"` | 	Context       string           `yaml:"context"` | ||||||
|  | 	Namespace     string           `yaml:"namespace"` | ||||||
| 	Repositories  []RepositorySpec `yaml:"repositories"` | 	Repositories  []RepositorySpec `yaml:"repositories"` | ||||||
| 	Charts        []ChartSpec      `yaml:"charts"` | 	Charts        []ChartSpec      `yaml:"charts"` | ||||||
| } | } | ||||||
|  | @ -99,6 +100,11 @@ func renderTemplateString(s string) (string, error) { | ||||||
| 	return tplString.String(), nil | 	return tplString.String(), nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (state *HelmState) applyDefaultsTo(spec ChartSpec) ChartSpec { | ||||||
|  | 	spec.Namespace = state.Namespace | ||||||
|  | 	return spec | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (state *HelmState) SyncRepos(helm helmexec.Interface) []error { | func (state *HelmState) SyncRepos(helm helmexec.Interface) []error { | ||||||
| 	var wg sync.WaitGroup | 	var wg sync.WaitGroup | ||||||
| 	errs := []error{} | 	errs := []error{} | ||||||
|  | @ -137,8 +143,8 @@ func (state *HelmState) SyncCharts(helm helmexec.Interface, additonalValues []st | ||||||
| 	for w := 1; w <= workerLimit; w++ { | 	for w := 1; w <= workerLimit; w++ { | ||||||
| 		go func() { | 		go func() { | ||||||
| 			for chart := range jobQueue { | 			for chart := range jobQueue { | ||||||
| 
 | 				chartWithDefaults := state.applyDefaultsTo(chart) | ||||||
| 				flags, flagsErr := flagsForChart(state.BaseChartPath, &chart) | 				flags, flagsErr := flagsForChart(state.BaseChartPath, &chartWithDefaults) | ||||||
| 				if flagsErr != nil { | 				if flagsErr != nil { | ||||||
| 					errQueue <- flagsErr | 					errQueue <- flagsErr | ||||||
| 					doneQueue <- true | 					doneQueue <- true | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue