Introducing Topology Mode Annotation, Deprecating Topology Hints

Annotation

As part of this change, kube-proxy accepts any value for either
annotation that is not "disabled".

Change-Id: Idfc26eb4cc97ff062649dc52ed29823a64fc59a4
This commit is contained in:
Rob Scott
2023-03-13 06:21:32 +00:00
parent 16bc942a6b
commit e23af041f5
10 changed files with 116 additions and 32 deletions

View File

@@ -1843,7 +1843,7 @@ func TestReconcileTopology(t *testing.T) {
service := svc.DeepCopy()
service.Annotations = map[string]string{
corev1.AnnotationTopologyAwareHints: tc.hintsAnnotation,
corev1.DeprecatedAnnotationTopologyAwareHints: tc.hintsAnnotation,
}
r.reconcile(service, tc.pods, tc.existingSlices, time.Now())

View File

@@ -378,12 +378,17 @@ func unchangedSlices(existingSlices, slicesToUpdate, slicesToDelete []*discovery
return unchangedSlices
}
// hintsEnabled returns true if the provided annotations include a
// v1.AnnotationTopologyAwareHints key with a value set to "Auto" or "auto".
// hintsEnabled returns true if the provided annotations include either
// v1.AnnotationTopologyMode or v1.DeprecatedAnnotationTopologyAwareHints key
// with a value set to "Auto" or "auto". When both are set,
// v1.DeprecatedAnnotationTopologyAwareHints has precedence.
func hintsEnabled(annotations map[string]string) bool {
val, ok := annotations[v1.AnnotationTopologyAwareHints]
val, ok := annotations[v1.DeprecatedAnnotationTopologyAwareHints]
if !ok {
return false
val, ok = annotations[v1.AnnotationTopologyMode]
if !ok {
return false
}
}
return val == "Auto" || val == "auto"
}

View File

@@ -1149,24 +1149,72 @@ func Test_hintsEnabled(t *testing.T) {
annotations: map[string]string{"topology-hints": "enabled"},
expectEnabled: false,
}, {
name: "annotation == enabled",
annotations: map[string]string{v1.AnnotationTopologyAwareHints: "enabled"},
name: "hints annotation == enabled",
annotations: map[string]string{v1.DeprecatedAnnotationTopologyAwareHints: "enabled"},
expectEnabled: false,
}, {
name: "annotation == aUto",
annotations: map[string]string{v1.AnnotationTopologyAwareHints: "aUto"},
name: "hints annotation == aUto",
annotations: map[string]string{v1.DeprecatedAnnotationTopologyAwareHints: "aUto"},
expectEnabled: false,
}, {
name: "annotation == auto",
annotations: map[string]string{v1.AnnotationTopologyAwareHints: "auto"},
name: "hints annotation == auto",
annotations: map[string]string{v1.DeprecatedAnnotationTopologyAwareHints: "auto"},
expectEnabled: true,
}, {
name: "annotation == Auto",
annotations: map[string]string{v1.AnnotationTopologyAwareHints: "Auto"},
name: "hints annotation == Auto",
annotations: map[string]string{v1.DeprecatedAnnotationTopologyAwareHints: "Auto"},
expectEnabled: true,
}, {
name: "annotation == disabled",
annotations: map[string]string{v1.AnnotationTopologyAwareHints: "disabled"},
name: "hints annotation == disabled",
annotations: map[string]string{v1.DeprecatedAnnotationTopologyAwareHints: "disabled"},
expectEnabled: false,
}, {
name: "mode annotation == enabled",
annotations: map[string]string{v1.AnnotationTopologyMode: "enabled"},
expectEnabled: false,
}, {
name: "mode annotation == aUto",
annotations: map[string]string{v1.AnnotationTopologyMode: "aUto"},
expectEnabled: false,
}, {
name: "mode annotation == auto",
annotations: map[string]string{v1.AnnotationTopologyMode: "auto"},
expectEnabled: true,
}, {
name: "mode annotation == Auto",
annotations: map[string]string{v1.AnnotationTopologyMode: "Auto"},
expectEnabled: true,
}, {
name: "mode annotation == disabled",
annotations: map[string]string{v1.AnnotationTopologyMode: "disabled"},
expectEnabled: false,
}, {
name: "mode annotation == enabled",
annotations: map[string]string{v1.AnnotationTopologyMode: "enabled"},
expectEnabled: false,
}, {
name: "mode annotation == aUto",
annotations: map[string]string{v1.AnnotationTopologyMode: "aUto"},
expectEnabled: false,
}, {
name: "mode annotation == auto",
annotations: map[string]string{v1.AnnotationTopologyMode: "auto"},
expectEnabled: true,
}, {
name: "mode annotation == Auto",
annotations: map[string]string{v1.AnnotationTopologyMode: "Auto"},
expectEnabled: true,
}, {
name: "mode annotation == disabled",
annotations: map[string]string{v1.AnnotationTopologyMode: "disabled"},
expectEnabled: false,
}, {
name: "mode annotation == disabled, hints annotation == auto",
annotations: map[string]string{v1.AnnotationTopologyMode: "disabled", v1.DeprecatedAnnotationTopologyAwareHints: "auto"},
expectEnabled: true,
}, {
name: "mode annotation == auto, hints annotation == disabled",
annotations: map[string]string{v1.AnnotationTopologyMode: "auto", v1.DeprecatedAnnotationTopologyAwareHints: "disabled"},
expectEnabled: false,
}}
for _, tc := range testCases {