Merge pull request #171 from nrb/168-fix

Don't delete 'headless' services
pull/175/head
Steve Kriss 2017-11-01 16:30:32 -07:00 committed by GitHub
commit c49d11f17a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -45,7 +45,10 @@ func (sr *serviceRestorer) Prepare(obj runtime.Unstructured, restore *api.Restor
return nil, nil, err
}
delete(spec, "clusterIP")
// Since clusterIP is an optional key, we can ignore 'not found' errors. Also assuming it was a string already.
if val, _ := collections.GetString(spec, "clusterIP"); val != "None" {
delete(spec, "clusterIP")
}
ports, err := collections.GetSlice(obj.UnstructuredContent(), "spec.ports")
if err != nil {

View File

@ -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").WithSpecField("ports", []interface{}{}).Unstructured,
expectedErr: false,
expectedRes: NewTestUnstructured().WithName("svc-1").WithSpecField("clusterIP", "None").WithSpecField("ports", []interface{}{}).Unstructured,
},
{
name: "nodePort (only) should be deleted from all spec.ports",
obj: NewTestUnstructured().WithName("svc-1").