Skip to content

Commit

Permalink
chore: merged from main & fixed run sparrow test
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Bressi <[email protected]>
  • Loading branch information
puffitos committed Dec 6, 2023
2 parents 8321bba + 2e90825 commit b430b71
Show file tree
Hide file tree
Showing 51 changed files with 1,134 additions and 298 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ jobs:

- name: Get Version
id: version
run: jq -r '.version' ./dist/metadata.json | { read value; echo "value=$value"; } >> "$GITHUB_OUTPUT"
run: echo "value=commit-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "ghcr.io/caas-team/sparrow:v${{ steps.version.outputs.value }}"
image-ref: "ghcr.io/caas-team/sparrow:${{ steps.version.outputs.value }}"
format: "sarif"
output: "trivy-results.sarif"

Expand All @@ -61,4 +61,4 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push snapshot container image
run: docker push ghcr.io/caas-team/sparrow:v${{ steps.version.outputs.value }}
run: docker push ghcr.io/caas-team/sparrow:${{ steps.version.outputs.value }}
84 changes: 84 additions & 0 deletions .github/workflows/end2end.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# This workflow installs 1 instance of sparrow and
# verify the API output

name: End2End Testing
on:
push:
paths:
- 'chart/**'

jobs:
end2end:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Set up K3S
uses: debianmaster/actions-k3s@master
id: k3s
with:
version: 'v1.26.9-k3s1'
- name: Check Cluster
run: |
kubectl get nodes
- name: Check Coredns Deployment
run: |
kubectl -n kube-system rollout status deployment/coredns --timeout=60s
STATUS=$(kubectl -n kube-system get deployment coredns -o jsonpath={.status.readyReplicas})
if [[ $STATUS -ne 1 ]]
then
echo "Deployment coredns not ready"
kubectl -n kube-system get events
exit 1
else
echo "Deployment coredns OK"
fi
- name: Check Metricsserver Deployment
run: |
kubectl -n kube-system rollout status deployment/metrics-server --timeout=60s
STATUS=$(kubectl -n kube-system get deployment metrics-server -o jsonpath={.status.readyReplicas})
if [[ $STATUS -ne 1 ]]
then
echo "Deployment metrics-server not ready"
kubectl -n kube-system get events
exit 1
else
echo "Deployment metrics-server OK"
fi
- name: Setup Helm
run: |
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
helm version
- name: Get Image Tag
id: version
run: echo "value=commit-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Install Sparrow
run: |
helm upgrade -i sparrow \
--atomic \
--timeout 300s \
--set extraArgs.loaderType=file \
--set extraArgs.loaderFilePath=/runconfig/checks.yaml \
--set image.tag=${{ steps.version.outputs.value }} \
chart
- name: Check Pods
run: |
kubectl get pods
- name: Wait for Sparrow
run: |
sleep 60
- name: Healthcheck
run: |
kubectl create job curl --image=quay.io/curl/curl:latest -- curl -f -v -H 'Content-Type: application/json' http://sparrow:8080/v1/metrics/health
kubectl wait --for=condition=complete job/curl
STATUS=$(kubectl get job curl -o jsonpath={.status.succeeded})
if [[ $STATUS -ne 1 ]]
then
echo "Job failed"
kubectl logs -ljob-name=curl
kubectl delete job curl
exit 1
else
echo "Job OK"
kubectl delete job curl
fi
22 changes: 20 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:
packages: write

jobs:
rel:
main:
name: Release Sparrow
runs-on: ubuntu-latest
steps:
Expand All @@ -35,4 +35,22 @@ jobs:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

helm:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Registry login
run: helm registry login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}

- name: Helm lint
run: helm lint ./chart

- name: Helm package
run: helm package ./chart -d ./chart

