Skip to content

Commit

Permalink
Don't delete 'headless' services
Browse files Browse the repository at this point in the history
Deleting the clusterIP field when the service should be headless will
cause it to be assigned a new IP on restore; instead it should retain
the headless state after restoration.

Fixes vmware-tanzu#168

Signed-off-by: Nolan Brubaker <[email protected]>
  • Loading branch information
Nolan Brubaker committed Nov 1, 2017
1 parent 9c3d7f9 commit d22907c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/restore/restorers/service_restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package restorers

import (
"fmt"
"k8s.io/apimachinery/pkg/runtime"

api "github.com/heptio/ark/pkg/apis/ark/v1"
Expand Down Expand Up @@ -45,7 +46,9 @@ func (sr *serviceRestorer) Prepare(obj runtime.Unstructured, restore *api.Restor
return nil, nil, err
}

delete(spec, "clusterIP")
if fmt.Sprintf("%v", spec["clusterIP"]) != "None" {
delete(spec, "clusterIP")
}

ports, err := collections.GetSlice(obj.UnstructuredContent(), "spec.ports")
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/restore/restorers/service_restorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func TestServiceRestorerPrepare(t *testing.T) {
expectedErr: false,
expectedRes: NewTestUnstructured().WithName("svc-1").WithSpec("foo").WithSpecField("ports", []interface{}{}).Unstructured,
},
{
name: "headless clusterIP should not be deleted from spec",
obj: NewTestUnstructured().WithName("svc-1").WithSpecField("clusterIP", "None").Unstructured,
expectedErr: false,
expectedRes: NewTestUnstructured().WithName("svc-1").WithSpecField("clusterIP", "None").Unstructured,
},
{
name: "nodePort (only) should be deleted from all spec.ports",
obj: NewTestUnstructured().WithName("svc-1").
Expand Down

0 comments on commit d22907c

Please sign in to comment.