Skip to content

Ignore attempt to empty route spec.host field #9425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/route/registry/route/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func (s routeStrategy) PrepareForUpdate(obj, old runtime.Object) {
// Limit to kind/name
// TODO: convert to LocalObjectReference
route.Spec.To = kapi.ObjectReference{Kind: route.Spec.To.Kind, Name: route.Spec.To.Name}
// Ignore attempts to clear the spec Host
// Prevents "immutable field" errors when applying the same route definition used to create
if len(route.Spec.Host) == 0 {
route.Spec.Host = oldRoute.Spec.Host
}
}

// allocateHost allocates a host name ONLY if the host name on the route is empty and an allocator
Expand Down
48 changes: 48 additions & 0 deletions pkg/route/registry/route/strategy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package route

import (
"testing"

"github.com/openshift/origin/pkg/route/api"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/types"
)

type testAllocator struct {
}

func (t testAllocator) AllocateRouterShard(*api.Route) (*api.RouterShard, error) {
return &api.RouterShard{}, nil
}
func (t testAllocator) GenerateHostname(*api.Route, *api.RouterShard) string {
return "mygeneratedhost.com"
}

func TestEmptyHostDefaulting(t *testing.T) {
strategy := NewStrategy(testAllocator{})

hostlessCreatedRoute := &api.Route{}
strategy.PrepareForCreate(hostlessCreatedRoute)
if hostlessCreatedRoute.Spec.Host != "mygeneratedhost.com" {
t.Fatalf("Expected host to be allocated, got %s", hostlessCreatedRoute.Spec.Host)
}

persistedRoute := &api.Route{
ObjectMeta: kapi.ObjectMeta{
Namespace: "foo",
Name: "myroute",
UID: types.UID("abc"),
ResourceVersion: "1",
},
Spec: api.RouteSpec{
Host: "myhost.com",
},
}
obj, _ := kapi.Scheme.DeepCopy(persistedRoute)
hostlessUpdatedRoute := obj.(*api.Route)
hostlessUpdatedRoute.Spec.Host = ""
strategy.PrepareForUpdate(hostlessUpdatedRoute, persistedRoute)
if hostlessUpdatedRoute.Spec.Host != "myhost.com" {
t.Fatalf("expected empty spec.host to default to existing spec.host, got %s", hostlessUpdatedRoute.Spec.Host)
}
}