Skip to content

Commit b98df09

Browse files
committed
Fix nil pointer issue in add & remove package
1 parent dc4c940 commit b98df09

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

cmd/add.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ func (cmd *AddCmd) RunAddPackage(cobraCmd *cobra.Command, args []string) {
186186
}
187187
}
188188

189+
if deploymentConfig == nil {
190+
log.Fatalf("Deployment %s not found", cmd.packageFlags.Deployment)
191+
}
192+
189193
kubectl, err := kubectl.NewClient()
190194
if err != nil {
191195
log.Fatalf("Unable to create new kubectl client: %v", err)
@@ -414,7 +418,7 @@ func (cmd *AddCmd) insertOrReplacePortMapping(labelSelectorMap map[string]*strin
414418
selectors = map[string]*string{}
415419
}
416420

417-
if *v.ResourceType == cmd.portFlags.ResourceType && isMapEqual(selectors, labelSelectorMap) {
421+
if isMapEqual(selectors, labelSelectorMap) {
418422
portMap := append(*v.PortMappings, portMappings...)
419423

420424
v.PortMappings = &portMap

cmd/remove.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ func (cmd *RemoveCmd) RunRemovePackage(cobraCmd *cobra.Command, args []string) {
153153
}
154154
}
155155

156+
if deploymentConfig == nil {
157+
log.Fatalf("Deployment %s not found", cmd.packageFlags.Deployment)
158+
}
159+
156160
chartPath, err := filepath.Abs(*deploymentConfig.Helm.ChartPath)
157161
if err != nil {
158162
log.Fatal(err)
@@ -277,13 +281,11 @@ func (cmd *RemoveCmd) RunRemovePort(cobraCmd *cobra.Command, args []string) {
277281
config := configutil.GetConfig()
278282

279283
labelSelectorMap, err := parseSelectors(cmd.portFlags.Selector)
280-
281284
if err != nil {
282285
log.Fatalf("Error parsing selectors: %s", err.Error())
283286
}
284287

285288
argPorts := ""
286-
287289
if len(args) == 1 {
288290
argPorts = args[0]
289291
}
@@ -298,20 +300,25 @@ func (cmd *RemoveCmd) RunRemovePort(cobraCmd *cobra.Command, args []string) {
298300
ports := strings.Split(argPorts, ",")
299301
newPortForwards := make([]*v1.PortForwardingConfig, 0, len(*config.DevSpace.Ports)-1)
300302

301-
OUTER:
302303
for _, v := range *config.DevSpace.Ports {
303-
if cmd.portFlags.RemoveAll ||
304-
isMapEqual(labelSelectorMap, *v.LabelSelector) {
304+
if cmd.portFlags.RemoveAll || isMapEqual(labelSelectorMap, *v.LabelSelector) {
305305
continue
306306
}
307307

308+
newPortMappings := []*v1.PortMapping{}
309+
308310
for _, pm := range *v.PortMappings {
309311
if containsPort(strconv.Itoa(*pm.LocalPort), ports) || containsPort(strconv.Itoa(*pm.RemotePort), ports) {
310-
continue OUTER
312+
continue
311313
}
314+
315+
newPortMappings = append(newPortMappings, pm)
312316
}
313317

314-
newPortForwards = append(newPortForwards, v)
318+
if len(newPortMappings) > 0 {
319+
v.PortMappings = &newPortMappings
320+
newPortForwards = append(newPortForwards, v)
321+
}
315322
}
316323

317324
config.DevSpace.Ports = &newPortForwards

cmd/status.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ func (cmd *StatusCmd) RunStatus(cobraCmd *cobra.Command, args []string) {
106106
"Internal Registry",
107107
"Not Deployed",
108108
"",
109-
"",
110109
err.Error(),
111110
})
112111
} else if registryStatus != nil {
@@ -212,7 +211,6 @@ func (cmd *StatusCmd) getRegistryStatus() ([]string, error) {
212211
return []string{
213212
"Internal Registry",
214213
"Running",
215-
pod.GetName(),
216214
pod.GetNamespace(),
217215
"",
218216
//fmt.Sprintf("Created: %s", pod.GetCreationTimestamp().String()),

0 commit comments

Comments
 (0)