Skip to content

Commit 911e388

Browse files
authored
Set included namespaces as loaded from config (#178)
This feature was implemented but was not connected to the config file - oops, my bad! Signed-off-by: Charlie Egan <[email protected]>
1 parent 7e9ce6f commit 911e388

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

agent.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
schedule: "* * * *"
2-
token: eyJjbHVzdGVyIjoibXkgY2x1c3RlciIsInRva2VuIjoidG9rZW4yYiJ9
2+
token: ewogICJjbHVzdGVyIjogIm15IGNsdXN0ZXIiLAogICJ0b2tlbiI6ICJleGFtcGxlIgp9Cg==
33
endpoint:
44
protocol: http
55
host: "localhost:8080"

pkg/datagatherer/k8s/dynamic.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (c *ConfigDynamic) UnmarshalYAML(unmarshal func(interface{}) error) error {
3737
Resource string `yaml:"resource"`
3838
} `yaml:"resource-type"`
3939
ExcludeNamespaces []string `yaml:"exclude-namespaces"`
40+
IncludeNamespaces []string `yaml:"include-namespaces"`
4041
}{}
4142
err := unmarshal(&aux)
4243
if err != nil {
@@ -48,6 +49,7 @@ func (c *ConfigDynamic) UnmarshalYAML(unmarshal func(interface{}) error) error {
4849
c.GroupVersionResource.Version = aux.ResourceType.Version
4950
c.GroupVersionResource.Resource = aux.ResourceType.Resource
5051
c.ExcludeNamespaces = aux.ExcludeNamespaces
52+
c.IncludeNamespaces = aux.IncludeNamespaces
5153

5254
return nil
5355
}

pkg/datagatherer/k8s/dynamic_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestNewDataGathererWithClient(t *testing.T) {
8686
}
8787
}
8888

89-
func TestGenericGatherer_Fetch(t *testing.T) {
89+
func TestDynamicGatherer_Fetch(t *testing.T) {
9090
emptyScheme := runtime.NewScheme()
9191
tests := map[string]struct {
9292
gvr schema.GroupVersionResource
@@ -190,7 +190,7 @@ func TestGenericGatherer_Fetch(t *testing.T) {
190190
}
191191
}
192192

193-
func TestUnmarshalGenericConfig(t *testing.T) {
193+
func TestUnmarshalDynamicConfig(t *testing.T) {
194194
textCfg := `
195195
kubeconfig: "/home/someone/.kube/config"
196196
resource-type:
@@ -200,6 +200,11 @@ resource-type:
200200
exclude-namespaces:
201201
- kube-system
202202
- my-namespace
203+
# this config is invalid, but the validation is tested elsewhere
204+
# include-namespaces is here just to ensure that they are loaded
205+
# from the config file
206+
include-namespaces:
207+
- default
203208
`
204209

205210
expectedGVR := schema.GroupVersionResource{
@@ -213,6 +218,8 @@ exclude-namespaces:
213218
"my-namespace",
214219
}
215220

221+
expectedIncludeNamespaces := []string{"default"}
222+
216223
cfg := ConfigDynamic{}
217224
err := yaml.Unmarshal([]byte(textCfg), &cfg)
218225
if err != nil {
@@ -230,6 +237,9 @@ exclude-namespaces:
230237
if got, want := cfg.ExcludeNamespaces, expectedExcludeNamespaces; !reflect.DeepEqual(got, want) {
231238
t.Errorf("ExcludeNamespaces does not match: got=%+v want=%+v", got, want)
232239
}
240+
if got, want := cfg.IncludeNamespaces, expectedIncludeNamespaces; !reflect.DeepEqual(got, want) {
241+
t.Errorf("IncludeNamespaces does not match: got=%+v want=%+v", got, want)
242+
}
233243
}
234244

235245
func TestConfigDynamicValidate(t *testing.T) {

0 commit comments

Comments
 (0)