-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for applying changes to the service resource. Roll back 8ae4b02 since service topology feature gate isn't yet enabled, and add TODOs to re-introduce support when the gate is finally enabled.
- Loading branch information
1 parent
169a749
commit a9d8d33
Showing
4 changed files
with
147 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package controller | ||
|
||
import ( | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestDNSServiceChanged(t *testing.T) { | ||
testCases := []struct { | ||
description string | ||
mutate func(*corev1.Service) | ||
expect bool | ||
}{ | ||
{ | ||
description: "if nothing changes", | ||
mutate: func(_ *corev1.Service) {}, | ||
expect: false, | ||
}, | ||
{ | ||
description: "if .uid changes", | ||
mutate: func(service *corev1.Service) { | ||
service.UID = "2" | ||
}, | ||
expect: false, | ||
}, | ||
{ | ||
description: "if .spec.topologyKey changes", | ||
mutate: func(service *corev1.Service) { | ||
service.Spec.TopologyKeys = []string{"foo"} | ||
}, | ||
// TODO: Change to true when the service topology feature gate is enabled. | ||
expect: false, | ||
}, | ||
{ | ||
description: "if .spec.selector changes", | ||
mutate: func(service *corev1.Service) { | ||
service.Spec.Selector = map[string]string{"foo": "bar"} | ||
}, | ||
expect: true, | ||
}, | ||
{ | ||
description: "if .spec.type changes", | ||
mutate: func(service *corev1.Service) { | ||
service.Spec.Type = corev1.ServiceTypeNodePort | ||
}, | ||
expect: true, | ||
}, | ||
{ | ||
description: "if .spec.sessionAffinity changes", | ||
mutate: func(service *corev1.Service) { | ||
service.Spec.SessionAffinity = corev1.ServiceAffinityClientIP | ||
}, | ||
expect: true, | ||
}, | ||
{ | ||
description: "if .spec.publishNotReadyAddresses changes", | ||
mutate: func(service *corev1.Service) { | ||
service.Spec.PublishNotReadyAddresses = true | ||
}, | ||
expect: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
original := corev1.Service{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "dns-original", | ||
Namespace: "openshift-dns", | ||
UID: "1", | ||
}, | ||
Spec: corev1.ServiceSpec{ | ||
Type: corev1.ServiceTypeClusterIP, | ||
SessionAffinity: corev1.ServiceAffinityNone, | ||
}, | ||
} | ||
mutated := original.DeepCopy() | ||
tc.mutate(mutated) | ||
if changed, updated := serviceChanged(&original, mutated); changed != tc.expect { | ||
t.Errorf("%s, expect serviceChanged to be %t, got %t", tc.description, tc.expect, changed) | ||
} else if changed { | ||
if changedAgain, _ := serviceChanged(mutated, updated); changedAgain { | ||
t.Errorf("%s, serviceChanged does not behave as a fixed point function", tc.description) | ||
} | ||
} | ||
} | ||
} |