-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/loadbalancing] Add return_hostnames option to k8s resolver (#…
…35411) **Description:** Adds an optional configuration option to the k8s resolver which allows for hostnames to be returned instead of IPs. This allows certain scenarios like using istio in sidecar mode. Requirements have been added to the documentation. **Link to tracking Issue:** #18412 **Testing:** Added corresponding hostname-based tests for adding backends/endpoints as well as deleting them. There were also tests missing for the k8s handler and so some tests were added as well there. Specifically failing if you want hostnames, but endpoints are returned that do not have hostnames. Aside from unit tests, also ran this in our lab cluster and deleted pods or performed rollouts to our statefulset. Somewhat tangential to the PR itself, but istio now reports mTLS traffic with zero workarounds required which was the motivation for the issue. **Documentation:** Added documentation explaining the new option and the requirements needed to use it. Also added an additional "important" note object specifically calling out that the k8s resolver needs RBAC to work.
- Loading branch information
Showing
8 changed files
with
259 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: loadbalancingexporter | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Adds a an optional configuration to the k8s resolver which returns hostnames instead of IPs for headless services pointing at statefulsets | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [18412] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [] |
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
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
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
105 changes: 105 additions & 0 deletions
105
exporter/loadbalancingexporter/resolver_k8s_handler_test.go
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,105 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package loadbalancingexporter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestConvertToEndpoints(tst *testing.T) { | ||
// Create dummy Endpoints objects | ||
endpoints1 := &corev1.Endpoints{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-endpoints-1", | ||
Namespace: "test-namespace", | ||
}, | ||
Subsets: []corev1.EndpointSubset{ | ||
{ | ||
Addresses: []corev1.EndpointAddress{ | ||
{ | ||
Hostname: "pod-1", | ||
IP: "192.168.10.101", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
endpoints2 := &corev1.Endpoints{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-endpoints-2", | ||
Namespace: "test-namespace", | ||
}, | ||
Subsets: []corev1.EndpointSubset{ | ||
{ | ||
Addresses: []corev1.EndpointAddress{ | ||
{ | ||
Hostname: "pod-2", | ||
IP: "192.168.10.102", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
endpoints3 := &corev1.Endpoints{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test-endpoints-3", | ||
Namespace: "test-namespace", | ||
}, | ||
Subsets: []corev1.EndpointSubset{ | ||
{ | ||
Addresses: []corev1.EndpointAddress{ | ||
{ | ||
IP: "192.168.10.103", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
returnNames bool | ||
includedEndpoints []*corev1.Endpoints | ||
expectedEndpoints map[string]bool | ||
wantNil bool | ||
}{ | ||
{ | ||
name: "return hostnames", | ||
returnNames: true, | ||
includedEndpoints: []*corev1.Endpoints{endpoints1, endpoints2}, | ||
expectedEndpoints: map[string]bool{"pod-1": true, "pod-2": true}, | ||
wantNil: false, | ||
}, | ||
{ | ||
name: "return IPs", | ||
returnNames: false, | ||
includedEndpoints: []*corev1.Endpoints{endpoints1, endpoints2, endpoints3}, | ||
expectedEndpoints: map[string]bool{"192.168.10.101": true, "192.168.10.102": true, "192.168.10.103": true}, | ||
wantNil: false, | ||
}, | ||
{ | ||
name: "missing hostname", | ||
returnNames: true, | ||
includedEndpoints: []*corev1.Endpoints{endpoints1, endpoints3}, | ||
expectedEndpoints: nil, | ||
wantNil: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
tst.Run(tt.name, func(tst *testing.T) { | ||
ok, res := convertToEndpoints(tt.returnNames, tt.includedEndpoints...) | ||
if tt.wantNil { | ||
assert.Nil(tst, res) | ||
} else { | ||
assert.Equal(tst, tt.expectedEndpoints, res) | ||
} | ||
assert.Equal(tst, !tt.wantNil, ok) | ||
}) | ||
} | ||
} |
Oops, something went wrong.