Skip to content

Commit

Permalink
[chore][internal/k8stest] Make k8stest package publicly available
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Jan 24, 2025
1 parent a05740a commit 8cd81f9
Show file tree
Hide file tree
Showing 30 changed files with 69 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ internal/exp/metrics/ @open-telemetry
internal/filter/ @open-telemetry/collector-contrib-approvers @open-telemetry/collector-approvers
internal/grpcutil/ @open-telemetry/collector-contrib-approvers @jmacd @moh-osman3 @lquerel
internal/k8sconfig/ @open-telemetry/collector-contrib-approvers @dmitryax
internal/k8stest/ @open-telemetry/collector-contrib-approvers @crobert-1
internal/kafka/ @open-telemetry/collector-contrib-approvers @pavolloffay @MovieStoreGuy
internal/kubelet/ @open-telemetry/collector-contrib-approvers @dmitryax
internal/metadataproviders/ @open-telemetry/collector-contrib-approvers @Aneurysm9 @dashpole
Expand Down Expand Up @@ -167,6 +166,7 @@ pkg/translator/signalfx/ @open-telemetry
pkg/translator/skywalking/ @open-telemetry/collector-contrib-approvers @JaredTan95
pkg/translator/zipkin/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @andrzej-stencel @crobert-1
pkg/winperfcounters/ @open-telemetry/collector-contrib-approvers @dashpole @Mrod1598 @alxbl @pjanotti
pkg/xk8stest/ @open-telemetry/collector-contrib-approvers @crobert-1

processor/attributesprocessor/ @open-telemetry/collector-contrib-approvers @boostchicken
processor/coralogixprocessor/ @open-telemetry/collector-contrib-approvers @crobert-1 @povilasv
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ body:
- internal/filter
- internal/grpcutil
- internal/k8sconfig
- internal/k8stest
- internal/kafka
- internal/kubelet
- internal/metadataproviders
Expand Down Expand Up @@ -170,6 +169,7 @@ body:
- pkg/translator/skywalking
- pkg/translator/zipkin
- pkg/winperfcounters
- pkg/xk8stest
- processor/attributes
- processor/coralogix
- processor/cumulativetodelta
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ body:
- internal/filter
- internal/grpcutil
- internal/k8sconfig
- internal/k8stest
- internal/kafka
- internal/kubelet
- internal/metadataproviders
Expand Down Expand Up @@ -164,6 +163,7 @@ body:
- pkg/translator/skywalking
- pkg/translator/zipkin
- pkg/winperfcounters
- pkg/xk8stest
- processor/attributes
- processor/coralogix
- processor/cumulativetodelta
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ body:
- internal/filter
- internal/grpcutil
- internal/k8sconfig
- internal/k8stest
- internal/kafka
- internal/kubelet
- internal/metadataproviders
Expand Down Expand Up @@ -164,6 +163,7 @@ body:
- pkg/translator/skywalking
- pkg/translator/zipkin
- pkg/winperfcounters
- pkg/xk8stest
- processor/attributes
- processor/coralogix
- processor/cumulativetodelta
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/unmaintained.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ body:
- internal/filter
- internal/grpcutil
- internal/k8sconfig
- internal/k8stest
- internal/kafka
- internal/kubelet
- internal/metadataproviders
Expand Down Expand Up @@ -169,6 +168,7 @@ body:
- pkg/translator/skywalking
- pkg/translator/zipkin
- pkg/winperfcounters
- pkg/xk8stest
- processor/attributes
- processor/coralogix
- processor/cumulativetodelta
Expand Down
2 changes: 1 addition & 1 deletion cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuremonitorexporter => ../../exporter/azuremonitorexporter
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuredataexplorerexporter => ../../exporter/azuredataexplorerexporter
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig => ../../internal/k8sconfig
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest => ../../internal/k8stest
- github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest => ../../pkg/xk8stest
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka => ../../internal/kafka
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/rabbitmq => ../../internal/rabbitmq
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver => ../../receiver/carbonreceiver
Expand Down
2 changes: 1 addition & 1 deletion connector/datadogconnector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sco

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/docker => ../../internal/docker

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest => ../../internal/k8stest
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest => ../../pkg/xk8stest

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry => ../../pkg/resourcetotelemetry

Expand Down
2 changes: 1 addition & 1 deletion exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ replace github.com/openshift/api v3.9.0+incompatible => github.com/openshift/api

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest => ../../internal/k8stest
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest => ../../pkg/xk8stest

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dockerstatsreceiver => ../../receiver/dockerstatsreceiver

Expand Down
2 changes: 0 additions & 2 deletions exporter/datadogexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion exporter/datadogexporter/integrationtest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ replace github.com/openshift/api v3.9.0+incompatible => github.com/openshift/api

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../../pkg/pdatatest

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest => ../../../internal/k8stest
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest => ../../../pkg/xk8stest

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dockerstatsreceiver => ../../../receiver/dockerstatsreceiver

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions internal/k8stest/README.md → pkg/xk8stest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

The purpose of this package is to provide reusable kubernetes test helpers.

**Warning:**
This package is experimental and its API compatibility might be broken without any notice.

## Functionality

This package includes the ability to [create and delete k8s objects](./k8s_objects.go),
Expand Down
2 changes: 1 addition & 1 deletion internal/k8stest/client.go → pkg/xk8stest/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package k8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest"
package xk8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest"

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion internal/k8stest/go.mod → pkg/xk8stest/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest
module github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest

go 1.22.0

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package k8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest"
package xk8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest"

import (
"bytes"
Expand All @@ -20,27 +20,30 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
)

func CreateCollectorObjects(t *testing.T, client *K8sClient, testID string, manifestsDir string) []*unstructured.Unstructured {
func CreateCollectorObjects(t *testing.T, client *K8sClient, testID string, manifestsDir string, templateValues map[string]string, host string) []*unstructured.Unstructured {
if manifestsDir == "" {
manifestsDir = filepath.Join(".", "testdata", "e2e", "collector")
}
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")
host = HostEndpoint(t)
}
var podNamespace string
var podLabels map[string]any
createdObjs := make([]*unstructured.Unstructured, 0, len(manifestFiles))
for _, manifestFile := range manifestFiles {
tmpl := template.Must(template.New(manifestFile.Name()).ParseFiles(filepath.Join(manifestsDir, manifestFile.Name())))
manifest := &bytes.Buffer{}
require.NoError(t, tmpl.Execute(manifest, map[string]string{
defaultTemplateValues := map[string]string{
"Name": "otelcol-" + testID,
"HostEndpoint": host,
"TestID": testID,
}))
}
for key, value := range templateValues {
defaultTemplateValues[key] = value
}
require.NoError(t, tmpl.Execute(manifest, defaultTemplateValues))
obj, err := CreateObject(client, manifest.Bytes())
require.NoErrorf(t, err, "failed to create collector object from manifest %s", manifestFile.Name())
objKind := obj.GetKind()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package k8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest"
package xk8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest"

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package k8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest"
package xk8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest"

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package k8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8stest"
package xk8stest // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest"

import (
"bytes"
Expand Down
File renamed without changes.
Loading

0 comments on commit 8cd81f9

Please sign in to comment.