Skip to content

Commit d4c55d0

Browse files
committed
Export endpoints, endpointslice, mirroring controller names
1 parent 610adeb commit d4c55d0

9 files changed

+62
-62
lines changed

pkg/controller/endpoint/endpoints_controller.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ const (
6767
// maxCapacity
6868
truncated = "truncated"
6969

70-
// labelManagedBy is a label for recognizing Endpoints managed by this controller.
71-
labelManagedBy = "endpoints.kubernetes.io/managed-by"
70+
// LabelManagedBy is a label for recognizing Endpoints managed by this controller.
71+
LabelManagedBy = "endpoints.kubernetes.io/managed-by"
7272

73-
// controllerName is the name of this controller
74-
controllerName = "endpoint-controller"
73+
// ControllerName is the name of this controller
74+
ControllerName = "endpoint-controller"
7575
)
7676

7777
// NewEndpointController returns a new *Controller.
7878
func NewEndpointController(ctx context.Context, podInformer coreinformers.PodInformer, serviceInformer coreinformers.ServiceInformer,
7979
endpointsInformer coreinformers.EndpointsInformer, client clientset.Interface, endpointUpdatesBatchPeriod time.Duration) *Controller {
8080
broadcaster := record.NewBroadcaster(record.WithContext(ctx))
81-
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: controllerName})
81+
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: ControllerName})
8282

