Skip to content

Commit

Permalink
Merge pull request #404 from flanksource/moshloop
Browse files Browse the repository at this point in the history
postgres + javascript
  • Loading branch information
moshloop authored Jan 2, 2022
2 parents 858aa42 + eba90d9 commit 1bee13b
Show file tree
Hide file tree
Showing 61 changed files with 3,309 additions and 1,319 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ on:
- "**.go"
- "Makefile"
- "**.yaml"
- '**.yml'
- '**/github/workflows/lint.yml'
- '**/.eslint*'
- '**/package.json'
- 'Makefile'
- '**.jsx?'
- '**.tsx?'
- "**.yml"
- "**/github/workflows/lint.yml"
- "**/.eslint*"
- "**/package.json"
- "Makefile"
- "**.jsx?"
- "**.tsx?"
pull_request:
paths:
- "**.go"
- "Makefile"
- "**.yaml"
- '**.yml'
- '**/github/workflows/lint.yml'
- '**/.eslint*'
- '**/package.json'
- 'Makefile'
- '**.jsx?'
- '**.tsx?'
- "**.yml"
- "**/github/workflows/lint.yml"
- "**/.eslint*"
- "**/package.json"
- "Makefile"
- "**.jsx?"
- "**.tsx?"
jobs:
eslint:
runs-on: ubuntu-latest
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.17.x
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
- name: setup node
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/postgres-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.17.x
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/cache@v2
Expand All @@ -39,4 +39,4 @@ jobs:
cache-
- run: make bin
- name: Test
run: ./test/e2e-postgres.sh
run: ./test/e2e-postgres.sh
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x
go-version: 1.17.x
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 20m
build-tags: aws

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN npm i
ADD ui/ .
RUN ls && npm run build

FROM golang:1.16 as builder
FROM golang:1.17 as builder
WORKDIR /app
COPY ./ ./
ARG NAME
Expand All @@ -17,7 +17,7 @@ RUN go mod download
COPY --from=node /app/build /app/ui/build
WORKDIR /app
RUN go version
RUN GOOS=linux GOARCH=amd64 go build -o canary-checker -ldflags "-X \"main.version=$VERSION\"" main.go
RUN make build

FROM ubuntu:bionic
WORKDIR /app
Expand Down Expand Up @@ -50,5 +50,5 @@ RUN apt-get update && \
rm -Rf /var/lib/apt/lists/* && \
rm -Rf /usr/share/doc && rm -Rf /usr/share/man && \
apt-get clean
COPY --from=builder /app/canary-checker /app
COPY --from=builder /app/.bin/canary-checker /app
ENTRYPOINT ["/app/canary-checker"]
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static: .bin/kustomize manifests generate .bin/yq

# Generate manifests e.g. CRD, RBAC etc.
manifests: .bin/controller-gen .bin/yq
.bin/controller-gen crd:trivialVersions=false paths="./..." output:stdout > config/deploy/crd.yaml
.bin/controller-gen crd paths="./..." output:stdout > config/deploy/crd.yaml
.bin/yq eval -i '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.junit.items.properties.spec.properties.containers.items.properties.ports.items.required=["containerPort", "protocol"]' config/deploy/crd.yaml
.bin/yq eval -i '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.junit.items.properties.spec.properties.initContainers.items.properties.ports.items.required=["containerPort", "protocol"]' config/deploy/crd.yaml

Expand Down Expand Up @@ -102,8 +102,8 @@ compress:

.PHONY: linux
linux: ui
GOOS=linux GOARCH=amd64 go build -o ./.bin/$(NAME)_linux_amd64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
GOOS=linux GOARCH=arm64 go build -o ./.bin/$(NAME)_linux_arm64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
GOOS=linux GOARCH=amd64 go build -o ./.bin/$(NAME)_linux_amd64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go
GOOS=linux GOARCH=arm64 go build -o ./.bin/$(NAME)_linux_arm64 -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go

.PHONY: darwin
darwin: ui
Expand Down Expand Up @@ -154,16 +154,20 @@ ui:
build:
go build -o ./.bin/$(NAME) -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go

.PHONY: fast-build
fast-build:
go build --tags fast -o ./.bin/$(NAME) -ldflags "-X \"main.version=$(VERSION_TAG)\"" main.go

.PHONY: install
install: build
install:
cp ./.bin/$(NAME) /usr/local/bin/

.PHONY: test-e2e
test-e2e: bin
./test/e2e.sh

.bin/controller-gen:
GOBIN=$(PWD)/.bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.0
GOBIN=$(PWD)/.bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0
CONTROLLER_GEN=$(GOBIN)/controller-gen

.bin/kustomize: .bin
Expand Down
3 changes: 3 additions & 0 deletions api/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func (ctx *Context) WithDeadline(deadline time.Time) (*Context, gocontext.Cancel
}

func New(client *kommons.Client, canary v1.Canary) *Context {
if canary.Namespace == "" {
canary.Namespace = "default"
}
return &Context{
Context: gocontext.Background(),
Kommons: client,
Expand Down
31 changes: 13 additions & 18 deletions api/v1/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,7 @@ type GCPConnection struct {
type FolderCheck struct {
Description `yaml:",inline" json:",inline"`
Templatable `yaml:",inline" json:",inline"`
// Path can be the s3 or gcs bucket, or reference to local folder
// for s3 the prefix need to be s3://<bucket-name> for gCloud, gcs://<bucket-name>
// Path to folder or object storage, e.g. `s3://<bucket-name>`, `gcs://<bucket-name>`, `/path/tp/folder`
Path string `yaml:"path" json:"path"`
Filter FolderFilter `yaml:"filter,omitempty" json:"filter,omitempty"`
FolderTest `yaml:",inline" json:",inline"`
Expand Down Expand Up @@ -896,31 +895,27 @@ type ContainerdPush struct {
}

/*
[include:k8s/kuberenetes_pass.yaml]
[include:k8s/kubernetes_pass.yaml]
*/
type Kubernetes struct {
KubernetesCheck `yaml:",inline" json:",inline"`
}

