-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move examples from docs to fixtures
* chore: move examples from docs to fixutres * chore: add schema validation for fixtures * chore: cleaner error handling * chore: fix breaking test flow
- Loading branch information
1 parent
71f3b6a
commit 90e0283
Showing
11 changed files
with
111 additions
and
8 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
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,11 @@ | ||
apiVersion: mission-control.flanksource.com/v1 | ||
kind: Notification | ||
metadata: | ||
name: cronjob-alerts | ||
namespace: default | ||
spec: | ||
events: | ||
- config.unhealthy | ||
filter: config.type == 'Kubernetes::CronJob' | ||
to: | ||
email: [email protected] |
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,11 @@ | ||
apiVersion: mission-control.flanksource.com/v1 | ||
kind: Notification | ||
metadata: | ||
name: deployment-health-alerts | ||
spec: | ||
events: | ||
- config.unhealthy | ||
- config.warning | ||
filter: config.type == 'Kubernetes::Deployment' | ||
to: | ||
connection: connection://mission-control/slack |
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,21 @@ | ||
apiVersion: mission-control.flanksource.com/v1 | ||
kind: Notification | ||
metadata: | ||
name: podcrashlooping-alerts | ||
namespace: default | ||
spec: | ||
events: | ||
- config.unhealthy | ||
filter: config.type == 'Kubernetes::Pod' && config.status == 'CrashLoopBackOff' | ||
title: "Pod {{.config.name}} in namespace {{.config.tags.namespace}} is in CrashLoopBackOff" | ||
template: | | ||
{{.config.tags.namespace}}/{{.config.name}} | ||
## Reason | ||
{{.config.config | jq '.status.containerStatuses[0].state.waiting.message' }} | ||
### Labels: | ||
{{range $k, $v := .config.config.metadata.labels}} | ||
**{{$k}}**: {{$v}} | ||
{{end}} | ||
to: | ||
email: [email protected] |
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
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
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,57 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/santhosh-tekuri/jsonschema/v6" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func validateFixtureDirWithSchema(schemaPath, dir string) { | ||
schema, err := jsonschema.NewCompiler().Compile(schemaPath) | ||
Expect(err).To(BeNil()) | ||
|
||
err = filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { | ||
if strings.HasSuffix(path, ".yaml") || strings.HasSuffix(path, ".yml") { | ||
yamlRaw, err := os.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var m any | ||
err = yaml.Unmarshal(yamlRaw, &m) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := schema.Validate(m); err != nil { | ||
return fmt.Errorf("schema validation failed for %s: %w", path, err) | ||
} | ||
} | ||
return nil | ||
}) | ||
Expect(err).To(BeNil()) | ||
} | ||
|
||
var _ = Describe("Fixture schema validation", func() { | ||
It("Notifications", func() { | ||
schemaPath := "../config/schemas/notification.schema.json" | ||
validateFixtureDirWithSchema(schemaPath, "../fixtures/notifications/") | ||
}) | ||
|
||
It("Playbooks", func() { | ||
schemaPath := "../config/schemas/playbook.schema.json" | ||
validateFixtureDirWithSchema(schemaPath, "../fixtures/playbooks/") | ||
}) | ||
|
||
It("Rules", func() { | ||
schemaPath := "../config/schemas/incident-rules.schema.json" | ||
validateFixtureDirWithSchema(schemaPath, "../fixtures/rules") | ||
}) | ||
}) |