Skip to content

Commit

Permalink
Merge pull request #1488 from flanksource/feat/config-component-confi…
Browse files Browse the repository at this point in the history
…g-relationship

feat: allow forming relationships to component and configs by lookup
  • Loading branch information
moshloop authored Dec 8, 2023
2 parents 311edab + bb9ee81 commit 4cf37ee
Show file tree
Hide file tree
Showing 17 changed files with 2,409 additions and 8 deletions.
19 changes: 19 additions & 0 deletions api/v1/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/flanksource/canary-checker/api/external"
"github.com/flanksource/duty"
"github.com/flanksource/duty/connection"
"github.com/flanksource/duty/models"
"github.com/flanksource/duty/types"
Expand Down Expand Up @@ -481,10 +482,28 @@ type AlertManager struct {
AlertManagerCheck `yaml:",inline" json:",inline"`
}

// CheckRelationship defines a way to link the check results to components and configs
// using lookup expressions.
type CheckRelationship struct {
Components []duty.LookupSpec `yaml:"components,omitempty" json:"components,omitempty"`
Configs []duty.LookupSpec `yaml:"configs,omitempty" json:"configs,omitempty"`
}

type Relatable struct {
// Relationships defines a way to link the check results to components and configs
// using lookup expressions.
Relationships *CheckRelationship `yaml:"relationships,omitempty" json:"relationships,omitempty"`
}

func (t Relatable) GetRelationship() *CheckRelationship {
return t.Relationships
}

type AlertManagerCheck struct {
Description `yaml:",inline" json:",inline"`
Templatable `yaml:",inline" json:",inline"`
Connection `yaml:",inline" json:",inline"`
Relatable `yaml:",inline" json:",inline"`
Alerts []string `yaml:"alerts" json:"alerts,omitempty" template:"true"`
Filters map[string]string `yaml:"filters" json:"filters,omitempty" template:"true"`
ExcludeFilters map[string]string `yaml:"exclude_filters" json:"exclude_filters,omitempty" template:"true"`
Expand Down
47 changes: 47 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions checks/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func transform(ctx *context.Context, in *pkg.CheckResult) ([]*pkg.CheckResult, b
t.TransformDeleteStrategy = cUtils.Coalesce(t.TransformDeleteStrategy, in.Check.GetTransformDeleteStrategy())

r := t.ToCheckResult()
r.ParentCheck = in.Check
r.Canary = in.Canary
r.Canary.Namespace = cUtils.Coalesce(t.Namespace, r.Canary.Namespace)
if r.Canary.Labels == nil {
Expand Down
94 changes: 94 additions & 0 deletions config/deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,100 @@ spec:
type: string
type: object
type: object
relationships:
description: Relationships defines a way to link the check results to components and configs using lookup expressions.
properties:
components:
items:
description: LookupSpec defines a tuple of fields to lookup.
properties:
name:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
namespace:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
type:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
type: object
type: array
configs:
items:
description: LookupSpec defines a tuple of fields to lookup.
properties:
name:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
namespace:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
type:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
type: object
type: array
type: object
test:
properties:
expr:
Expand Down
94 changes: 94 additions & 0 deletions config/deploy/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,100 @@ spec:
type: string
type: object
type: object
relationships:
description: Relationships defines a way to link the check results to components and configs using lookup expressions.
properties:
components:
items:
description: LookupSpec defines a tuple of fields to lookup.
properties:
name:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
namespace:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
type:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
type: object
type: array
configs:
items:
description: LookupSpec defines a tuple of fields to lookup.
properties:
name:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
namespace:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
type:
description: Lookup specifies the type of lookup to perform.
properties:
expr:
description: Expr is a cel-expression.
type: string
label:
description: Label specifies the key to lookup on the label.
type: string
value:
description: Value is the static value to use.
type: string
type: object
type: object
type: array
type: object
test:
properties:
expr:
Expand Down
51 changes: 51 additions & 0 deletions config/schemas/canary.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
"password": {
"$ref": "#/$defs/EnvVar"
},
"relationships": {
"$ref": "#/$defs/CheckRelationship"
},
"alerts": {
"items": {
"type": "string"
Expand Down Expand Up @@ -737,6 +740,24 @@
"additionalProperties": false,
"type": "object"
},
"CheckRelationship": {
"properties": {
"components": {
"items": {
"$ref": "#/$defs/LookupSpec"
},
"type": "array"
},
"configs": {
"items": {
"$ref": "#/$defs/LookupSpec"
},
"type": "array"
}
},
"additionalProperties": false,
"type": "object"
},
"CheckStatus": {
"properties": {
"lastTransitionedTime": {
Expand Down Expand Up @@ -2182,6 +2203,36 @@
"additionalProperties": false,
"type": "object"
},
"Lookup": {
"properties": {
"expr": {
"type": "string"
},
"value": {
"type": "string"
},
"label": {
"type": "string"
}
},
"additionalProperties": false,
"type": "object"
},
"LookupSpec": {
"properties": {
"name": {
"$ref": "#/$defs/Lookup"
},
"namespace": {
"$ref": "#/$defs/Lookup"
},
"type": {
"$ref": "#/$defs/Lookup"
}
},
"additionalProperties": false,
"type": "object"
},
"ManagedFieldsEntry": {
"properties": {
"manager": {
Expand Down
Loading

0 comments on commit 4cf37ee

Please sign in to comment.