Skip to content

Commit

Permalink
[chore] [k8s] fix k8s e2e tests (#33548)
Browse files Browse the repository at this point in the history
**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Only return address that is not empty for `kind` network.
This started affecting the e2e tests possibly because of the
`ubuntu-latest`'s docker version update that is mentioned at
#33520 (comment).
Relates to
#33520.

/cc @fatsheep9146 

Sample `kind` network:

```console
curl --unix-socket /run/docker.sock http://docker/networks/kind | jq              
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   841  100   841    0     0   821k      0 --:--:-- --:--:-- --:--:--  821k
{
  "Name": "kind",
  "Id": "801d2abe204253cbd5d1d135f111a7fb386b830382bde79a699fb4f9aaf674b1",
  "Created": "2024-06-13T15:31:57.738509232+03:00",
  "Scope": "local",
  "Driver": "bridge",
  "EnableIPv6": true,
  "IPAM": {
    "Driver": "default",
    "Options": {},
    "Config": [
      {
        "Subnet": "fc00:f853:ccd:e793::/64"
      },
      {
        "Subnet": "172.18.0.0/16",
        "Gateway": "172.18.0.1"
      }
    ]
  },
  "Internal": false,
  "Attachable": false,
  "Ingress": false,
  "ConfigFrom": {
    "Network": ""
  },
  "ConfigOnly": false,
  "Containers": {
    "db113750635782bc1bfdf31e5f62af3c63f02a9c8844f7fe9ef045b5d9b76d12": {
      "Name": "kind-control-plane",
      "EndpointID": "8b15bb391109ca1ecfbb4bf7a96060b01e3913694d34e23d67eec22684f037bb",
      "MacAddress": "02:42:ac:12:00:02",
      "IPv4Address": "172.18.0.2/16",
      "IPv6Address": "fc00:f853:ccd:e793::2/64"
    }
  },
  "Options": {
    "com.docker.network.bridge.enable_ip_masquerade": "true",
    "com.docker.network.driver.mtu": "1500"
  },
  "Labels": {}
}
```

**Link to tracking Issue:** <Issue number if applicable>

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>

---------

Signed-off-by: ChrsMark <[email protected]>
  • Loading branch information
ChrsMark authored Jun 13, 2024
1 parent b03a61a commit 7519485
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
3 changes: 3 additions & 0 deletions internal/k8stest/k8s_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func CreateCollectorObjects(t *testing.T, client *K8sClient, testID string, mani
manifestFiles, err := os.ReadDir(manifestsDir)
require.NoErrorf(t, err, "failed to read collector manifests directory %s", manifestsDir)
host := HostEndpoint(t)
if host == "" {
require.Fail(t, "host endpoint cannot be empty")
}
var podNamespace string
var podLabels map[string]any
createdObjs := make([]*unstructured.Unstructured, 0, len(manifestFiles))
Expand Down
4 changes: 3 additions & 1 deletion internal/k8stest/k8s_data_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func HostEndpoint(t *testing.T) string {
network, err := client.NetworkInspect(ctx, "kind", types.NetworkInspectOptions{})
require.NoError(t, err)
for _, ipam := range network.IPAM.Config {
return ipam.Gateway
if ipam.Gateway != "" {
return ipam.Gateway
}
}
require.Fail(t, "failed to find host endpoint")
return ""
Expand Down
3 changes: 0 additions & 3 deletions processor/k8sattributesprocessor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func newExpectedValue(mode int, value string) *expectedValue {
// make docker-otelcontribcol
// KUBECONFIG=/tmp/kube-config-otelcol-e2e-testing kind load docker-image otelcontribcol:latest
func TestE2E_ClusterRBAC(t *testing.T) {
t.Skip("skipping flaky test, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33520")

testDir := filepath.Join("testdata", "e2e", "clusterrbac")

Expand Down Expand Up @@ -422,7 +421,6 @@ func TestE2E_ClusterRBAC(t *testing.T) {

// Test with `filter::namespace` set and only role binding to collector's SA. We can't get node and namespace labels/annotations.
func TestE2E_NamespacedRBAC(t *testing.T) {
t.Skip("skipping flaky test, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33520")

testDir := filepath.Join("testdata", "e2e", "namespacedrbac")

Expand Down Expand Up @@ -563,7 +561,6 @@ func TestE2E_NamespacedRBAC(t *testing.T) {
// Test with `filter::namespace` set, role binding for namespace-scoped objects (pod, replicaset) and clusterrole
// binding for node and namespace objects.
func TestE2E_MixRBAC(t *testing.T) {
t.Skip("skipping flaky test, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33520")

testDir := filepath.Join("testdata", "e2e", "mixrbac")

Expand Down
1 change: 0 additions & 1 deletion receiver/k8sclusterreceiver/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing"
// make docker-otelcontribcol
// KUBECONFIG=/tmp/kube-config-otelcol-e2e-testing kind load docker-image otelcontribcol:latest
func TestE2E(t *testing.T) {
t.Skip("skipping flaky test, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33520")

var expected pmetric.Metrics
expectedFile := filepath.Join("testdata", "e2e", "expected.yaml")
Expand Down
8 changes: 4 additions & 4 deletions receiver/k8sclusterreceiver/testdata/e2e/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ resourceMetrics:
stringValue: 1a5b9c371c8a7c5d8b0e56a82395aeee88523b1e2d96f17b4a6ae22bf11936bb
- key: container.image.name
value:
stringValue: registry.k8s.io/kube-apiserver
stringValue: registry.k8s.io/kube-apiserver-amd64
- key: container.image.tag
value:
stringValue: v1.25.3
Expand Down Expand Up @@ -865,7 +865,7 @@ resourceMetrics:
stringValue: 2e506922310bbf1ffb8dbbf56c04e540306f272b794d89ffbe776fe5e2fc148e
- key: container.image.name
value:
stringValue: registry.k8s.io/kube-scheduler
stringValue: registry.k8s.io/kube-scheduler-amd64
- key: container.image.tag
value:
stringValue: v1.25.3
Expand Down Expand Up @@ -918,7 +918,7 @@ resourceMetrics:
stringValue: 3baa03c525095d74e7ee24a5c4c42a4680b131f9b8a68f5e2e853ae569d97e4c
- key: container.image.name
value:
stringValue: registry.k8s.io/kube-controller-manager
stringValue: registry.k8s.io/kube-controller-manager-amd64
- key: container.image.tag
value:
stringValue: v1.25.3
Expand Down Expand Up @@ -971,7 +971,7 @@ resourceMetrics:
stringValue: 5cfead143bc88798f93fae8e05586b1191771477030fe89ed7bca288bb82c0aa
- key: container.image.name
value:
stringValue: registry.k8s.io/kube-proxy
stringValue: registry.k8s.io/kube-proxy-amd64
- key: container.image.tag
value:
stringValue: v1.25.3
Expand Down
1 change: 0 additions & 1 deletion receiver/k8sobjectsreceiver/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const (
)

func TestE2E(t *testing.T) {
t.Skip("skipping flaky test, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33520")

k8sClient, err := k8stest.NewK8sClient(testKubeConfig)
require.NoError(t, err)
Expand Down
1 change: 0 additions & 1 deletion receiver/kubeletstatsreceiver/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
const testKubeConfig = "/tmp/kube-config-otelcol-e2e-testing"

func TestE2E(t *testing.T) {
t.Skip("skipping flaky test, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33520")

var expected pmetric.Metrics
expectedFile := filepath.Join("testdata", "e2e", "expected.yaml")
Expand Down

0 comments on commit 7519485

Please sign in to comment.