Skip to content

Commit

Permalink
k8s: use core/v1 consts for topology-aware hints annotation/label
Browse files Browse the repository at this point in the history
  • Loading branch information
tklauser authored and pchaigno committed Feb 21, 2023
1 parent 47de737 commit 4bff537
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
4 changes: 1 addition & 3 deletions pkg/k8s/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const (
serviceAffinityNone = ""
serviceAffinityLocal = "local"
serviceAffinityRemote = "remote"

annotationTopologyAwareHints = "service.kubernetes.io/topology-aware-hints"
)

func getAnnotationIncludeExternal(svc *slim_corev1.Service) bool {
Expand Down Expand Up @@ -71,7 +69,7 @@ func getAnnotationServiceAffinity(svc *slim_corev1.Service) string {
}

func getAnnotationTopologyAwareHints(svc *slim_corev1.Service) bool {
if value, ok := svc.ObjectMeta.Annotations[annotationTopologyAwareHints]; ok {
if value, ok := svc.ObjectMeta.Annotations[v1.AnnotationTopologyAwareHints]; ok {
return strings.ToLower(value) == "auto"
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/k8s/service_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const (
DeleteService
)

// Used to implement the topology aware hints.
const LabelTopologyZone = "topology.kubernetes.io/zone"

// String returns the cache action as a string
func (c CacheAction) String() string {
switch c {
Expand Down Expand Up @@ -730,7 +727,7 @@ func (s *ServiceCache) updateSelfNodeLabels(labels map[string]string,
s.mutex.Lock()
defer s.mutex.Unlock()

zone := labels[LabelTopologyZone]
zone := labels[core_v1.LabelTopologyZone]

if s.selfNodeZoneLabel == zone {
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/k8s/service_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ func (s *K8sSuite) TestServiceEndpointFiltering(c *check.C) {
Namespace: "bar",
Labels: map[string]string{"foo": "bar"},
Annotations: map[string]string{
annotationTopologyAwareHints: "auto",
v1.AnnotationTopologyAwareHints: "auto",
},
},
Spec: slim_corev1.ServiceSpec{
Expand Down Expand Up @@ -1107,7 +1107,7 @@ func (s *K8sSuite) TestServiceEndpointFiltering(c *check.C) {
k8sNode := &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node1",
Labels: map[string]string{LabelTopologyZone: "test-zone-2"},
Labels: map[string]string{v1.LabelTopologyZone: "test-zone-2"},
},
}

Expand Down Expand Up @@ -1152,7 +1152,7 @@ func (s *K8sSuite) TestServiceEndpointFiltering(c *check.C) {

// Set the node's zone to test-zone-1 to select the first endpoint
k8sNode.ObjectMeta.Labels = map[string]string{
LabelTopologyZone: "test-zone-1",
v1.LabelTopologyZone: "test-zone-1",
}
svcCache.OnUpdateNode(k8sNode, k8sNode, swg)
c.Assert(testutils.WaitUntil(func() bool {
Expand Down
3 changes: 2 additions & 1 deletion pkg/k8s/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"gopkg.in/check.v1"
corev1 "k8s.io/api/core/v1"

"github.com/cilium/cilium/pkg/checker"
"github.com/cilium/cilium/pkg/cidr"
Expand Down Expand Up @@ -201,7 +202,7 @@ func (s *K8sSuite) TestParseService(c *check.C) {
option.Config.EnableNodePort = oldNodePort
}()
objMeta.Annotations = map[string]string{
annotationTopologyAwareHints: "auto",
corev1.AnnotationTopologyAwareHints: "auto",
}
k8sSvc = &slim_corev1.Service{
ObjectMeta: objMeta,
Expand Down

0 comments on commit 4bff537

Please sign in to comment.