Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jan 23, 2024
1 parent 457a670 commit 86235d9
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 77 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@bfdd3570ce990073878bf10f6b2d79082de49492 # v2.2.0
with:
go-version: 1.20.x
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # v3.4.0
with:
version: v1.54
args: --timeout 10m
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@bfdd3570ce990073878bf10f6b2d79082de49492 # v2.2.0
with:
go-version: 1.20.x
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- uses: actions/cache@8492260343ad570701412c2f464a5877dc76bace # v2
with:
path: |
Expand Down
36 changes: 18 additions & 18 deletions api/v1/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type SeverityKeywords struct {
}

type KubernetesEventExclusions struct {
Names []string `json:"name" yaml:"name"`
Namespaces []string `json:"namespace" yaml:"namespace"`
Reasons []string `json:"reason" yaml:"reason"`
Names []string `json:"name,omitempty" yaml:"name,omitempty"`
Namespaces []string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
Reasons []string `json:"reason,omitempty" yaml:"reason,omitempty"`
}

// Filter returns true if the given input matches any of the exclusions.
Expand Down Expand Up @@ -55,22 +55,22 @@ type KubernetesEventConfig struct {
SeverityKeywords SeverityKeywords `json:"severityKeywords,omitempty"`
}

type KubernetesConfigExclusions struct {
type KubernetesExclusionConfig struct {
Names []string `json:"name" yaml:"name"`
Kinds []string `json:"kind" yaml:"kind"`
Namespaces []string `json:"namespace" yaml:"namespace"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
}

// List returns the union of the exclusions.
func (t *KubernetesConfigExclusions) List() []string {
func (t *KubernetesExclusionConfig) List() []string {
result := append(t.Names, t.Kinds...)
result = append(result, t.Namespaces...)
return result
}

// Filter returns true if the given input matches any of the exclusions.
func (t *KubernetesConfigExclusions) Filter(name, namespace, kind string, labels map[string]string) bool {
func (t *KubernetesExclusionConfig) Filter(name, namespace, kind string, labels map[string]string) bool {
if name != "" && len(t.Names) != 0 {
if collections.MatchItems(name, t.Names...) {
return true
Expand Down Expand Up @@ -150,18 +150,18 @@ type KubernetesRelationship struct {

type Kubernetes struct {
BaseScraper `json:",inline"`
ClusterName string `json:"clusterName,omitempty"`
Namespace string `json:"namespace,omitempty"`
UseCache bool `json:"useCache,omitempty"`
AllowIncomplete bool `json:"allowIncomplete,omitempty"`
Scope string `json:"scope,omitempty"`
Since string `json:"since,omitempty"`
Selector string `json:"selector,omitempty"`
FieldSelector string `json:"fieldSelector,omitempty"`
Kubeconfig *types.EnvVar `json:"kubeconfig,omitempty"`
MaxInflight int64 `json:"maxInflight,omitempty"`
Event KubernetesEventConfig `json:"event,omitempty"`
Exclusions KubernetesConfigExclusions `json:"exclusions,omitempty"`
ClusterName string `json:"clusterName,omitempty"`
Namespace string `json:"namespace,omitempty"`
UseCache bool `json:"useCache,omitempty"`
AllowIncomplete bool `json:"allowIncomplete,omitempty"`
Scope string `json:"scope,omitempty"`
Since string `json:"since,omitempty"`
Selector string `json:"selector,omitempty"`
FieldSelector string `json:"fieldSelector,omitempty"`
MaxInflight int64 `json:"maxInflight,omitempty"`
Exclusions KubernetesExclusionConfig `json:"exclusions,omitempty"`
Kubeconfig *types.EnvVar `json:"kubeconfig,omitempty"`
Event KubernetesEventConfig `json:"event,omitempty"`

// Relationships specify the fields to use to relate Kubernetes objects.
Relationships []KubernetesRelationship `json:"relationships,omitempty"`
Expand Down
14 changes: 7 additions & 7 deletions api/v1/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ func TestKubernetesConfigExclusions_Filter(t *testing.T) {
}
tests := []struct {
name string
config KubernetesConfigExclusions
config KubernetesExclusionConfig
args args
shouldExclude bool
}{
{
name: "exclusion by name",
config: KubernetesConfigExclusions{
config: KubernetesExclusionConfig{
Names: []string{"junit-*"},
},
args: args{
Expand All @@ -29,7 +29,7 @@ func TestKubernetesConfigExclusions_Filter(t *testing.T) {
},
{
name: "exclusion by namespace",
config: KubernetesConfigExclusions{
config: KubernetesExclusionConfig{
Namespaces: []string{"*-canaries"},
},
args: args{
Expand All @@ -39,7 +39,7 @@ func TestKubernetesConfigExclusions_Filter(t *testing.T) {
},
{
name: "exclusion by kind",
config: KubernetesConfigExclusions{
config: KubernetesExclusionConfig{
Kinds: []string{"*Chart"},
},
args: args{
Expand All @@ -49,7 +49,7 @@ func TestKubernetesConfigExclusions_Filter(t *testing.T) {
},
{
name: "exclusion by labels | exact match",
config: KubernetesConfigExclusions{
config: KubernetesExclusionConfig{
Labels: map[string]string{
"prod": "env",
},
Expand All @@ -63,7 +63,7 @@ func TestKubernetesConfigExclusions_Filter(t *testing.T) {
},
{
name: "exclusion by labels | one matches",
config: KubernetesConfigExclusions{
config: KubernetesExclusionConfig{
Labels: map[string]string{
"prod": "env",
"is-billed": "true",
Expand All @@ -80,7 +80,7 @@ func TestKubernetesConfigExclusions_Filter(t *testing.T) {
},
{
name: "no exclusions",
config: KubernetesConfigExclusions{},
config: KubernetesExclusionConfig{},
args: args{
namespace: "default",
name: "test-foo",
Expand Down
76 changes: 38 additions & 38 deletions api/v1/zz_generated.deepcopy.go

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

4 changes: 0 additions & 4 deletions chart/crds/configs.flanksource.com_scrapeconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1334,10 +1334,6 @@ spec:
items:
type: string
type: array
required:
- name
- namespace
- reason
type: object
severityKeywords:
description: SeverityKeywords is used to identify the severity
Expand Down
Loading

0 comments on commit 86235d9

Please sign in to comment.