8383
e := &Controller{
8484
client: client,
@@ -503,7 +503,7 @@ func (e *Controller) syncService(ctx context.Context, key string) error {
503503
} else {
504504
newEndpoints.Labels = utillabels.CloneAndRemoveLabel(newEndpoints.Labels, v1.IsHeadlessService)
505505
}
506-
newEndpoints.Labels[labelManagedBy] = controllerName
506+
newEndpoints.Labels[LabelManagedBy] = ControllerName
507507

508508
logger.V(4).Info("Update endpoints", "service", klog.KObj(service), "readyEndpoints", totalReadyEps, "notreadyEndpoints", totalNotReadyEps)
509509
var updatedEndpoints *v1.Endpoints
@@ -720,16 +720,16 @@ func endpointSubsetsEqualIgnoreResourceVersion(subsets1, subsets2 []v1.EndpointS
720720
// labelsCorrectForEndpoints tests that epLabels is correctly derived from svcLabels
721721
// (ignoring the v1.IsHeadlessService label).
722722
func labelsCorrectForEndpoints(epLabels, svcLabels map[string]string) bool {
723-
if epLabels[labelManagedBy] != controllerName {
723+
if epLabels[LabelManagedBy] != ControllerName {
724724
return false
725725
}
726726

727-
// Every label in epLabels except v1.IsHeadlessService and labelManagedBy should
727+
// Every label in epLabels except v1.IsHeadlessService and LabelManagedBy should
728728
// correspond to a label in svcLabels, and svcLabels should not have any other
729729
// labels that aren't in epLabels.
730730
skipped := 0
731731
for k, v := range epLabels {
732-
if k == v1.IsHeadlessService || k == labelManagedBy {
732+
if k == v1.IsHeadlessService || k == LabelManagedBy {
733733
skipped++
734734
} else if sv, exists := svcLabels[k]; !exists || sv != v {
735735
return false

pkg/controller/endpoint/endpoints_controller_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func TestSyncEndpointsExistingNilSubsets(t *testing.T) {
318318
Namespace: ns,
319319
ResourceVersion: "1",
320320
Labels: map[string]string{
321-
labelManagedBy: controllerName,
321+
LabelManagedBy: ControllerName,
322322
},
323323
},
324324
Subsets: nil,
@@ -350,7 +350,7 @@ func TestSyncEndpointsExistingEmptySubsets(t *testing.T) {
350350
Namespace: ns,
351351
ResourceVersion: "1",
352352
Labels: map[string]string{
353-
labelManagedBy: controllerName,
353+
LabelManagedBy: ControllerName,
354354
},
355355
},
356356
Subsets: []v1.EndpointSubset{},
@@ -383,7 +383,7 @@ func TestSyncEndpointsWithPodResourceVersionUpdateOnly(t *testing.T) {
383383
Namespace: ns,
384384
ResourceVersion: "1",
385385
Labels: map[string]string{
386-
labelManagedBy: controllerName,
386+
LabelManagedBy: ControllerName,
387387
},
388388
},
389389
Subsets: []v1.EndpointSubset{{
@@ -510,7 +510,7 @@ func TestSyncEndpointsProtocolTCP(t *testing.T) {
510510
Namespace: ns,
511511
ResourceVersion: "1",
512512
Labels: map[string]string{
513-
labelManagedBy: controllerName,
513+
LabelManagedBy: ControllerName,
514514
v1.IsHeadlessService: "",
515515
},
516516
},
@@ -534,7 +534,7 @@ func TestSyncEndpointsHeadlessServiceLabel(t *testing.T) {
534534
Namespace: ns,
535535
ResourceVersion: "1",
536536
Labels: map[string]string{
537-
labelManagedBy: controllerName,
537+
LabelManagedBy: ControllerName,
538538
v1.IsHeadlessService: "",
539539
},
540540
},
@@ -663,7 +663,7 @@ func TestSyncEndpointsProtocolUDP(t *testing.T) {
663663
Namespace: ns,
664664
ResourceVersion: "1",
665665
Labels: map[string]string{
666-
labelManagedBy: controllerName,
666+
LabelManagedBy: ControllerName,
667667
v1.IsHeadlessService: "",
668668
},
669669
},
@@ -713,7 +713,7 @@ func TestSyncEndpointsProtocolSCTP(t *testing.T) {
713713
Namespace: ns,
714714
ResourceVersion: "1",
715715
Labels: map[string]string{
716-
labelManagedBy: controllerName,
716+
LabelManagedBy: ControllerName,
717717
v1.IsHeadlessService: "",
718718
},
719719
},
@@ -759,7 +759,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
759759
Namespace: ns,
760760
ResourceVersion: "1",
761761
Labels: map[string]string{
762-
labelManagedBy: controllerName,
762+
LabelManagedBy: ControllerName,
763763
v1.IsHeadlessService: "",
764764
},
765765
},
@@ -806,7 +806,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllNotReady(t *testing.T) {
806806
Namespace: ns,
807807
ResourceVersion: "1",
808808
Labels: map[string]string{
809-
labelManagedBy: controllerName,
809+
LabelManagedBy: ControllerName,
810810
v1.IsHeadlessService: "",
811811
},
812812
},
@@ -853,7 +853,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllMixed(t *testing.T) {
853853
Namespace: ns,
854854
ResourceVersion: "1",
855855
Labels: map[string]string{
856-
labelManagedBy: controllerName,
856+
LabelManagedBy: ControllerName,
857857
v1.IsHeadlessService: "",
858858
},
859859
},
@@ -878,7 +878,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
878878
Namespace: ns,
879879
ResourceVersion: "1",
880880
Labels: map[string]string{
881-
labelManagedBy: controllerName,
881+
LabelManagedBy: ControllerName,
882882
},
883883
},
884884
Subsets: []v1.EndpointSubset{{
@@ -906,7 +906,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
906906
Namespace: ns,
907907
ResourceVersion: "1",
908908
Labels: map[string]string{
909-
labelManagedBy: controllerName,
909+
LabelManagedBy: ControllerName,
910910
v1.IsHeadlessService: "",
911911
},
912912
},
@@ -930,7 +930,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
930930
Name: "foo",
931931
Namespace: ns,
932932
Labels: map[string]string{
933-
labelManagedBy: controllerName,
933+
LabelManagedBy: ControllerName,
934934
},
935935
},
936936
Subsets: []v1.EndpointSubset{{
@@ -995,7 +995,7 @@ func TestSyncEndpointsItems(t *testing.T) {
995995
ResourceVersion: "",
996996
Name: "foo",
997997
Labels: map[string]string{
998-
labelManagedBy: controllerName,
998+
LabelManagedBy: ControllerName,
999999
v1.IsHeadlessService: "",
10001000
},
10011001
},
@@ -1046,7 +1046,7 @@ func TestSyncEndpointsItemsWithLabels(t *testing.T) {
10461046
}}
10471047

10481048
serviceLabels[v1.IsHeadlessService] = ""
1049-
serviceLabels[labelManagedBy] = controllerName
1049+
serviceLabels[LabelManagedBy] = ControllerName
10501050
data := runtime.EncodeOrDie(clientscheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &v1.Endpoints{
10511051
ObjectMeta: metav1.ObjectMeta{
10521052
ResourceVersion: "",
@@ -1099,7 +1099,7 @@ func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) {
10991099
}
11001100

11011101
serviceLabels[v1.IsHeadlessService] = ""
1102-
serviceLabels[labelManagedBy] = controllerName
1102+
serviceLabels[LabelManagedBy] = ControllerName
11031103
data := runtime.EncodeOrDie(clientscheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &v1.Endpoints{
11041104
ObjectMeta: metav1.ObjectMeta{
11051105
Name: "foo",
@@ -1209,7 +1209,7 @@ func TestSyncEndpointsHeadlessService(t *testing.T) {
12091209
Namespace: ns,
12101210
ResourceVersion: "1",
12111211
Labels: map[string]string{
1212-
labelManagedBy: controllerName,
1212+
LabelManagedBy: ControllerName,
12131213
"a": "b",
12141214
v1.IsHeadlessService: "",
12151215
},
@@ -1239,7 +1239,7 @@ func TestSyncEndpointsItemsExcludeNotReadyPodsWithRestartPolicyNeverAndPhaseFail
12391239
Namespace: ns,
12401240
ResourceVersion: "1",
12411241
Labels: map[string]string{
1242-
labelManagedBy: controllerName,
1242+
LabelManagedBy: ControllerName,
12431243
"foo": "bar",
12441244
},
12451245
},
@@ -1264,7 +1264,7 @@ func TestSyncEndpointsItemsExcludeNotReadyPodsWithRestartPolicyNeverAndPhaseFail
12641264
Namespace: ns,
12651265
ResourceVersion: "1",
12661266
Labels: map[string]string{
1267-
labelManagedBy: controllerName,
1267+
LabelManagedBy: ControllerName,
12681268
v1.IsHeadlessService: "",
12691269
},
12701270
},
@@ -1310,7 +1310,7 @@ func TestSyncEndpointsItemsExcludeNotReadyPodsWithRestartPolicyNeverAndPhaseSucc
13101310
Namespace: ns,
13111311
ResourceVersion: "1",
13121312
Labels: map[string]string{
1313-
labelManagedBy: controllerName,
1313+
LabelManagedBy: ControllerName,
13141314
v1.IsHeadlessService: "",
13151315
},
13161316
},
@@ -1357,7 +1357,7 @@ func TestSyncEndpointsItemsExcludeNotReadyPodsWithRestartPolicyOnFailureAndPhase
13571357
Namespace: ns,
13581358
ResourceVersion: "1",
13591359
Labels: map[string]string{
1360-
labelManagedBy: controllerName,
1360+
LabelManagedBy: ControllerName,
13611361
v1.IsHeadlessService: "",
13621362
},
13631363
},
@@ -1392,7 +1392,7 @@ func TestSyncEndpointsHeadlessWithoutPort(t *testing.T) {
13921392
ObjectMeta: metav1.ObjectMeta{
13931393
Name: "foo",
13941394
Labels: map[string]string{
1395-
labelManagedBy: controllerName,
1395+
LabelManagedBy: ControllerName,
13961396
v1.IsHeadlessService: "",
13971397
},
13981398
},
@@ -1612,7 +1612,7 @@ func TestLastTriggerChangeTimeAnnotation(t *testing.T) {
16121612
v1.EndpointsLastChangeTriggerTime: triggerTimeString,
16131613
},
16141614
Labels: map[string]string{
1615-
labelManagedBy: controllerName,
1615+
LabelManagedBy: ControllerName,
16161616
v1.IsHeadlessService: "",
16171617
},
16181618
},
@@ -1669,7 +1669,7 @@ func TestLastTriggerChangeTimeAnnotation_AnnotationOverridden(t *testing.T) {
16691669
v1.EndpointsLastChangeTriggerTime: triggerTimeString,
16701670
},
16711671
Labels: map[string]string{
1672-
labelManagedBy: controllerName,
1672+
LabelManagedBy: ControllerName,
16731673
v1.IsHeadlessService: "",
16741674
},
16751675
},
@@ -1724,7 +1724,7 @@ func TestLastTriggerChangeTimeAnnotation_AnnotationCleared(t *testing.T) {
17241724
Namespace: ns,
17251725
ResourceVersion: "1",
17261726
Labels: map[string]string{
1727-
labelManagedBy: controllerName,
1727+
LabelManagedBy: ControllerName,
17281728
v1.IsHeadlessService: "",
17291729
}, // Annotation not set anymore.
17301730
},

pkg/controller/endpointslice/endpointslice_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ const (
7272
// maxSyncBackOff is the max backoff period for syncService calls.
7373
maxSyncBackOff = 1000 * time.Second
7474

75-
// controllerName is a unique value used with LabelManagedBy to indicated
75+
// ControllerName is a unique value used with LabelManagedBy to indicated
7676
// the component managing an EndpointSlice.
77-
controllerName = "endpointslice-controller.k8s.io"
77+
ControllerName = "endpointslice-controller.k8s.io"
7878

7979
// topologyQueueItemKey is the key for all items in the topologyQueue.
8080
topologyQueueItemKey = "topologyQueueItemKey"
@@ -185,7 +185,7 @@ func NewController(ctx context.Context, podInformer coreinformers.PodInformer,
185185
c.endpointSliceTracker,
186186
c.topologyCache,
187187
c.eventRecorder,
188-
controllerName,
188+
ControllerName,
189189
endpointslicerec.WithTrafficDistributionEnabled(utilfeature.DefaultFeatureGate.Enabled(features.ServiceTrafficDistribution)),
190190
)
191191

pkg/controller/endpointslice/endpointslice_controller_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func TestSyncServiceEndpointSlicePendingDeletion(t *testing.T) {
397397
OwnerReferences: []metav1.OwnerReference{*ownerRef},
398398
Labels: map[string]string{
399399
discovery.LabelServiceName: serviceName,
400-
discovery.LabelManagedBy: controllerName,
400+
discovery.LabelManagedBy: ControllerName,
401401
},
402402
DeletionTimestamp: &deletedTs,
403403
},
@@ -442,7 +442,7 @@ func TestSyncServiceEndpointSliceLabelSelection(t *testing.T) {
442442
OwnerReferences: []metav1.OwnerReference{*ownerRef},
443443
Labels: map[string]string{
444444
discovery.LabelServiceName: serviceName,
445-
discovery.LabelManagedBy: controllerName,
445+
discovery.LabelManagedBy: ControllerName,
446446
},
447447
},
448448
AddressType: discovery.AddressTypeIPv4,
@@ -453,7 +453,7 @@ func TestSyncServiceEndpointSliceLabelSelection(t *testing.T) {
453453
OwnerReferences: []metav1.OwnerReference{*ownerRef},
454454
Labels: map[string]string{
455455
discovery.LabelServiceName: serviceName,
456-
discovery.LabelManagedBy: controllerName,
456+
discovery.LabelManagedBy: ControllerName,
457457
},
458458
},
459459
AddressType: discovery.AddressTypeIPv4,
@@ -472,7 +472,7 @@ func TestSyncServiceEndpointSliceLabelSelection(t *testing.T) {
472472
Namespace: ns,
473473
Labels: map[string]string{
474474
discovery.LabelServiceName: "something-else",
475-
discovery.LabelManagedBy: controllerName,
475+
discovery.LabelManagedBy: ControllerName,
476476
},
477477
},
478478
AddressType: discovery.AddressTypeIPv4,
@@ -529,7 +529,7 @@ func TestOnEndpointSliceUpdate(t *testing.T) {
529529
Namespace: ns,
530530
Labels: map[string]string{
531531
discovery.LabelServiceName: serviceName,
532-
discovery.LabelManagedBy: controllerName,
532+
discovery.LabelManagedBy: ControllerName,
533533
},
534534
},
535535
AddressType: discovery.AddressTypeIPv4,
@@ -1750,7 +1750,7 @@ func TestSyncServiceStaleInformer(t *testing.T) {
17501750
Generation: testcase.informerGenerationNumber,
17511751
Labels: map[string]string{
17521752
discovery.LabelServiceName: serviceName,
1753-
discovery.LabelManagedBy: controllerName,
1753+
discovery.LabelManagedBy: ControllerName,
17541754
},
17551755
},
17561756
AddressType: discovery.AddressTypeIPv4,
@@ -1977,7 +1977,7 @@ func TestUpdateNode(t *testing.T) {
19771977
Namespace: "ns",
19781978
Labels: map[string]string{
19791979
discovery.LabelServiceName: "svc",
1980-
discovery.LabelManagedBy: controllerName,
1980+
discovery.LabelManagedBy: ControllerName,
19811981
},
19821982
},
19831983
Endpoints: []discovery.Endpoint{

pkg/controller/endpointslicemirroring/endpointslicemirroring_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ const (
6262
// maxSyncBackOff is the max backoff period for syncEndpoints calls.
6363
maxSyncBackOff = 100 * time.Second
6464

65-
// controllerName is a unique value used with LabelManagedBy to indicated
65+
// ControllerName is a unique value used with LabelManagedBy to indicated
6666
// the component managing an EndpointSlice.
67-
controllerName = "endpointslicemirroring-controller.k8s.io"
67+
ControllerName = "endpointslicemirroring-controller.k8s.io"
6868
)
6969

7070
// NewController creates and initializes a new Controller
@@ -537,7 +537,7 @@ func (c *Controller) deleteMirroredSlices(namespace, name string) error {
537537
func endpointSlicesMirroredForService(endpointSliceLister discoverylisters.EndpointSliceLister, namespace, name string) ([]*discovery.EndpointSlice, error) {
538538
esLabelSelector := labels.Set(map[string]string{
539539
discovery.LabelServiceName: name,
540-
discovery.LabelManagedBy: controllerName,
540+
discovery.LabelManagedBy: ControllerName,
541541
}).AsSelectorPreValidated()
542542
return endpointSliceLister.EndpointSlices(namespace).List(esLabelSelector)
543543
}

0 commit comments

Comments
 (0)