-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: watch kubernetes events (#296)
* feat: watch kubernetes events [skip ci] * chore: update getSourceFromEvent test * feat: impl consuming of the events [skip ci] * refactor: save changes immediately and then consume the collected in interval * wip: setup a way to scrape selected configs by ids * chore: bump sigs.k8s.io/controller-runtime * chore: save results from targetted scrape - go mod tidy on hack - bug fix. KetOne can return empty object without any error. * chore: fix github workflows - Update versions in lint workflow - Update go version in Docker image * fix: Docker image * chore: bump go version in .github/lint.yml * chore: bump duty * chore: remove Involved object definition. * refactor: scrape uses config directly instead of a config index * feat: new format for exclusions [skip ci] * chore: bump commons * chore: go mod tidy on hack * refactor: use mapstructure to decode events instead of json * feat: directly use the kubernetes scraper and remove TargettedScraper interface * chore: create different method to generate event from map. This is because mapstructure doesn't handle the conversion of timestamp (string) to time.Time type * refactor: move KubernetsEvent to v1 so Filter() can take event object as an argument * feat: enable retry when watching events * chore: bump gomplate * chore: cleanup
- Loading branch information
1 parent
8a8b510
commit 21f5489
Showing
20 changed files
with
1,972 additions
and
695 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
.bin/ | ||
.config-db/ | ||
.DS_Store | ||
.env | ||
.github/ | ||
.idea/ | ||
.releaserc | ||
.vscode/ | ||
|
||
build | ||
|
||
build/ | ||
chart/ | ||
CONTRIBUTING.md | ||
SECURITY.md | ||
README.md | ||
PROJECT | ||
|
||
cover.out | ||
.releaserc | ||
Dockerfile | ||
PROJECT | ||
README.md | ||
SECURITY.md | ||
test.test |
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,98 @@ | ||
package v1 | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestKubernetesConfigExclusions_Filter(t *testing.T) { | ||
type args struct { | ||
name string | ||
namespace string | ||
kind string | ||
labels map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
config KubernetesExclusionConfig | ||
args args | ||
shouldExclude bool | ||
}{ | ||
{ | ||
name: "exclusion by name", | ||
config: KubernetesExclusionConfig{ | ||
Names: []string{"junit-*"}, | ||
}, | ||
args: args{ | ||
name: "junit-123", | ||
}, | ||
shouldExclude: true, | ||
}, | ||
{ | ||
name: "exclusion by namespace", | ||
config: KubernetesExclusionConfig{ | ||
Namespaces: []string{"*-canaries"}, | ||
}, | ||
args: args{ | ||
namespace: "customer-canaries", | ||
}, | ||
shouldExclude: true, | ||
}, | ||
{ | ||
name: "exclusion by kind", | ||
config: KubernetesExclusionConfig{ | ||
Kinds: []string{"*Chart"}, | ||
}, | ||
args: args{ | ||
kind: "HelmChart", | ||
}, | ||
shouldExclude: true, | ||
}, | ||
{ | ||
name: "exclusion by labels | exact match", | ||
config: KubernetesExclusionConfig{ | ||
Labels: map[string]string{ | ||
"prod": "env", | ||
}, | ||
}, | ||
args: args{ | ||
labels: map[string]string{ | ||
"prod": "env", | ||
}, | ||
}, | ||
shouldExclude: true, | ||
}, | ||
{ | ||
name: "exclusion by labels | one matches", | ||
config: KubernetesExclusionConfig{ | ||
Labels: map[string]string{ | ||
"prod": "env", | ||
"is-billed": "true", | ||
"trace-enabled": "true", | ||
}, | ||
}, | ||
args: args{ | ||
labels: map[string]string{ | ||
"prod": "env", | ||
"trace-enabled": "false", | ||
}, | ||
}, | ||
shouldExclude: true, | ||
}, | ||
{ | ||
name: "no exclusions", | ||
config: KubernetesExclusionConfig{}, | ||
args: args{ | ||
namespace: "default", | ||
name: "test-foo", | ||
}, | ||
shouldExclude: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.config.Filter(tt.args.name, tt.args.namespace, tt.args.kind, tt.args.labels); got != tt.shouldExclude { | ||
t.Errorf("KubernetesConfigExclusions.Filter() = %v, want %v", got, tt.shouldExclude) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.