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 radix-api #607

Merged
merged 3 commits into from
Mar 18, 2024
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
26 changes: 12 additions & 14 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,30 @@ on:
workflow_dispatch:

jobs:

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
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

go-version-file: 'go.mod'
- name: golangci-lint
run: golangci-lint run --timeout=30m --max-same-issues=0 --out-format=github-actions
uses: golangci/golangci-lint-action@v4
with:
version: v1.55.2

test:
name: Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version-file: 'go.mod'
- name: Install dependencies
run: go mod download
- name: Run Tests
Expand All @@ -41,9 +39,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: git fetch --no-tags --no-recurse-submodules --depth=1 origin master:master
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
go-version-file: 'go.mod'
- name: Install dependencies
run: go mod download
- name: Install Swagger
Expand All @@ -69,6 +67,6 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build docker image
run: docker build .
15 changes: 15 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
run:
timeout: 30m

linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
- zerologlint

issues:
max-same-issues: 0
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"REQUIRE_APP_CONFIGURATION_ITEM": "true",
"REQUIRE_APP_AD_GROUPS": "true",
"RADIX_ENVIRONMENT":"qa",
"RADIX_APP":"radix-api"
"RADIX_APP":"radix-api",
"LOG_LEVEL":"info",
"LOG_PRETTY":"true"
},
"args": [
"--useOutClusterClient=false"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21-alpine3.18 as builder
FROM golang:1.21-alpine3.19 as builder
ENV GO111MODULE=on

RUN apk update && \
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ mocks: bootstrap
mockgen -source ./api/utils/tlsvalidation/interface.go -destination ./api/utils/tlsvalidation/mock/tls_secret_validator_mock.go -package mock
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
mockgen -source ./api/environmentvariables/env_vars_handler.go -destination ./api/environmentvariables/env_vars_handler_mock.go -package environmentvariables
mockgen -source ./api/environmentvariables/env_vars_handler_factory.go -destination ./api/environmentvariables/env_vars_handler_factory_mock.go -package environmentvariables

.PHONY: test
test:
Expand Down
19 changes: 10 additions & 9 deletions api/applications/applications_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/equinor/radix-operator/pkg/apis/radixvalidators"
operatorUtils "github.com/equinor/radix-operator/pkg/apis/utils"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
authorizationapi "k8s.io/api/authorization/v1"
rbacv1 "k8s.io/api/rbac/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -144,7 +144,8 @@ func (ah *ApplicationHandler) RegisterApplication(ctx context.Context, applicati
}
if len(application.SharedSecret) == 0 {
application.SharedSecret = radixutils.RandString(20)
log.Debugf("There is no Shared Secret specified for the registering application - a random Shared Secret has been generated")

log.Ctx(ctx).Debug().Msg("There is no Shared Secret specified for the registering application - a random Shared Secret has been generated")
}

radixRegistration, err := applicationModels.NewApplicationRegistrationBuilder().
Expand Down Expand Up @@ -431,7 +432,7 @@ func (ah *ApplicationHandler) TriggerPipelinePromote(ctx context.Context, appNam
return nil, radixhttp.ValidationError("Radix Application Pipeline", "Deployment name, from environment and to environment are required for \"promote\" pipeline")
}

log.Infof("Creating promote pipeline job for %s using deployment %s from environment %s into environment %s", appName, deploymentName, fromEnvironment, toEnvironment)
log.Ctx(ctx).Info().Msgf("Creating promote pipeline job for %s using deployment %s from environment %s into environment %s", appName, deploymentName, fromEnvironment, toEnvironment)

jobParameters := pipelineParameters.MapPipelineParametersPromoteToJobParameter()

Expand Down Expand Up @@ -470,7 +471,7 @@ func (ah *ApplicationHandler) TriggerPipelineDeploy(ctx context.Context, appName
return nil, radixhttp.ValidationError("Radix Application Pipeline", "To environment is required for \"deploy\" pipeline")
}

log.Infof("Creating deploy pipeline job for %s into environment %s", appName, toEnvironment)
log.Ctx(ctx).Info().Msgf("Creating deploy pipeline job for %s into environment %s", appName, toEnvironment)

