Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release memory fix and changes to swagger definitions #569

Merged
merged 11 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Pull-Request Testing
on:
pull_request:
workflow_dispatch:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install dependencies
run: go mod download
- name: Install GolangCI Lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2

- name: golangci-lint
run: golangci-lint run --timeout=30m --max-same-issues=0 --out-format=github-actions

test:
name: Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install dependencies
run: go mod download
- name: Run Tests
run: go test -cover `go list ./... | grep -v 'pkg/client'`

test-swagger:
name: Test Swagger
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install dependencies
run: go mod download
- name: Install Swagger
run: go install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5
- name: Generate Swagger
run: swagger generate spec -o ./swagger.json --scan-models --exclude-deps
- name: Validate no changes
run: diff swagger.json ./swaggerui/html/swagger.json
- name: Check breaking changes
if: always()
id: breaking
continue-on-error: true
run: swagger diff --break <(git show master:swaggerui/html/swagger.json) swagger.json > /tmp/swagger_breaking_changes.txt
- name: Add comment
if: failure() && steps.breaking.outcome == 'failure'
uses: mshick/add-pr-comment@v2
with:
message-id: breaking-comment
preformatted: true
message-path: /tmp/swagger_breaking_changes.txt

build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build docker image
run: docker build .
15 changes: 0 additions & 15 deletions .github/workflows/radix-api-pr.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ bin/*
vendor

debug
swaggerui/statik.go

__debug_bin
.dccache
Expand Down
14 changes: 0 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ RUN apk update && \
apk add bash jq alpine-sdk sed gawk git ca-certificates curl && \
apk add --no-cache gcc musl-dev

RUN go install honnef.co/go/tools/cmd/staticcheck@2023.1.3 && \
go install github.com/rakyll/statik@v0.1.7 && \
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5

WORKDIR /go/src/github.com/equinor/radix-api/

# get dependencies
Expand All @@ -18,16 +14,6 @@ RUN go mod download
# copy api code
COPY . .

# Generate swagger
RUN swagger generate spec -o ./swaggerui_src/swagger.json --scan-models --exclude-deps && \
swagger validate ./swaggerui_src/swagger.json && \
statik -src=./swaggerui_src/ -p swaggerui

# lint and unit tests
RUN staticcheck ./... && \
go vet ./... && \
CGO_ENABLED=0 GOOS=linux go test ./...

# Build radix api go project
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w" -a -installsuffix cgo -o /usr/local/bin/radix-api

Expand Down
61 changes: 24 additions & 37 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ CX_ARCHS = amd64
.PHONY: build
build: $(BINS)

.PHONY: test
test:
go test -cover `go list ./...`

mocks:
.PHONY: mocks
mocks: bootstrap
mockgen -source ./api/buildstatus/models/buildstatus.go -destination ./api/test/mock/buildstatus_mock.go -package mock
mockgen -source ./api/deployments/deployment_handler.go -destination ./api/deployments/mock/deployment_handler_mock.go -package mock
mockgen -source ./api/environments/job_handler.go -destination ./api/environments/mock/job_handler_mock.go -package mock
Expand All @@ -31,21 +28,28 @@ mocks:
mockgen -source ./api/utils/jobscheduler/interface.go -destination ./api/utils/jobscheduler/mock/job_scheduler_factory_mock.go -package mock
mockgen -source ./api/events/event_handler.go -destination ./api/events/mock/event_handler_mock.go -package mock

.PHONY: test
test:
go test -cover `go list ./...`

.PHONY: lint
lint: bootstrap
golangci-lint run --max-same-issues 0

build-kaniko:
docker run --rm -it -v $(CURRENT_FOLDER):/workspace gcr.io/kaniko-project/executor:latest --destination=$(DOCKER_REGISTRY)/radix-api-server:3hv6o --snapshotMode=time --cache=true

# This make command is only needed for local testing now
# we also do make swagger inside Dockerfile
.PHONY: swagger
swagger:
rm -f ./swaggerui_src/swagger.json ./swaggerui/statik.go
swagger: SHELL:=/bin/bash
swagger: bootstrap
swagger generate spec -o ./swagger.json --scan-models --exclude-deps
swagger validate ./swagger.json
mv swagger.json ./swaggerui_src/swagger.json
statik -src=./swaggerui_src/ -p swaggerui
mv swagger.json ./swaggerui/html/swagger.json

.PHONY: $(BINS)
$(BINS): vendor
$(BINS): bootstrap
go build -ldflags '$(LDFLAGS)' -o bin/$@ .

.PHONY: docker-build
Expand All @@ -61,34 +65,17 @@ docker-push: $(addsuffix -push,$(IMAGES))
az acr login --name $(CONTAINER_REPO)
docker push $(DOCKER_REGISTRY)/$*-server:$(IMAGE_TAG)

HAS_GOMETALINTER := $(shell command -v gometalinter;)
HAS_DEP := $(shell command -v dep;)
HAS_GIT := $(shell command -v git;)
HAS_SWAGGER := $(shell command -v swagger;)
HAS_STATIK := $(shell command -v statik;)
HAS_SWAGGER := $(shell command -v swagger;)
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
HAS_MOCKGEN := $(shell command -v mockgen;)

vendor:
ifndef HAS_GIT
$(error You must install git)
endif
ifndef HAS_DEP
go get -u github.com/golang/dep/cmd/dep
bootstrap:
ifndef HAS_SWAGGER
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5
endif
ifndef HAS_GOMETALINTER
go get -u github.com/alecthomas/gometalinter
gometalinter --install
ifndef HAS_GOLANGCI_LINT
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2
endif
dep ensure
ifndef HAS_SWAGGER
go get -u github.com/go-swagger/go-swagger/cmd/swagger
ifndef HAS_MOCKGEN
go install github.com/golang/mock/mockgen@v1.6.0
endif

ifndef HAS_STATIK
go get github.com/rakyll/statik
endif

.PHONY: bootstrap
bootstrap: vendor

staticcheck:
staticcheck ./...
48 changes: 16 additions & 32 deletions api/alerting/alerting_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ func UpdateEnvironmentAlertingConfig(accounts models.Accounts, w http.ResponseWr
// required: false
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test group (Required if Impersonate-User is set)
// type: array
// items:
// type: string
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// responses:
// "200":
Expand Down Expand Up @@ -182,10 +180,8 @@ func GetEnvironmentAlertingConfig(accounts models.Accounts, w http.ResponseWrite
// required: false
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test group (Required if Impersonate-User is set)
// type: array
// items:
// type: string
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// responses:
// "200":
Expand Down Expand Up @@ -237,10 +233,8 @@ func EnableEnvironmentAlerting(accounts models.Accounts, w http.ResponseWriter,
// required: false
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test group (Required if Impersonate-User is set)
// type: array
// items:
// type: string
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// responses:
// "200":
Expand Down Expand Up @@ -294,10 +288,8 @@ func DisableEnvironmentAlerting(accounts models.Accounts, w http.ResponseWriter,
// required: false
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test group (Required if Impersonate-User is set)
// type: array
// items:
// type: string
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// responses:
// "200":
Expand Down Expand Up @@ -351,10 +343,8 @@ func UpdateApplicationAlertingConfig(accounts models.Accounts, w http.ResponseWr
// required: false
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test group (Required if Impersonate-User is set)
// type: array
// items:
// type: string
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// responses:
// "200":
Expand Down Expand Up @@ -409,10 +399,8 @@ func GetApplicationAlertingConfig(accounts models.Accounts, w http.ResponseWrite
// required: false
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test group (Required if Impersonate-User is set)
// type: array
// items:
// type: string
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// responses:
// "200":
Expand Down Expand Up @@ -458,10 +446,8 @@ func EnableApplicationAlerting(accounts models.Accounts, w http.ResponseWriter,
// required: false
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test group (Required if Impersonate-User is set)
// type: array
// items:
// type: string
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// responses:
// "200":
Expand Down Expand Up @@ -509,10 +495,8 @@ func DisableApplicationAlerting(accounts models.Accounts, w http.ResponseWriter,
// required: false
// - name: Impersonate-Group
// in: header
// description: Works only with custom setup of cluster. Allow impersonation of test group (Required if Impersonate-User is set)
// type: array
// items:
// type: string
// description: Works only with custom setup of cluster. Allow impersonation of a comma-seperated list of test groups (Required if Impersonate-User is set)
// type: string
// required: false
// responses:
// "200":
Expand Down
Loading
Loading