/*
Folder Check provides an abstraction over checker related to folder.
Currently, used to perform the following checks:
- s3bucket check
- search objects matching the provided object path pattern
- check that latest object is no older than provided MaxAge value in seconds
- check that latest object size is not smaller than provided MinSize value in bytes.
- gcsBucket check
- search objects matching the provided object path pattern
- check that latest object is no older than provided MaxAge value in seconds
- check that latest object size is not smaller than provided MinSize value in bytes.
- Smb check: which connects to the given samba server with given credentials
find the age of the latest updated file and compare it with minAge
count the number of file present and compare with minCount if defined
- local Folder check
The folder check lists files in a folder (local or SMB/CIFS) or object storage platform like S3 or GCS and provides a mechanism to test:
* `minAge` - A file has been added within at least minAge e.g Has a backup been created in the last 24h
* `maxAge` - A file has been added and not removed within maxAge e.g. Has a file been processed in less than 24h
* `minSize` -
* `maxSize` -
* `minCount` -
* `maxCount` -
[include:quarantine/smb_pass.yaml]
[include:datasources/s3_bucket_pass.yaml]
[include:datasource/folder_pass.yaml]
[include:datasources/folder_pass.yaml]
*/
type Folder struct {
FolderCheck `yaml:",inline" json:",inline"`
Expand Down
17 changes: 14 additions & 3 deletions api/v1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ type Template struct {
Template string `yaml:"template,omitempty" json:"template,omitempty"`
JSONPath string `yaml:"jsonPath,omitempty" json:"jsonPath,omitempty"`
Expression string `yaml:"expr,omitempty" json:"expr,omitempty"`
Javascript string `yaml:"javascript,omitempty" json:"javascript,omitempty"`
}

func (t Template) IsEmpty() bool {
return t.Template == "" && t.JSONPath == "" && t.Expression == ""
return t.Template == "" && t.JSONPath == "" && t.Expression == "" && t.Javascript == ""
}

// +k8s:deepcopy-gen=false
Expand All @@ -218,9 +219,15 @@ type TestFunction interface {
GetTestFunction() Template
}

// +k8s:deepcopy-gen=false
type Transformer interface {
GetTransformer() Template
}

type Templatable struct {
Test Template `yaml:"test,omitempty" json:"test,omitempty"`
Display Template `yaml:"display,omitempty" json:"display,omitempty"`
Test Template `yaml:"test,omitempty" json:"test,omitempty"`
Display Template `yaml:"display,omitempty" json:"display,omitempty"`
Transform Template `yaml:"transform,omitempty" json:"transform,omitempty"`
}

func (t Templatable) GetTestFunction() Template {
Expand All @@ -231,6 +238,10 @@ func (t Templatable) GetDisplayTemplate() Template {
return t.Display
}

func (t Templatable) GetTransformer() Template {
return t.Transform
}

type Description struct {
// Description for the check
Description string `yaml:"description,omitempty" json:"description,omitempty" template:"true"`
Expand Down
4 changes: 1 addition & 3 deletions api/v1/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions checks/aws_config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !fast

package checks

import (
Expand Down
69 changes: 69 additions & 0 deletions checks/aws_stubs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//go:build fast

package checks

import (
"errors"

"github.com/flanksource/canary-checker/api/context"
"github.com/flanksource/canary-checker/api/external"
"github.com/flanksource/canary-checker/pkg"
)

type S3Checker struct{}
type EC2Checker struct{}
type CloudWatchChecker struct{}
type AwsConfigChecker struct{}

func (c *AwsConfigChecker) Type() string {
return "awsconfig"
}

func (c *AwsConfigChecker) Run(ctx *context.Context) []*pkg.CheckResult {
return pkg.SetupError(ctx.Canary, errors.New("AWS not included in binary"))
}

func (c *EC2Checker) Run(ctx *context.Context) []*pkg.CheckResult {
return pkg.SetupError(ctx.Canary, errors.New("AWS not included in binary"))
}

func (c *CloudWatchChecker) Run(ctx *context.Context) []*pkg.CheckResult {
return pkg.SetupError(ctx.Canary, errors.New("AWS not included in binary"))
}

func (c *S3Checker) Run(ctx *context.Context) []*pkg.CheckResult {
return pkg.SetupError(ctx.Canary, errors.New("AWS not included in binary"))
}

func (c *AwsConfigChecker) Check(ctx *context.Context, extConfig external.Check) *pkg.CheckResult {
return pkg.Fail(extConfig, ctx.Canary).Failf("AWS not included in binary")
}

func (c *CloudWatchChecker) Type() string {
return "cloudwatch"
}

func (c *CloudWatchChecker) Check(ctx *context.Context, extConfig external.Check) *pkg.CheckResult {
return pkg.Fail(extConfig, ctx.Canary).Failf("AWS not included in binary")
}

// Type: returns checker type
func (c *EC2Checker) Type() string {
return "ec2"
}

func (c *EC2Checker) Check(ctx *context.Context, extConfig external.Check) *pkg.CheckResult {
return pkg.Fail(extConfig, ctx.Canary).Failf("AWS not included in binary")
}

func (c *S3Checker) Type() string {
return "s3"
}

func (c *S3Checker) Check(ctx *context.Context, extConfig external.Check) *pkg.CheckResult {
return pkg.Fail(extConfig, ctx.Canary).Failf("AWS not included in binary")
}

func CheckS3Bucket(ctx *context.Context, extConfig external.Check) *pkg.CheckResult {
return pkg.Fail(extConfig, ctx.Canary).Failf("AWS not included in binary")
}
14 changes: 8 additions & 6 deletions checks/cloudwatch.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//go:build !fast

package checks

import (
"fmt"
"strings"

"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types"
Expand Down Expand Up @@ -50,19 +52,19 @@ func (c *CloudWatchChecker) Check(ctx *context.Context, extConfig external.Check
return result.ErrorMessage(err)
}
result.AddDetails(alarms)
message := ""
firing := []string{}
for _, alarm := range alarms.MetricAlarms {
if alarm.StateValue == types.StateValueAlarm {
message += fmt.Sprintf("alarm '%s': is in %s state Reason: %s ReasonData: %s\n", *alarm.AlarmName, alarm.StateValue, *alarm.StateReason, *alarm.StateReasonData)
firing = append(firing, *alarm.AlarmName)
}
}
for _, alarm := range alarms.CompositeAlarms {
if alarm.StateValue == types.StateValueAlarm {
message += fmt.Sprintf("alarm '%s': is in %s state Reason: %s ReasonData: %s\n", *alarm.AlarmName, alarm.StateValue, *alarm.StateReason, *alarm.StateReasonData)
firing = append(firing, *alarm.AlarmName)
}
}
if message != "" {
return result.Failf(message)
if len(firing) > 0 {
return result.Failf(strings.Join(firing, ","))
}
return result
}
Loading

0 comments on commit 1bee13b

Please sign in to comment.