@@ -253,25 +253,26 @@ func (cmd *RemoveCmd) RunRemoveSync(cobraCmd *cobra.Command, args []string) {
253253 return
254254 }
255255
256- newSyncPaths := make ([]* v1.SyncConfig , 0 , len (* config .DevSpace .Sync )- 1 )
257-
258- for _ , v := range * config .DevSpace .Sync {
259- if cmd .syncFlags .RemoveAll ||
260- cmd .syncFlags .LocalPath == * v .LocalSubPath ||
261- cmd .syncFlags .ContainerPath == * v .ContainerPath ||
262- isMapEqual (labelSelectorMap , * v .LabelSelector ) {
263- continue
264- }
265-
266- newSyncPaths = append (newSyncPaths , v )
267- }
256+ if config .DevSpace .Sync != nil && len (* config .DevSpace .Sync ) > 0 {
257+ newSyncPaths := make ([]* v1.SyncConfig , 0 , len (* config .DevSpace .Sync )- 1 )
258+
259+ for _ , v := range * config .DevSpace .Sync {
260+ if cmd .syncFlags .RemoveAll ||
261+ cmd .syncFlags .LocalPath == * v .LocalSubPath ||
262+ cmd .syncFlags .ContainerPath == * v .ContainerPath ||
263+ isMapEqual (labelSelectorMap , * v .LabelSelector ) {
264+ continue
265+ }
268266
269- config .DevSpace .Sync = & newSyncPaths
267+ newSyncPaths = append (newSyncPaths , v )
268+ }
270269
271- err = configutil . SaveConfig ()
270+ config . DevSpace . Sync = & newSyncPaths
272271
273- if err != nil {
274- log .Fatalf ("Couldn't save config file: %s" , err .Error ())
272+ err = configutil .SaveConfig ()
273+ if err != nil {
274+ log .Fatalf ("Couldn't save config file: %s" , err .Error ())
275+ }
275276 }
276277}
277278
@@ -297,34 +298,37 @@ func (cmd *RemoveCmd) RunRemovePort(cobraCmd *cobra.Command, args []string) {
297298 }
298299
299300 ports := strings .Split (argPorts , "," )
300- newPortForwards := make ([]* v1.PortForwardingConfig , 0 , len (* config .DevSpace .Ports )- 1 )
301-
302- for _ , v := range * config .DevSpace .Ports {
303- if cmd .portFlags .RemoveAll || isMapEqual (labelSelectorMap , * v .LabelSelector ) {
304- continue
305- }
306301
307- newPortMappings := []* v1.PortMapping {}
302+ if config .DevSpace .Ports != nil && len (* config .DevSpace .Ports ) > 0 {
303+ newPortForwards := make ([]* v1.PortForwardingConfig , 0 , len (* config .DevSpace .Ports )- 1 )
308304
309- for _ , pm := range * v . PortMappings {
310- if containsPort ( strconv . Itoa ( * pm . LocalPort ), ports ) || containsPort ( strconv . Itoa ( * pm . RemotePort ), ports ) {
305+ for _ , v := range * config . DevSpace . Ports {
306+ if cmd . portFlags . RemoveAll || isMapEqual ( labelSelectorMap , * v . LabelSelector ) {
311307 continue
312308 }
313309
314- newPortMappings = append (newPortMappings , pm )
315- }
310+ newPortMappings := []* v1.PortMapping {}
311+
312+ for _ , pm := range * v .PortMappings {
313+ if containsPort (strconv .Itoa (* pm .LocalPort ), ports ) || containsPort (strconv .Itoa (* pm .RemotePort ), ports ) {
314+ continue
315+ }
316+
317+ newPortMappings = append (newPortMappings , pm )
318+ }
316319
317- if len (newPortMappings ) > 0 {
318- v .PortMappings = & newPortMappings
319- newPortForwards = append (newPortForwards , v )
320+ if len (newPortMappings ) > 0 {
321+ v .PortMappings = & newPortMappings
322+ newPortForwards = append (newPortForwards , v )
323+ }
320324 }
321- }
322325
323- config .DevSpace .Ports = & newPortForwards
326+ config .DevSpace .Ports = & newPortForwards
324327
325- err = configutil .SaveConfig ()
326- if err != nil {
327- log .Fatalf ("Couldn't save config file: %s" , err .Error ())
328+ err = configutil .SaveConfig ()
329+ if err != nil {
330+ log .Fatalf ("Couldn't save config file: %s" , err .Error ())
331+ }
328332 }
329333}
330334
0 commit comments