@@ -16,8 +16,9 @@ import (
1616
1717 "github.com/covexo/devspace/pkg/devspace/config/configutil"
1818 "github.com/covexo/devspace/pkg/devspace/config/v1"
19- helmClient "github.com/covexo/devspace/pkg/devspace/deploy/ helm"
19+ helmClient "github.com/covexo/devspace/pkg/devspace/helm"
2020 "github.com/covexo/devspace/pkg/devspace/kubectl"
21+ "github.com/covexo/devspace/pkg/devspace/services"
2122 "github.com/covexo/devspace/pkg/util/log"
2223 "github.com/russross/blackfriday"
2324 "github.com/skratchdot/open-golang/open"
@@ -43,17 +44,20 @@ type addSyncCmdFlags struct {
4344 LocalPath string
4445 ContainerPath string
4546 ExcludedPaths string
47+ Namespace string
4648}
4749
4850type addPortCmdFlags struct {
4951 ResourceType string
5052 Selector string
53+ Namespace string
5154}
5255
5356type addPackageFlags struct {
5457 AppVersion string
5558 ChartVersion string
5659 SkipQuestion bool
60+ Deployment string
5761}
5862
5963func init () {
@@ -105,6 +109,7 @@ func init() {
105109 addSyncCmd .Flags ().StringVar (& cmd .syncFlags .ResourceType , "resource-type" , "pod" , "Selected resource type" )
106110 addSyncCmd .Flags ().StringVar (& cmd .syncFlags .Selector , "selector" , "" , "Comma separated key=value selector list (e.g. release=test)" )
107111 addSyncCmd .Flags ().StringVar (& cmd .syncFlags .LocalPath , "local" , "" , "Relative local path" )
112+ addSyncCmd .Flags ().StringVar (& cmd .syncFlags .Namespace , "namespace" , "" , "Namespace to use" )
108113 addSyncCmd .Flags ().StringVar (& cmd .syncFlags .ContainerPath , "container" , "" , "Absolute container path" )
109114 addSyncCmd .Flags ().StringVar (& cmd .syncFlags .ExcludedPaths , "exclude" , "" , "Comma separated list of paths to exclude (e.g. node_modules/,bin,*.exe)" )
110115
@@ -128,6 +133,7 @@ func init() {
128133 }
129134
130135 addPortCmd .Flags ().StringVar (& cmd .portFlags .ResourceType , "resource-type" , "pod" , "Selected resource type" )
136+ addPortCmd .Flags ().StringVar (& cmd .portFlags .Namespace , "namespace" , "" , "Namespace to use" )
131137 addPortCmd .Flags ().StringVar (& cmd .portFlags .Selector , "selector" , "" , "Comma separated key=value selector list (e.g. release=test)" )
132138
133139 addCmd .AddCommand (addPortCmd )
@@ -147,27 +153,49 @@ func init() {
147153 devspace add package
148154 devspace add package mysql
149155 devspace add package mysql --app-version=5.7.14
150- devspace add package mysql --chart-version=0.10.3
156+ devspace add package mysql --chart-version=0.10.3 -d devspace-default
151157 #######################################################
152158 ` ,
153159 Run : cmd .RunAddPackage ,
154160 }
155161
156162 addPackageCmd .Flags ().StringVar (& cmd .packageFlags .AppVersion , "app-version" , "" , "App version" )
157163 addPackageCmd .Flags ().StringVar (& cmd .packageFlags .ChartVersion , "chart-version" , "" , "Chart version" )
164+ addPackageCmd .Flags ().StringVarP (& cmd .packageFlags .Deployment , "deployment" , "d" , "" , "The deployment name to use" )
158165 addPackageCmd .Flags ().BoolVar (& cmd .packageFlags .SkipQuestion , "skip-question" , false , "Skips the question to show the readme in a browser" )
159166
160167 addCmd .AddCommand (addPackageCmd )
161168}
162169
163170// RunAddPackage executes the add package command logic
164171func (cmd * AddCmd ) RunAddPackage (cobraCmd * cobra.Command , args []string ) {
172+ config := configutil .GetConfig ()
173+ if config .DevSpace .Deployments == nil || (len (* config .DevSpace .Deployments ) != 1 && cmd .packageFlags .Deployment == "" ) {
174+ log .Fatalf ("Please specify the deployment via the -d flag" )
175+ }
176+
177+ var deploymentConfig * v1.DeploymentConfig
178+ for _ , deployConfig := range * config .DevSpace .Deployments {
179+ if cmd .packageFlags .Deployment == "" || cmd .packageFlags .Deployment == * deployConfig .Name {
180+ if deployConfig .Helm == nil || deployConfig .Helm .ChartPath == nil {
181+ log .Fatalf ("Selected deployment %s is not a valid helm deployment" , * deployConfig .Name )
182+ }
183+
184+ deploymentConfig = deployConfig
185+ break
186+ }
187+ }
188+
189+ if deploymentConfig == nil {
190+ log .Fatalf ("Deployment %s not found" , cmd .packageFlags .Deployment )
191+ }
192+
165193 kubectl , err := kubectl .NewClient ()
166194 if err != nil {
167195 log .Fatalf ("Unable to create new kubectl client: %v" , err )
168196 }
169197
170- helm , err := helmClient .NewClient (kubectl , false )
198+ helm , err := helmClient .NewClient (kubectl , log . GetInstance (), false )
171199 if err != nil {
172200 log .Fatalf ("Error initializing helm client: %v" , err )
173201 }
@@ -186,13 +214,12 @@ func (cmd *AddCmd) RunAddPackage(cobraCmd *cobra.Command, args []string) {
186214 }
187215
188216 log .Done ("Chart found" )
189-
190- cwd , err := os .Getwd ()
217+ chartPath , err := filepath .Abs (* deploymentConfig .Helm .ChartPath )
191218 if err != nil {
192219 log .Fatal (err )
193220 }
194221
195- requirementsFile := filepath .Join (cwd , "chart" , "requirements.yaml" )
222+ requirementsFile := filepath .Join (chartPath , "requirements.yaml" )
196223 _ , err = os .Stat (requirementsFile )
197224 if os .IsNotExist (err ) {
198225 entry := "dependencies:\n " +
@@ -233,15 +260,15 @@ func (cmd *AddCmd) RunAddPackage(cobraCmd *cobra.Command, args []string) {
233260 }
234261
235262 log .StartWait ("Update chart dependencies" )
236- err = helm .UpdateDependencies (filepath . Join ( cwd , "chart" ) )
263+ err = helm .UpdateDependencies (chartPath )
237264 log .StopWait ()
238265
239266 if err != nil {
240267 log .Fatal (err )
241268 }
242269
243270 // Check if key already exists
244- valuesYaml := filepath .Join (cwd , "chart" , "values.yaml" )
271+ valuesYaml := filepath .Join (chartPath , "values.yaml" )
245272 valuesYamlContents := map [interface {}]interface {}{}
246273
247274 err = yamlutil .ReadYamlFromFile (valuesYaml , valuesYamlContents )
@@ -261,16 +288,11 @@ func (cmd *AddCmd) RunAddPackage(cobraCmd *cobra.Command, args []string) {
261288 }
262289 }
263290
264- log .Donef ("Successfully added %s as chart dependency, you can configure the package in 'chart /values.yaml'" , version .GetName ())
265- cmd .showReadme (version )
291+ log .Donef ("Successfully added %s as chart dependency, you can configure the package in '%s /values.yaml'" , * deploymentConfig . Helm . ChartPath , version .GetName ())
292+ cmd .showReadme (chartPath , version )
266293}
267294
268- func (cmd * AddCmd ) showReadme (chartVersion * repo.ChartVersion ) {
269- cwd , err := os .Getwd ()
270- if err != nil {
271- log .Fatal (err )
272- }
273-
295+ func (cmd * AddCmd ) showReadme (chartPath string , chartVersion * repo.ChartVersion ) {
274296 if cmd .packageFlags .SkipQuestion {
275297 return
276298 }
@@ -285,7 +307,7 @@ func (cmd *AddCmd) showReadme(chartVersion *repo.ChartVersion) {
285307 return
286308 }
287309
288- content , err := tar .ExtractSingleFileToStringTarGz (filepath .Join (cwd , "chart" , "charts" , chartVersion .GetName ()+ "-" + chartVersion .GetVersion ()+ ".tgz" ), chartVersion .GetName ()+ "/README.md" )
310+ content , err := tar .ExtractSingleFileToStringTarGz (filepath .Join (chartPath , "charts" , chartVersion .GetName ()+ "-" + chartVersion .GetVersion ()+ ".tgz" ), chartVersion .GetName ()+ "/README.md" )
289311 if err != nil {
290312 log .Fatal (err )
291313 }
@@ -312,17 +334,15 @@ func (cmd *AddCmd) RunAddSync(cobraCmd *cobra.Command, args []string) {
312334 config := configutil .GetConfig ()
313335
314336 if cmd .syncFlags .Selector == "" {
315- cmd .syncFlags .Selector = "release=" + * config . DevSpace . Release . Name
337+ cmd .syncFlags .Selector = "release=" + services . GetNameOfFirstHelmDeployment ()
316338 }
317339
318340 labelSelectorMap , err := parseSelectors (cmd .syncFlags .Selector )
319-
320341 if err != nil {
321342 log .Fatalf ("Error parsing selectors: %s" , err .Error ())
322343 }
323344
324345 excludedPaths := make ([]string , 0 , 0 )
325-
326346 if cmd .syncFlags .ExcludedPaths != "" {
327347 excludedPathStrings := strings .Split (cmd .syncFlags .ExcludedPaths , "," )
328348
@@ -333,10 +353,10 @@ func (cmd *AddCmd) RunAddSync(cobraCmd *cobra.Command, args []string) {
333353 }
334354
335355 workdir , err := os .Getwd ()
336-
337356 if err != nil {
338357 log .Fatalf ("Unable to determine current workdir: %s" , err .Error ())
339358 }
359+
340360 cmd .syncFlags .LocalPath = strings .TrimPrefix (cmd .syncFlags .LocalPath , workdir )
341361 cmd .syncFlags .LocalPath = "./" + strings .TrimPrefix (cmd .syncFlags .LocalPath , "./" )
342362
@@ -350,6 +370,7 @@ func (cmd *AddCmd) RunAddSync(cobraCmd *cobra.Command, args []string) {
350370 ContainerPath : configutil .String (cmd .syncFlags .ContainerPath ),
351371 LocalSubPath : configutil .String (cmd .syncFlags .LocalPath ),
352372 ExcludePaths : & excludedPaths ,
373+ Namespace : & cmd .syncFlags .Namespace ,
353374 })
354375
355376 config .DevSpace .Sync = & syncConfig
@@ -362,28 +383,23 @@ func (cmd *AddCmd) RunAddSync(cobraCmd *cobra.Command, args []string) {
362383
363384// RunAddPort executes the add port command logic
364385func (cmd * AddCmd ) RunAddPort (cobraCmd * cobra.Command , args []string ) {
365- config := configutil .GetConfig ()
366-
367386 if cmd .portFlags .Selector == "" {
368- cmd .portFlags .Selector = "release=" + * config . DevSpace . Release . Name
387+ cmd .portFlags .Selector = "release=" + services . GetNameOfFirstHelmDeployment ()
369388 }
370389
371390 labelSelectorMap , err := parseSelectors (cmd .portFlags .Selector )
372-
373391 if err != nil {
374392 log .Fatalf ("Error parsing selectors: %s" , err .Error ())
375393 }
376394
377395 portMappings , err := parsePortMappings (args [0 ])
378-
379396 if err != nil {
380397 log .Fatalf ("Error parsing port mappings: %s" , err .Error ())
381398 }
382399
383400 cmd .insertOrReplacePortMapping (labelSelectorMap , portMappings )
384401
385402 err = configutil .SaveConfig ()
386-
387403 if err != nil {
388404 log .Fatalf ("Couldn't save config file: %s" , err .Error ())
389405 }
@@ -393,7 +409,7 @@ func (cmd *AddCmd) insertOrReplacePortMapping(labelSelectorMap map[string]*strin
393409 config := configutil .GetConfig ()
394410
395411 // Check if we should add to existing port mapping
396- for _ , v := range * config .DevSpace .PortForwarding {
412+ for _ , v := range * config .DevSpace .Ports {
397413 var selectors map [string ]* string
398414
399415 if v .LabelSelector != nil {
@@ -402,21 +418,22 @@ func (cmd *AddCmd) insertOrReplacePortMapping(labelSelectorMap map[string]*strin
402418 selectors = map [string ]* string {}
403419 }
404420
405- if * v . ResourceType == cmd . portFlags . ResourceType && isMapEqual (selectors , labelSelectorMap ) {
421+ if isMapEqual (selectors , labelSelectorMap ) {
406422 portMap := append (* v .PortMappings , portMappings ... )
407423
408424 v .PortMappings = & portMap
409425
410426 return
411427 }
412428 }
413- portMap := append (* config .DevSpace .PortForwarding , & v1.PortForwardingConfig {
429+ portMap := append (* config .DevSpace .Ports , & v1.PortForwardingConfig {
414430 ResourceType : nil ,
415431 LabelSelector : & labelSelectorMap ,
416432 PortMappings : & portMappings ,
433+ Namespace : & cmd .portFlags .Namespace ,
417434 })
418435
419- config .DevSpace .PortForwarding = & portMap
436+ config .DevSpace .Ports = & portMap
420437}
421438
422439func isMapEqual (map1 map [string ]* string , map2 map [string ]* string ) bool {
0 commit comments