Skip to content

Commit

Permalink
Merge pull request #869 from shubheksha/fix/786-fix-error-ExternalNam…
Browse files Browse the repository at this point in the history
…e-service-restore

Fix error when restoring ExternalName services
  • Loading branch information
nrb authored Sep 25, 2018
2 parents a6fa7af + e3222a9 commit ed2bca8
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions pkg/restore/service_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,10 @@ func (a *serviceAction) Execute(obj runtime.Unstructured, restore *api.Restore)
delete(spec, "clusterIP")
}

preservedPorts, err := getPreservedPorts(obj)
if err != nil {
return nil, nil, err
}

ports, err := collections.GetSlice(obj.UnstructuredContent(), "spec.ports")
err = deleteNodePorts(obj, &spec)
if err != nil {
return nil, nil, err
}

for _, port := range ports {
p := port.(map[string]interface{})
var name string
if nameVal, ok := p["name"]; ok {
name = nameVal.(string)
}
if preservedPorts[name] {
continue
}
delete(p, "nodePort")
}

return obj, nil, nil
}

Expand All @@ -101,3 +83,29 @@ func getPreservedPorts(obj runtime.Unstructured) (map[string]bool, error) {
}
return preservedPorts, nil
}

func deleteNodePorts(obj runtime.Unstructured, spec *map[string]interface{}) error {
preservedPorts, err := getPreservedPorts(obj)
if err != nil {
return err
}

ports, err := collections.GetSlice(obj.UnstructuredContent(), "spec.ports")
serviceType, _ := collections.GetString(*spec, "type")
if err != nil && serviceType != "ExternalName" {
return err
}

for _, port := range ports {
p := port.(map[string]interface{})
var name string
if nameVal, ok := p["name"]; ok {
name = nameVal.(string)
}
if preservedPorts[name] {
continue
}
delete(p, "nodePort")
}
return nil
}

0 comments on commit ed2bca8

Please sign in to comment.