-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use pod dns addrs instead of IPs to check status (#1489)
Summary: Using the pod advertised DNS addr instead of the IP address ensures that the SSL cert is valid and that we can scrape with TLS. Relevant Issues: Followup to a breakage caused by #1480 Type of change: /kind bug Test Plan: skaffold the operator to test. --------- Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>
- Loading branch information
Showing
6 changed files
with
126 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2018- The Pixie Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package k8s | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func GetPodAddr(pod v1.Pod) string { | ||
// IPv4 | ||
podIP := strings.ReplaceAll(pod.Status.PodIP, ".", "-") | ||
// IPv6 | ||
podIP = strings.ReplaceAll(podIP, ":", "-") | ||
|
||
return fmt.Sprintf("%s.%s.pod.cluster.local", podIP, pod.Namespace) | ||
} |
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,63 @@ | ||
/* | ||
* Copyright 2018- The Pixie Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package k8s_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"px.dev/pixie/src/utils/shared/k8s" | ||
) | ||
|
||
func TestGetPodAddr(t *testing.T) { | ||
keyValueStringToMapTests := []struct { | ||
pod v1.Pod | ||
expectedAddr string | ||
}{ | ||
{ | ||
pod: v1.Pod{ | ||
Status: v1.PodStatus{ | ||
PodIP: "1.2.3.4", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "test-ns", | ||
}, | ||
}, | ||
expectedAddr: "1-2-3-4.test-ns.pod.cluster.local", | ||
}, | ||
{ | ||
pod: v1.Pod{ | ||
Status: v1.PodStatus{ | ||
PodIP: "2001:0db8:85a3:0000:0000:8a2e:0370:7334", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: "test-ns", | ||
}, | ||
}, | ||
expectedAddr: "2001-0db8-85a3-0000-0000-8a2e-0370-7334.test-ns.pod.cluster.local", | ||
}, | ||
} | ||
|
||
for _, tc := range keyValueStringToMapTests { | ||
assert.Equal(t, tc.expectedAddr, k8s.GetPodAddr(tc.pod)) | ||
} | ||
} |
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