pipeline, err := jobPipeline.GetPipelineFromName("deploy")
if err != nil {
Expand Down Expand Up @@ -502,7 +503,7 @@ func (ah *ApplicationHandler) triggerPipelineBuildOrBuildDeploy(ctx context.Cont
return nil, applicationModels.AppNameAndBranchAreRequiredForStartingPipeline()
}

log.Infof("Creating build pipeline job for %s on branch %s for commit %s", appName, branch, commitID)
log.Ctx(ctx).Info().Msgf("Creating build pipeline job for %s on branch %s for commit %s", appName, branch, commitID)

radixRegistration, err := ah.getUserAccount().RadixClient.RadixV1().RadixRegistrations().Get(ctx, appName, metav1.GetOptions{})
if err != nil {
Expand All @@ -528,7 +529,7 @@ func (ah *ApplicationHandler) triggerPipelineBuildOrBuildDeploy(ctx context.Cont
return nil, err
}

log.Infof("Creating build pipeline job for %s on branch %s for commit %s", appName, branch, commitID)
log.Ctx(ctx).Info().Msgf("Creating build pipeline job for %s on branch %s for commit %s", appName, branch, commitID)

jobSummary, err := ah.jobHandler.HandleStartPipelineJob(ctx, appName, pipeline, jobParameters)
if err != nil {
Expand Down Expand Up @@ -631,7 +632,7 @@ func (ah *ApplicationHandler) RegenerateDeployKey(ctx context.Context, appName s
return false, err
})
if errors.Is(err, context.DeadlineExceeded) {
log.Warnf("context deadline exceeded while waiting for new deploy key secret to be created for application %s", appName)
log.Ctx(ctx).Warn().Msgf("context deadline exceeded while waiting for new deploy key secret to be created for application %s", appName)
return nil
}
return err
Expand Down Expand Up @@ -708,7 +709,7 @@ func (ah *ApplicationHandler) validateUserIsMemberOfAdGroups(ctx context.Context
defer func() {
err = deleteRole(context.Background(), ah.accounts.ServiceAccount.Client, ah.namespace, role.GetName())
if err != nil {
log.Warnf("Failed to delete role %s: %v", role.GetName(), err)
log.Ctx(ctx).Warn().Msgf("Failed to delete role %s: %v", role.GetName(), err)
}
}()
roleBinding, err := createRoleBindingForRole(ctx, ah.accounts.ServiceAccount.Client, ah.namespace, role, name, adGroups, labels)
Expand All @@ -718,7 +719,7 @@ func (ah *ApplicationHandler) validateUserIsMemberOfAdGroups(ctx context.Context
defer func() {
err = deleteRoleBinding(context.Background(), ah.accounts.ServiceAccount.Client, ah.namespace, roleBinding.GetName())
if err != nil {
log.Warnf("Failed to delete role binding %s: %v", roleBinding.GetName(), err)
log.Ctx(ctx).Warn().Msgf("Failed to delete role binding %s: %v", roleBinding.GetName(), err)
}
}()

Expand Down
5 changes: 3 additions & 2 deletions api/applications/validate_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/equinor/radix-operator/pkg/apis/utils"
"github.com/rs/zerolog/log"

"github.com/equinor/radix-api/models"
radixhttp "github.com/equinor/radix-common/net/http"
Expand All @@ -16,7 +17,6 @@ import (
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/equinor/radix-operator/pkg/apis/utils/git"
operatornumbers "github.com/equinor/radix-operator/pkg/apis/utils/numbers"
log "github.com/sirupsen/logrus"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -71,7 +71,8 @@ func verifyDeployKey(ctx context.Context, client kubernetes.Interface, rr *v1.Ra
}
return radixhttp.ValidationError("Radix Registration", message)
default:
log.Debugf("Ongoing - build docker image")

log.Ctx(ctx).Debug().Msg("Ongoing - build docker image")
}
}

Expand Down
16 changes: 8 additions & 8 deletions api/environments/component_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
operatorUtils "github.com/equinor/radix-operator/pkg/apis/utils"
jsonPatch "github.com/evanphx/json-patch/v5"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -27,7 +27,8 @@ const (

// StopComponent Stops a component
func (eh EnvironmentHandler) StopComponent(ctx context.Context, appName, envName, componentName string, ignoreComponentStatusError bool) error {
log.Infof("Stopping component %s, %s", componentName, appName)

log.Ctx(ctx).Info().Msgf("Stopping component %s, %s", componentName, appName)
updater, err := eh.getRadixCommonComponentUpdater(ctx, appName, envName, componentName)
if err != nil {
return err
Expand All @@ -47,7 +48,7 @@ func (eh EnvironmentHandler) StopComponent(ctx context.Context, appName, envName

// StartComponent Starts a component
func (eh EnvironmentHandler) StartComponent(ctx context.Context, appName, envName, componentName string, ignoreComponentStatusError bool) error {
log.Infof("Starting component %s, %s", componentName, appName)
log.Ctx(ctx).Info().Msgf("Starting component %s, %s", componentName, appName)
updater, err := eh.getRadixCommonComponentUpdater(ctx, appName, envName, componentName)
if err != nil {
return err
Expand All @@ -67,7 +68,7 @@ func (eh EnvironmentHandler) StartComponent(ctx context.Context, appName, envNam

// RestartComponent Restarts a component
func (eh EnvironmentHandler) RestartComponent(ctx context.Context, appName, envName, componentName string, ignoreComponentStatusError bool) error {
log.Infof("Restarting component %s, %s", componentName, appName)
log.Ctx(ctx).Info().Msgf("Restarting component %s, %s", componentName, appName)
updater, err := eh.getRadixCommonComponentUpdater(ctx, appName, envName, componentName)
if err != nil {
return err
Expand All @@ -84,7 +85,7 @@ func (eh EnvironmentHandler) RestartComponent(ctx context.Context, appName, envN

// RestartComponentAuxiliaryResource Restarts a component's auxiliary resource
func (eh EnvironmentHandler) RestartComponentAuxiliaryResource(ctx context.Context, appName, envName, componentName, auxType string) error {
log.Infof("Restarting auxiliary resource %s for component %s, %s", auxType, componentName, appName)
log.Ctx(ctx).Info().Msgf("Restarting auxiliary resource %s for component %s, %s", auxType, componentName, appName)

deploySummary, err := eh.deployHandler.GetLatestDeploymentForApplicationEnvironment(ctx, appName, envName)
if err != nil {
Expand Down Expand Up @@ -136,7 +137,7 @@ func (eh EnvironmentHandler) ScaleComponent(ctx context.Context, appName, envNam
if replicas > maxScaleReplicas {
return environmentModels.CannotScaleComponentToMoreThanMaxReplicas(appName, envName, componentName, maxScaleReplicas)
}
log.Infof("Scaling component %s, %s to %d replicas", componentName, appName, replicas)
log.Ctx(ctx).Info().Msgf("Scaling component %s, %s to %d replicas", componentName, appName, replicas)
updater, err := eh.getRadixCommonComponentUpdater(ctx, appName, envName, componentName)
if err != nil {
return err
Expand Down Expand Up @@ -184,9 +185,8 @@ func getReplicasForComponentInEnvironment(environmentConfig v1.RadixCommonEnviro

func (eh EnvironmentHandler) patch(ctx context.Context, namespace, name string, oldJSON, newJSON []byte) error {
patchBytes, err := jsonPatch.CreateMergePatch(oldJSON, newJSON)

if err != nil {
log.Fatalln(err)
return err
}

if patchBytes != nil {
Expand Down
15 changes: 7 additions & 8 deletions api/environments/environment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/equinor/radix-api/models"
"github.com/equinor/radix-operator/pkg/apis/defaults"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
)

const rootPath = "/applications/{appName}"
Expand Down Expand Up @@ -272,7 +271,7 @@ func (c *environmentController) GetApplicationEnvironmentDeployments(accounts mo
c.ErrorResponse(w, r, err)
}

c.JSONResponse(w,r, appEnvironmentDeployments)
c.JSONResponse(w, r, appEnvironmentDeployments)
}

// CreateEnvironment Creates a new environment
Expand Down Expand Up @@ -1106,7 +1105,7 @@ func (c *environmentController) GetPodLog(accounts models.Accounts, w http.Respo
fileName := fmt.Sprintf("%s.log", time.Now().Format("20060102150405"))
c.ReaderFileResponse(w, r, logs, fileName, "text/plain; charset=utf-8")
} else {
c.ReaderResponse(w, r, logs, "text/plain; charset=utf-8")
c.ReaderResponse(w, r, logs, "text/plain; charset=utf-8")
}
}

Expand Down Expand Up @@ -1187,14 +1186,14 @@ func (c *environmentController) GetScheduledJobLog(accounts models.Accounts, w h
c.ErrorResponse(w, r, err)
return
}
defer func() {_ = logs.Close()}()
defer func() { _ = logs.Close() }()

if asFile {
fileName := fmt.Sprintf("%s.log", time.Now().Format("20060102150405"))
c.ReaderFileResponse(w, r, logs, fileName, "text/plain; charset=utf-8")

} else {
c.ReaderResponse(w, r, logs, "text/plain; charset=utf-8")
c.ReaderResponse(w, r, logs, "text/plain; charset=utf-8")
}
}

Expand Down Expand Up @@ -2095,7 +2094,7 @@ func (c *environmentController) GetOAuthAuxiliaryResourcePodLog(accounts models.
c.ErrorResponse(w, r, err)
return
}
defer func() {_ = logs.Close()}()
defer func() { _ = logs.Close() }()

if asFile {
fileName := fmt.Sprintf("%s.log", time.Now().Format("20060102150405"))
Expand Down Expand Up @@ -2161,7 +2160,8 @@ func (c *environmentController) GetJobPayload(accounts models.Accounts, w http.R
return
}

c.ReaderResponse(w, r, payload, "text/plain; charset=utf-8")}
c.ReaderResponse(w, r, payload, "text/plain; charset=utf-8")
}

// ScaleComponent Scale component replicas
func (c *environmentController) ScaleComponent(accounts models.Accounts, w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -2216,7 +2216,6 @@ func (c *environmentController) ScaleComponent(accounts models.Accounts, w http.
componentName := mux.Vars(r)["componentName"]
replicas, err := strconv.Atoi(mux.Vars(r)["replicas"])
if err != nil {
log.Error(err)
c.ErrorResponse(w, r, fmt.Errorf("invalid new desired number of replicas argument"))
return
}
Expand Down
Loading