mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +00:00
Export endpoints, endpointslice, mirroring controller names
This commit is contained in:
parent
610adebdb7
commit
d4c55d06cf
@ -67,18 +67,18 @@ const (
|
|||||||
// maxCapacity
|
// maxCapacity
|
||||||
truncated = "truncated"
|
truncated = "truncated"
|
||||||
|
|
||||||
// labelManagedBy is a label for recognizing Endpoints managed by this controller.
|
// LabelManagedBy is a label for recognizing Endpoints managed by this controller.
|
||||||
labelManagedBy = "endpoints.kubernetes.io/managed-by"
|
LabelManagedBy = "endpoints.kubernetes.io/managed-by"
|
||||||
|
|
||||||
// controllerName is the name of this controller
|
// ControllerName is the name of this controller
|
||||||
controllerName = "endpoint-controller"
|
ControllerName = "endpoint-controller"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewEndpointController returns a new *Controller.
|
// NewEndpointController returns a new *Controller.
|
||||||
func NewEndpointController(ctx context.Context, podInformer coreinformers.PodInformer, serviceInformer coreinformers.ServiceInformer,
|
func NewEndpointController(ctx context.Context, podInformer coreinformers.PodInformer, serviceInformer coreinformers.ServiceInformer,
|
||||||
endpointsInformer coreinformers.EndpointsInformer, client clientset.Interface, endpointUpdatesBatchPeriod time.Duration) *Controller {
|
endpointsInformer coreinformers.EndpointsInformer, client clientset.Interface, endpointUpdatesBatchPeriod time.Duration) *Controller {
|
||||||
broadcaster := record.NewBroadcaster(record.WithContext(ctx))
|
broadcaster := record.NewBroadcaster(record.WithContext(ctx))
|
||||||
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: controllerName})
|
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: ControllerName})
|
||||||
|
|
||||||
e := &Controller{
|
e := &Controller{
|
||||||
client: client,
|
client: client,
|
||||||
@ -503,7 +503,7 @@ func (e *Controller) syncService(ctx context.Context, key string) error {
|
|||||||
} else {
|
} else {
|
||||||
newEndpoints.Labels = utillabels.CloneAndRemoveLabel(newEndpoints.Labels, v1.IsHeadlessService)
|
newEndpoints.Labels = utillabels.CloneAndRemoveLabel(newEndpoints.Labels, v1.IsHeadlessService)
|
||||||
}
|
}
|
||||||
newEndpoints.Labels[labelManagedBy] = controllerName
|
newEndpoints.Labels[LabelManagedBy] = ControllerName
|
||||||
|
|
||||||
logger.V(4).Info("Update endpoints", "service", klog.KObj(service), "readyEndpoints", totalReadyEps, "notreadyEndpoints", totalNotReadyEps)
|
logger.V(4).Info("Update endpoints", "service", klog.KObj(service), "readyEndpoints", totalReadyEps, "notreadyEndpoints", totalNotReadyEps)
|
||||||
var updatedEndpoints *v1.Endpoints
|
var updatedEndpoints *v1.Endpoints
|
||||||
@ -720,16 +720,16 @@ func endpointSubsetsEqualIgnoreResourceVersion(subsets1, subsets2 []v1.EndpointS
|
|||||||
// labelsCorrectForEndpoints tests that epLabels is correctly derived from svcLabels
|
// labelsCorrectForEndpoints tests that epLabels is correctly derived from svcLabels
|
||||||
// (ignoring the v1.IsHeadlessService label).
|
// (ignoring the v1.IsHeadlessService label).
|
||||||
func labelsCorrectForEndpoints(epLabels, svcLabels map[string]string) bool {
|
func labelsCorrectForEndpoints(epLabels, svcLabels map[string]string) bool {
|
||||||
if epLabels[labelManagedBy] != controllerName {
|
if epLabels[LabelManagedBy] != ControllerName {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every label in epLabels except v1.IsHeadlessService and labelManagedBy should
|
// Every label in epLabels except v1.IsHeadlessService and LabelManagedBy should
|
||||||
// correspond to a label in svcLabels, and svcLabels should not have any other
|
// correspond to a label in svcLabels, and svcLabels should not have any other
|
||||||
// labels that aren't in epLabels.
|
// labels that aren't in epLabels.
|
||||||
skipped := 0
|
skipped := 0
|
||||||
for k, v := range epLabels {
|
for k, v := range epLabels {
|
||||||
if k == v1.IsHeadlessService || k == labelManagedBy {
|
if k == v1.IsHeadlessService || k == LabelManagedBy {
|
||||||
skipped++
|
skipped++
|
||||||
} else if sv, exists := svcLabels[k]; !exists || sv != v {
|
} else if sv, exists := svcLabels[k]; !exists || sv != v {
|
||||||
return false
|
return false
|
||||||
|
@ -318,7 +318,7 @@ func TestSyncEndpointsExistingNilSubsets(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Subsets: nil,
|
Subsets: nil,
|
||||||
@ -350,7 +350,7 @@ func TestSyncEndpointsExistingEmptySubsets(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Subsets: []v1.EndpointSubset{},
|
Subsets: []v1.EndpointSubset{},
|
||||||
@ -383,7 +383,7 @@ func TestSyncEndpointsWithPodResourceVersionUpdateOnly(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Subsets: []v1.EndpointSubset{{
|
Subsets: []v1.EndpointSubset{{
|
||||||
@ -510,7 +510,7 @@ func TestSyncEndpointsProtocolTCP(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -534,7 +534,7 @@ func TestSyncEndpointsHeadlessServiceLabel(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -663,7 +663,7 @@ func TestSyncEndpointsProtocolUDP(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -713,7 +713,7 @@ func TestSyncEndpointsProtocolSCTP(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -759,7 +759,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAll(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -806,7 +806,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllNotReady(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -853,7 +853,7 @@ func TestSyncEndpointsItemsEmptySelectorSelectsAllMixed(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -878,7 +878,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Subsets: []v1.EndpointSubset{{
|
Subsets: []v1.EndpointSubset{{
|
||||||
@ -906,7 +906,7 @@ func TestSyncEndpointsItemsPreexisting(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -930,7 +930,7 @@ func TestSyncEndpointsItemsPreexistingIdentical(t *testing.T) {
|
|||||||
Name: "foo",
|
Name: "foo",
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Subsets: []v1.EndpointSubset{{
|
Subsets: []v1.EndpointSubset{{
|
||||||
@ -995,7 +995,7 @@ func TestSyncEndpointsItems(t *testing.T) {
|
|||||||
ResourceVersion: "",
|
ResourceVersion: "",
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1046,7 +1046,7 @@ func TestSyncEndpointsItemsWithLabels(t *testing.T) {
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
serviceLabels[v1.IsHeadlessService] = ""
|
serviceLabels[v1.IsHeadlessService] = ""
|
||||||
serviceLabels[labelManagedBy] = controllerName
|
serviceLabels[LabelManagedBy] = ControllerName
|
||||||
data := runtime.EncodeOrDie(clientscheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &v1.Endpoints{
|
data := runtime.EncodeOrDie(clientscheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &v1.Endpoints{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
ResourceVersion: "",
|
ResourceVersion: "",
|
||||||
@ -1099,7 +1099,7 @@ func TestSyncEndpointsItemsPreexistingLabelsChange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serviceLabels[v1.IsHeadlessService] = ""
|
serviceLabels[v1.IsHeadlessService] = ""
|
||||||
serviceLabels[labelManagedBy] = controllerName
|
serviceLabels[LabelManagedBy] = ControllerName
|
||||||
data := runtime.EncodeOrDie(clientscheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &v1.Endpoints{
|
data := runtime.EncodeOrDie(clientscheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &v1.Endpoints{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
@ -1209,7 +1209,7 @@ func TestSyncEndpointsHeadlessService(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
"a": "b",
|
"a": "b",
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
@ -1239,7 +1239,7 @@ func TestSyncEndpointsItemsExcludeNotReadyPodsWithRestartPolicyNeverAndPhaseFail
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1264,7 +1264,7 @@ func TestSyncEndpointsItemsExcludeNotReadyPodsWithRestartPolicyNeverAndPhaseFail
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1310,7 +1310,7 @@ func TestSyncEndpointsItemsExcludeNotReadyPodsWithRestartPolicyNeverAndPhaseSucc
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1357,7 +1357,7 @@ func TestSyncEndpointsItemsExcludeNotReadyPodsWithRestartPolicyOnFailureAndPhase
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1392,7 +1392,7 @@ func TestSyncEndpointsHeadlessWithoutPort(t *testing.T) {
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1612,7 +1612,7 @@ func TestLastTriggerChangeTimeAnnotation(t *testing.T) {
|
|||||||
v1.EndpointsLastChangeTriggerTime: triggerTimeString,
|
v1.EndpointsLastChangeTriggerTime: triggerTimeString,
|
||||||
},
|
},
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1669,7 +1669,7 @@ func TestLastTriggerChangeTimeAnnotation_AnnotationOverridden(t *testing.T) {
|
|||||||
v1.EndpointsLastChangeTriggerTime: triggerTimeString,
|
v1.EndpointsLastChangeTriggerTime: triggerTimeString,
|
||||||
},
|
},
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1724,7 +1724,7 @@ func TestLastTriggerChangeTimeAnnotation_AnnotationCleared(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
labelManagedBy: controllerName,
|
LabelManagedBy: ControllerName,
|
||||||
v1.IsHeadlessService: "",
|
v1.IsHeadlessService: "",
|
||||||
}, // Annotation not set anymore.
|
}, // Annotation not set anymore.
|
||||||
},
|
},
|
||||||
|
@ -72,9 +72,9 @@ const (
|
|||||||
// maxSyncBackOff is the max backoff period for syncService calls.
|
// maxSyncBackOff is the max backoff period for syncService calls.
|
||||||
maxSyncBackOff = 1000 * time.Second
|
maxSyncBackOff = 1000 * time.Second
|
||||||
|
|
||||||
// controllerName is a unique value used with LabelManagedBy to indicated
|
// ControllerName is a unique value used with LabelManagedBy to indicated
|
||||||
// the component managing an EndpointSlice.
|
// the component managing an EndpointSlice.
|
||||||
controllerName = "endpointslice-controller.k8s.io"
|
ControllerName = "endpointslice-controller.k8s.io"
|
||||||
|
|
||||||
// topologyQueueItemKey is the key for all items in the topologyQueue.
|
// topologyQueueItemKey is the key for all items in the topologyQueue.
|
||||||
topologyQueueItemKey = "topologyQueueItemKey"
|
topologyQueueItemKey = "topologyQueueItemKey"
|
||||||
@ -185,7 +185,7 @@ func NewController(ctx context.Context, podInformer coreinformers.PodInformer,
|
|||||||
c.endpointSliceTracker,
|
c.endpointSliceTracker,
|
||||||
c.topologyCache,
|
c.topologyCache,
|
||||||
c.eventRecorder,
|
c.eventRecorder,
|
||||||
controllerName,
|
ControllerName,
|
||||||
endpointslicerec.WithTrafficDistributionEnabled(utilfeature.DefaultFeatureGate.Enabled(features.ServiceTrafficDistribution)),
|
endpointslicerec.WithTrafficDistributionEnabled(utilfeature.DefaultFeatureGate.Enabled(features.ServiceTrafficDistribution)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ func TestSyncServiceEndpointSlicePendingDeletion(t *testing.T) {
|
|||||||
OwnerReferences: []metav1.OwnerReference{*ownerRef},
|
OwnerReferences: []metav1.OwnerReference{*ownerRef},
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: serviceName,
|
discovery.LabelServiceName: serviceName,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
DeletionTimestamp: &deletedTs,
|
DeletionTimestamp: &deletedTs,
|
||||||
},
|
},
|
||||||
@ -442,7 +442,7 @@ func TestSyncServiceEndpointSliceLabelSelection(t *testing.T) {
|
|||||||
OwnerReferences: []metav1.OwnerReference{*ownerRef},
|
OwnerReferences: []metav1.OwnerReference{*ownerRef},
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: serviceName,
|
discovery.LabelServiceName: serviceName,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
AddressType: discovery.AddressTypeIPv4,
|
AddressType: discovery.AddressTypeIPv4,
|
||||||
@ -453,7 +453,7 @@ func TestSyncServiceEndpointSliceLabelSelection(t *testing.T) {
|
|||||||
OwnerReferences: []metav1.OwnerReference{*ownerRef},
|
OwnerReferences: []metav1.OwnerReference{*ownerRef},
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: serviceName,
|
discovery.LabelServiceName: serviceName,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
AddressType: discovery.AddressTypeIPv4,
|
AddressType: discovery.AddressTypeIPv4,
|
||||||
@ -472,7 +472,7 @@ func TestSyncServiceEndpointSliceLabelSelection(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: "something-else",
|
discovery.LabelServiceName: "something-else",
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
AddressType: discovery.AddressTypeIPv4,
|
AddressType: discovery.AddressTypeIPv4,
|
||||||
@ -529,7 +529,7 @@ func TestOnEndpointSliceUpdate(t *testing.T) {
|
|||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: serviceName,
|
discovery.LabelServiceName: serviceName,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
AddressType: discovery.AddressTypeIPv4,
|
AddressType: discovery.AddressTypeIPv4,
|
||||||
@ -1750,7 +1750,7 @@ func TestSyncServiceStaleInformer(t *testing.T) {
|
|||||||
Generation: testcase.informerGenerationNumber,
|
Generation: testcase.informerGenerationNumber,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: serviceName,
|
discovery.LabelServiceName: serviceName,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
AddressType: discovery.AddressTypeIPv4,
|
AddressType: discovery.AddressTypeIPv4,
|
||||||
@ -1977,7 +1977,7 @@ func TestUpdateNode(t *testing.T) {
|
|||||||
Namespace: "ns",
|
Namespace: "ns",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: "svc",
|
discovery.LabelServiceName: "svc",
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Endpoints: []discovery.Endpoint{
|
Endpoints: []discovery.Endpoint{
|
||||||
|
@ -62,9 +62,9 @@ const (
|
|||||||
// maxSyncBackOff is the max backoff period for syncEndpoints calls.
|
// maxSyncBackOff is the max backoff period for syncEndpoints calls.
|
||||||
maxSyncBackOff = 100 * time.Second
|
maxSyncBackOff = 100 * time.Second
|
||||||
|
|
||||||
// controllerName is a unique value used with LabelManagedBy to indicated
|
// ControllerName is a unique value used with LabelManagedBy to indicated
|
||||||
// the component managing an EndpointSlice.
|
// the component managing an EndpointSlice.
|
||||||
controllerName = "endpointslicemirroring-controller.k8s.io"
|
ControllerName = "endpointslicemirroring-controller.k8s.io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewController creates and initializes a new Controller
|
// NewController creates and initializes a new Controller
|
||||||
@ -537,7 +537,7 @@ func (c *Controller) deleteMirroredSlices(namespace, name string) error {
|
|||||||
func endpointSlicesMirroredForService(endpointSliceLister discoverylisters.EndpointSliceLister, namespace, name string) ([]*discovery.EndpointSlice, error) {
|
func endpointSlicesMirroredForService(endpointSliceLister discoverylisters.EndpointSliceLister, namespace, name string) ([]*discovery.EndpointSlice, error) {
|
||||||
esLabelSelector := labels.Set(map[string]string{
|
esLabelSelector := labels.Set(map[string]string{
|
||||||
discovery.LabelServiceName: name,
|
discovery.LabelServiceName: name,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
}).AsSelectorPreValidated()
|
}).AsSelectorPreValidated()
|
||||||
return endpointSliceLister.EndpointSlices(namespace).List(esLabelSelector)
|
return endpointSliceLister.EndpointSlices(namespace).List(esLabelSelector)
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ func TestSyncEndpoints(t *testing.T) {
|
|||||||
Name: endpointsName + "-1",
|
Name: endpointsName + "-1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: endpointsName,
|
discovery.LabelServiceName: endpointsName,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
@ -358,7 +358,7 @@ func TestEndpointSlicesMirroredForService(t *testing.T) {
|
|||||||
Namespace: "ns1",
|
Namespace: "ns1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: "svc1",
|
discovery.LabelServiceName: "svc1",
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -373,7 +373,7 @@ func TestEndpointSlicesMirroredForService(t *testing.T) {
|
|||||||
Namespace: "ns2",
|
Namespace: "ns2",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: "svc1",
|
discovery.LabelServiceName: "svc1",
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -388,7 +388,7 @@ func TestEndpointSlicesMirroredForService(t *testing.T) {
|
|||||||
Namespace: "ns1",
|
Namespace: "ns1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: "svc2",
|
discovery.LabelServiceName: "svc2",
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -403,7 +403,7 @@ func TestEndpointSlicesMirroredForService(t *testing.T) {
|
|||||||
Namespace: "ns1",
|
Namespace: "ns1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: "svc1",
|
discovery.LabelServiceName: "svc1",
|
||||||
discovery.LabelManagedBy: controllerName + "foo",
|
discovery.LabelManagedBy: ControllerName + "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -431,7 +431,7 @@ func TestEndpointSlicesMirroredForService(t *testing.T) {
|
|||||||
Name: "example-1",
|
Name: "example-1",
|
||||||
Namespace: "ns1",
|
Namespace: "ns1",
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1078,7 +1078,7 @@ func TestReconcile(t *testing.T) {
|
|||||||
for _, epSlice := range tc.existingEndpointSlices {
|
for _, epSlice := range tc.existingEndpointSlices {
|
||||||
epSlice.Labels = map[string]string{
|
epSlice.Labels = map[string]string{
|
||||||
discovery.LabelServiceName: endpoints.Name,
|
discovery.LabelServiceName: endpoints.Name,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
}
|
}
|
||||||
_, err := client.DiscoveryV1().EndpointSlices(namespace).Create(context.TODO(), epSlice, metav1.CreateOptions{})
|
_, err := client.DiscoveryV1().EndpointSlices(namespace).Create(context.TODO(), epSlice, metav1.CreateOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1305,7 +1305,7 @@ func expectMatchingAddresses(t *testing.T, epSubset corev1.EndpointSubset, esEnd
|
|||||||
func fetchEndpointSlices(t *testing.T, client *fake.Clientset, namespace string) []discovery.EndpointSlice {
|
func fetchEndpointSlices(t *testing.T, client *fake.Clientset, namespace string) []discovery.EndpointSlice {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
fetchedSlices, err := client.DiscoveryV1().EndpointSlices(namespace).List(context.TODO(), metav1.ListOptions{
|
fetchedSlices, err := client.DiscoveryV1().EndpointSlices(namespace).List(context.TODO(), metav1.ListOptions{
|
||||||
LabelSelector: discovery.LabelManagedBy + "=" + controllerName,
|
LabelSelector: discovery.LabelManagedBy + "=" + ControllerName,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Expected no error fetching Endpoint Slices, got: %v", err)
|
t.Fatalf("Expected no error fetching Endpoint Slices, got: %v", err)
|
||||||
|
@ -73,7 +73,7 @@ func newEndpointSlice(endpoints *corev1.Endpoints, ports []discovery.EndpointPor
|
|||||||
|
|
||||||
// overwrite specific labels
|
// overwrite specific labels
|
||||||
epSlice.Labels[discovery.LabelServiceName] = endpoints.Name
|
epSlice.Labels[discovery.LabelServiceName] = endpoints.Name
|
||||||
epSlice.Labels[discovery.LabelManagedBy] = controllerName
|
epSlice.Labels[discovery.LabelManagedBy] = ControllerName
|
||||||
|
|
||||||
// clone all annotations but EndpointsLastChangeTriggerTime and LastAppliedConfigAnnotation
|
// clone all annotations but EndpointsLastChangeTriggerTime and LastAppliedConfigAnnotation
|
||||||
for annotation, val := range endpoints.Annotations {
|
for annotation, val := range endpoints.Annotations {
|
||||||
@ -267,5 +267,5 @@ func managedByChanged(endpointSlice1, endpointSlice2 *discovery.EndpointSlice) b
|
|||||||
// EndpointSlices is the EndpointSlice controller.
|
// EndpointSlices is the EndpointSlice controller.
|
||||||
func managedByController(endpointSlice *discovery.EndpointSlice) bool {
|
func managedByController(endpointSlice *discovery.EndpointSlice) bool {
|
||||||
managedBy, _ := endpointSlice.Labels[discovery.LabelManagedBy]
|
managedBy, _ := endpointSlice.Labels[discovery.LabelManagedBy]
|
||||||
return managedBy == controllerName
|
return managedBy == ControllerName
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ func TestNewEndpointSlice(t *testing.T) {
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: endpoints.Name,
|
discovery.LabelServiceName: endpoints.Name,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
GenerateName: fmt.Sprintf("%s-", endpoints.Name),
|
GenerateName: fmt.Sprintf("%s-", endpoints.Name),
|
||||||
@ -86,7 +86,7 @@ func TestNewEndpointSlice(t *testing.T) {
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
discovery.LabelServiceName: endpoints.Name,
|
discovery.LabelServiceName: endpoints.Name,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
Annotations: map[string]string{"foo": "bar"},
|
Annotations: map[string]string{"foo": "bar"},
|
||||||
GenerateName: fmt.Sprintf("%s-", endpoints.Name),
|
GenerateName: fmt.Sprintf("%s-", endpoints.Name),
|
||||||
@ -109,7 +109,7 @@ func TestNewEndpointSlice(t *testing.T) {
|
|||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
discovery.LabelServiceName: endpoints.Name,
|
discovery.LabelServiceName: endpoints.Name,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
GenerateName: fmt.Sprintf("%s-", endpoints.Name),
|
GenerateName: fmt.Sprintf("%s-", endpoints.Name),
|
||||||
@ -134,7 +134,7 @@ func TestNewEndpointSlice(t *testing.T) {
|
|||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
discovery.LabelServiceName: endpoints.Name,
|
discovery.LabelServiceName: endpoints.Name,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
Annotations: map[string]string{"foo2": "bar2"},
|
Annotations: map[string]string{"foo2": "bar2"},
|
||||||
GenerateName: fmt.Sprintf("%s-", endpoints.Name),
|
GenerateName: fmt.Sprintf("%s-", endpoints.Name),
|
||||||
@ -162,7 +162,7 @@ func TestNewEndpointSlice(t *testing.T) {
|
|||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
discovery.LabelServiceName: endpoints.Name,
|
discovery.LabelServiceName: endpoints.Name,
|
||||||
discovery.LabelManagedBy: controllerName,
|
discovery.LabelManagedBy: ControllerName,
|
||||||
},
|
},
|
||||||
Annotations: map[string]string{"foo2": "bar2"},
|
Annotations: map[string]string{"foo2": "bar2"},
|
||||||
GenerateName: fmt.Sprintf("%s-", endpoints.Name),
|
GenerateName: fmt.Sprintf("%s-", endpoints.Name),
|
||||||
|
Loading…
Reference in New Issue
Block a user