Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/k8sinventory/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sinventory

go 1.24.4
go 1.24.0

require (
github.com/stretchr/testify v1.11.1
Expand Down
26 changes: 11 additions & 15 deletions receiver/k8sobjectsreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@ import (
"k8s.io/client-go/dynamic"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sinventory"
)

type mode string

const (
PullMode mode = "pull"
WatchMode mode = "watch"

defaultPullInterval time.Duration = time.Hour
defaultMode mode = PullMode
defaultResourceVersion = "1"
defaultPullInterval time.Duration = time.Hour
defaultMode k8sinventory.Mode = k8sinventory.PullMode
defaultResourceVersion = "1"
)

var modeMap = map[mode]bool{
PullMode: true,
WatchMode: true,
var modeMap = map[k8sinventory.Mode]bool{
k8sinventory.PullMode: true,
k8sinventory.WatchMode: true,
}

type ErrorMode string
Expand All @@ -47,7 +43,7 @@ type K8sObjectsConfig struct {
Name string `mapstructure:"name"`
Group string `mapstructure:"group"`
Namespaces []string `mapstructure:"namespaces"`
Mode mode `mapstructure:"mode"`
Mode k8sinventory.Mode `mapstructure:"mode"`
LabelSelector string `mapstructure:"label_selector"`
FieldSelector string `mapstructure:"field_selector"`
Interval time.Duration `mapstructure:"interval"`
Expand Down Expand Up @@ -85,15 +81,15 @@ func (c *Config) Validate() error {
return fmt.Errorf("invalid mode: %v", object.Mode)
}

if object.Mode == PullMode && object.Interval == 0 {
if object.Mode == k8sinventory.PullMode && object.Interval == 0 {
object.Interval = defaultPullInterval
}

if object.Mode == PullMode && len(object.ExcludeWatchType) != 0 {
if object.Mode == k8sinventory.PullMode && len(object.ExcludeWatchType) != 0 {
return errors.New("the Exclude config can only be used with watch mode")
}

if object.Mode == PullMode && c.IncludeInitialState {
if object.Mode == k8sinventory.PullMode && c.IncludeInitialState {
return errors.New("include_initial_state can only be used with watch mode")
}
}
Expand Down
29 changes: 15 additions & 14 deletions receiver/k8sobjectsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
apiWatch "k8s.io/apimachinery/pkg/watch"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sinventory"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sobjectsreceiver/internal/metadata"
)

Expand All @@ -35,14 +36,14 @@ func TestLoadConfig(t *testing.T) {
Objects: []*K8sObjectsConfig{
{
Name: "pods",
Mode: PullMode,
Mode: k8sinventory.PullMode,
Interval: time.Hour,
FieldSelector: "status.phase=Running",
LabelSelector: "environment in (production),tier in (frontend)",
},
{
Name: "events",
Mode: WatchMode,
Mode: k8sinventory.WatchMode,
Namespaces: []string{"default"},
Group: "events.k8s.io",
ExcludeWatchType: []apiWatch.EventType{
Expand All @@ -61,13 +62,13 @@ func TestLoadConfig(t *testing.T) {
Objects: []*K8sObjectsConfig{
{
Name: "pods",
Mode: PullMode,
Mode: k8sinventory.PullMode,
ResourceVersion: "1",
Interval: time.Hour,
},
{
Name: "events",
Mode: PullMode,
Mode: k8sinventory.PullMode,
Interval: time.Hour,
},
},
Expand All @@ -82,14 +83,14 @@ func TestLoadConfig(t *testing.T) {
Objects: []*K8sObjectsConfig{
{
Name: "events",
Mode: WatchMode,
Mode: k8sinventory.WatchMode,
Namespaces: []string{"default"},
Group: "events.k8s.io",
ResourceVersion: "",
},
{
Name: "events",
Mode: WatchMode,
Mode: k8sinventory.WatchMode,
Namespaces: []string{"default"},
Group: "events.k8s.io",
ResourceVersion: "2",
Expand Down Expand Up @@ -150,7 +151,7 @@ func TestValidate(t *testing.T) {
Objects: []*K8sObjectsConfig{
{
Name: "pods",
Mode: PullMode,
Mode: k8sinventory.PullMode,
ExcludeWatchType: []apiWatch.EventType{
apiWatch.Deleted,
},
Expand All @@ -177,7 +178,7 @@ func TestValidate(t *testing.T) {
Objects: []*K8sObjectsConfig{
{
Name: "pods",
Mode: PullMode,
Mode: k8sinventory.PullMode,
},
},
},
Expand Down Expand Up @@ -209,7 +210,7 @@ func TestDeepCopy(t *testing.T) {
Name: "pods",
Group: "group",
Namespaces: []string{"default"},
Mode: PullMode,
Mode: k8sinventory.PullMode,
FieldSelector: "status.phase=Running",
LabelSelector: "environment in (production),tier in (frontend)",
Interval: time.Hour,
Expand All @@ -234,7 +235,7 @@ func TestDeepCopy(t *testing.T) {
actual.Name = "changed"
actual.Group = "changed"
actual.Namespaces[0] = "changed"
actual.Mode = WatchMode
actual.Mode = k8sinventory.WatchMode
actual.FieldSelector = "changed"
actual.LabelSelector = "changed"
actual.Interval = time.Minute
Expand Down Expand Up @@ -273,7 +274,7 @@ func TestConfigValidationIncludeInitialState(t *testing.T) {
Objects: []*K8sObjectsConfig{
{
Name: "pods",
Mode: WatchMode,
Mode: k8sinventory.WatchMode,
},
},
},
Expand All @@ -286,7 +287,7 @@ func TestConfigValidationIncludeInitialState(t *testing.T) {
Objects: []*K8sObjectsConfig{
{
Name: "pods",
Mode: WatchMode,
Mode: k8sinventory.WatchMode,
},
},
},
Expand All @@ -299,7 +300,7 @@ func TestConfigValidationIncludeInitialState(t *testing.T) {
Objects: []*K8sObjectsConfig{
{
Name: "pods",
Mode: PullMode,
Mode: k8sinventory.PullMode,
},
},
},
Expand All @@ -312,7 +313,7 @@ func TestConfigValidationIncludeInitialState(t *testing.T) {
Objects: []*K8sObjectsConfig{
{
Name: "pods",
Mode: WatchMode,
Mode: k8sinventory.WatchMode,
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions receiver/k8sobjectsreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/google/uuid v1.6.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/k8sleaderelector v0.140.1
github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.140.1
github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sinventory v0.0.0-20251127074440-9df7f9e0b2c4
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.140.1
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.140.1
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/xk8stest v0.140.1
Expand Down Expand Up @@ -152,6 +153,8 @@ retract (
v0.65.0
)

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

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

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