- name: Push helm package
run: helm push $(ls ./chart/*.tgz| head -1) oci://ghcr.io/${{ github.repository_owner }}/charts
160 changes: 160 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
linters-settings:
depguard:
# new configuration
rules:
logger:
deny:
# logging is allowed only by logutils.Log,
# logrus is allowed to use only in logutils package.
- pkg: "github.com/sirupsen/logrus"
desc: logging is allowed only by logutils.Log
dupl:
threshold: 100
funlen:
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner.
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
gocyclo:
min-complexity: 15
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
goimports:
local-prefixes: github.com/golangci/golangci-lint
gomnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
ignored-numbers:
- '0'
- '1'
- '2'
- '3'
ignored-functions:
- strings.SplitN

govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
revive:
rules:
- name: unexported-return
disabled: true
- name: unused-parameter

linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
- exportloopref
- funlen
- gocheckcompilerdirectives
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- noctx
- nolintlint
- revive
- staticcheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

# don't enable:
# - asciicheck
# - scopelint
# - gochecknoglobals
# - gocognit
# - godot
# - godox
# - goerr113
# - interfacer
# - lll
# - maligned
# - nestif
# - prealloc
# - stylecheck
# - testpackage
# - wsl

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gomnd

- path: pkg/golinters/errcheck.go
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
- path: pkg/commands/run.go
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
- path: pkg/commands/run.go
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used."

- path: pkg/golinters/gofumpt.go
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
- path: pkg/golinters/staticcheck_common.go
text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead."
- path: pkg/lint/lintersdb/manager.go
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."
- path: pkg/golinters/unused.go
text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)"
- path: test/(fix|linters)_test.go
text: "string `gocritic.go` has 3 occurrences, make it a constant"

run:
timeout: 5m
skip-dirs:
- test/testdata_etc # test files
- internal/cache # extracted from Go code
- internal/renameio # extracted from Go code
- internal/robustio # extracted from Go code
6 changes: 4 additions & 2 deletions .goreleaser-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
project_name: sparrow
snapshot:
name_template: "commit-{{ .ShortCommit }}"
builds:
- env: [CGO_ENABLED=0]
ldflags:
- -s -w -X main.version=v{{ .Version }}
- -s -w -X main.version={{ .Version }}
- -extldflags "-static"
goos:
- linux
Expand All @@ -11,7 +13,7 @@ builds:
- arm64
dockers:
- image_templates:
- "ghcr.io/caas-team/sparrow:v{{ .Version }}"
- "ghcr.io/caas-team/sparrow:{{ .Version }}"
dockerfile: Dockerfile
build_flag_templates:
- --label=org.opencontainers.image.title={{ .ProjectName }}
Expand Down
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
repos:
- repo: local
hooks:
- id: go-generate-repo
name: go generate
entry: go
args: [ generate, ./... ]
language: system
types: [ go ]
pass_filenames: false
always_run: true
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-mod-tidy-repo
- id: go-test-repo-mod
args: [ -race ]
- id: go-vet-repo-mod
- id: go-fumpt-repo
args: [ -l, -w ]
- id: golangci-lint-repo-mod
args: [ --config, .golangci.yaml, --, --fix ]
- repo: https://github.com/norwoodj/helm-docs
rev: "v1.11.3"
hooks:
- id: helm-docs
args:
- --chart-search-root=chart
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @y-eight @NiklasTreml @puffitos @nico151999 @lvlcn-t
* @y-eight @NiklasTreml @puffitos @nico151999 @lvlcn-t @eumel8
3 changes: 2 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Maximilian Schubert [y-eight], Deutsche Telekom IT GmbH
Niklas Treml [niklastreml], Deutsche Telekom IT GmbH
Bruno Bressi [puffitos], Deutsche Telekom IT GmbH
Nico Feulner [nico151999], Deutsche Telekom IT GmbH
Tom Vendolsky [lvlcn-t], Deutsche Telekom IT GmbH
Tom Vendolsky [lvlcn-t], Deutsche Telekom IT GmbH
Frank Kloeker [eumel8], Deutsche Telekom IT GmbH
Loading

0 comments on commit b430b71

Please sign in to comment.