Skip to content
Open
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
146 changes: 73 additions & 73 deletions workspaces/backend/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
version: "2"
run:
timeout: 5m
allow-parallel-runners: true

issues:
# disable the default set of exclude rules
exclude-use-default: false

exclude-rules:
# disable some linters for api packages
- path: "api/*"
linters:
- lll

# disable some linters for internal packages
- path: "internal/*"
linters:
- dupl
- lll

# exclude some linters for the test directory and test files
- path: test/.*|.*_test\.go
linters:
- dupl
- errcheck
- goconst
- gocyclo
- gosec

linters:
disable-all: true
default: none
enable:
- asciicheck
- bodyclose
Expand All @@ -42,12 +16,9 @@ linters:
- goconst
- gocritic
- gocyclo
- gofmt
- goheader
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
Expand All @@ -57,52 +28,81 @@ linters:
- prealloc
- revive
- staticcheck
- typecheck
- unconvert
- unparam
- unused
settings:
goconst:
ignore-string-values:
- "true"
- "false"
gocritic:
disabled-checks:
- assignOp
- filepathJoin
- paramTypeCombine
- rangeValCopy
- unnamedResult
- whyNoLint
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
goheader:
template: |-
Copyright 2024.

linters-settings:
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- assignOp
- filepathJoin
- paramTypeCombine
- rangeValCopy
- unnamedResult
- whyNoLint
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

goconst:
ignore-strings: "^(true|false)$"
http://www.apache.org/licenses/LICENSE-2.0

goimports:
local-prefixes: github.com/kubeflow/notebooks/workspaces/backend

goheader:
template: |-
Copyright 2024.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

misspell:
locale: US

revive:
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
misspell:
locale: US
revive:
rules:
- name: comment-spacings
exclusions:
generated: lax
rules:
- name: comment-spacings
- linters:
- lll
path: api/*
- linters:
- dupl
- lll
path: internal/*
- linters:
- dupl
- errcheck
- goconst
- gocyclo
- gosec
- prealloc
path: test/.*|.*_test\.go
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/kubeflow/notebooks/workspaces/backend
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion workspaces/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use the golang image to build the application
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
FROM --platform=$BUILDPLATFORM golang:1.26 AS builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
4 changes: 2 additions & 2 deletions workspaces/backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ SWAGGER = $(LOCALBIN)/swag
## Tool Versions
KUSTOMIZE_VERSION ?= v5.5.0
ENVTEST_VERSION ?= release-0.19
GOLANGCI_LINT_VERSION ?= v1.64.8
GOLANGCI_LINT_VERSION ?= v2.11.4
SWAGGER_VERSION ?= v1.16.6

.PHONY: SWAGGER
Expand All @@ -147,7 +147,7 @@ $(ENVTEST): $(LOCALBIN)
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))


##@ deployment
Expand Down
12 changes: 6 additions & 6 deletions workspaces/backend/api/pvcs_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ type PVCCreateEnvelope Envelope[*models.PVCCreate]
// @Failure 422 {object} ErrorEnvelope "Unprocessable Entity. Validation error."
// @Failure 500 {object} ErrorEnvelope "Internal server error"
// @Router /persistentvolumeclaims/{namespace} [get]
func (a *App) GetPVCsByNamespaceHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { //nolint:dupl
func (a *App) GetPVCsByNamespaceHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
namespace := ps.ByName(NamespacePathParam)

// validate path parameters
var valErrs field.ErrorList
valErrs = append(valErrs, helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace)...)
valErrs := helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace)
if len(valErrs) > 0 {
a.failedValidationResponse(w, r, errMsgPathParamsInvalid, valErrs, nil)
return
Expand Down Expand Up @@ -207,9 +206,10 @@ func (a *App) DeletePVCHandler(w http.ResponseWriter, r *http.Request, ps httpro
pvcName := ps.ByName(ResourceNamePathParam)

// validate path parameters
var valErrs field.ErrorList
valErrs = append(valErrs, helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace)...)
valErrs = append(valErrs, helper.ValidateKubernetesPVCName(field.NewPath(ResourceNamePathParam), pvcName)...)
valErrs := append(
helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace),
helper.ValidateKubernetesPVCName(field.NewPath(ResourceNamePathParam), pvcName)...,
)
if len(valErrs) > 0 {
a.failedValidationResponse(w, r, errMsgPathParamsInvalid, valErrs, nil)
return
Expand Down
19 changes: 10 additions & 9 deletions workspaces/backend/api/secrets_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ type SecretCreateEnvelope Envelope[*models.SecretCreate]
// @Failure 422 {object} ErrorEnvelope "Unprocessable Entity. Validation error."
// @Failure 500 {object} ErrorEnvelope "Internal server error"
// @Router /secrets/{namespace} [get]
func (a *App) GetSecretsByNamespaceHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { //nolint:dupl
func (a *App) GetSecretsByNamespaceHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
namespace := ps.ByName(NamespacePathParam)

var valErrs field.ErrorList
valErrs = append(valErrs, helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace)...)
valErrs := helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace)

if len(valErrs) > 0 {
a.failedValidationResponse(w, r, errMsgPathParamsInvalid, valErrs, nil)
Expand Down Expand Up @@ -100,9 +99,10 @@ func (a *App) GetSecretHandler(w http.ResponseWriter, r *http.Request, ps httpro
secretName := ps.ByName(ResourceNamePathParam)

// validate path parameters
var valErrs field.ErrorList
valErrs = append(valErrs, helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace)...)
valErrs = append(valErrs, helper.ValidateKubernetesSecretName(field.NewPath(ResourceNamePathParam), secretName)...)
valErrs := append(
helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace),
helper.ValidateKubernetesSecretName(field.NewPath(ResourceNamePathParam), secretName)...,
)
if len(valErrs) > 0 {
a.failedValidationResponse(w, r, errMsgPathParamsInvalid, valErrs, nil)
return
Expand Down Expand Up @@ -347,9 +347,10 @@ func (a *App) DeleteSecretHandler(w http.ResponseWriter, r *http.Request, ps htt
secretName := ps.ByName(ResourceNamePathParam)

// validate path parameters
var valErrs field.ErrorList
valErrs = append(valErrs, helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace)...)
valErrs = append(valErrs, helper.ValidateKubernetesSecretName(field.NewPath(ResourceNamePathParam), secretName)...)
valErrs := append(
helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace),
helper.ValidateKubernetesSecretName(field.NewPath(ResourceNamePathParam), secretName)...,
)
if len(valErrs) > 0 {
a.failedValidationResponse(w, r, errMsgPathParamsInvalid, valErrs, nil)
return
Expand Down
7 changes: 4 additions & 3 deletions workspaces/backend/api/workspace_actions_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ func (a *App) PauseActionWorkspaceHandler(w http.ResponseWriter, r *http.Request
namespace := ps.ByName(NamespacePathParam)
workspaceName := ps.ByName(ResourceNamePathParam)

var valErrs field.ErrorList
valErrs = append(valErrs, helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace)...)
valErrs = append(valErrs, helper.ValidateWorkspaceName(field.NewPath(ResourceNamePathParam), workspaceName)...)
valErrs := append(
helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace),
helper.ValidateWorkspaceName(field.NewPath(ResourceNamePathParam), workspaceName)...,
)
if len(valErrs) > 0 {
a.failedValidationResponse(w, r, errMsgPathParamsInvalid, valErrs, nil)
return
Expand Down
11 changes: 5 additions & 6 deletions workspaces/backend/api/workspacekinds_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func (a *App) GetWorkspaceKindHandler(w http.ResponseWriter, r *http.Request, ps
name := ps.ByName(ResourceNamePathParam)

// validate path parameters
var valErrs field.ErrorList
valErrs = append(valErrs, helper.ValidateWorkspaceKindName(field.NewPath(ResourceNamePathParam), name)...)
valErrs := helper.ValidateWorkspaceKindName(field.NewPath(ResourceNamePathParam), name)
if len(valErrs) > 0 {
a.failedValidationResponse(w, r, errMsgPathParamsInvalid, valErrs, nil)
return
Expand Down Expand Up @@ -207,10 +206,10 @@ func (a *App) CreateWorkspaceKindHandler(w http.ResponseWriter, r *http.Request,
// NOTE: we only do basic validation so we know it's safe to send to the Kubernetes API server
// comprehensive validation will be done by Kubernetes
// NOTE: checking the name field is non-empty also verifies that the workspace kind is not nil/empty
var valErrs field.ErrorList
valErrs = append(valErrs, helper.ValidateWorkspaceKindGVK(workspaceKind.APIVersion, workspaceKind.Kind)...)
wskNamePath := field.NewPath("metadata", "name")
valErrs = append(valErrs, helper.ValidateWorkspaceKindName(wskNamePath, workspaceKind.Name)...)
valErrs := append(
helper.ValidateWorkspaceKindGVK(workspaceKind.APIVersion, workspaceKind.Kind),
helper.ValidateWorkspaceKindName(field.NewPath("metadata", "name"), workspaceKind.Name)...,
)
if len(valErrs) > 0 {
a.failedValidationResponse(w, r, errMsgRequestBodyInvalid, valErrs, nil)
return
Expand Down
14 changes: 8 additions & 6 deletions workspaces/backend/api/workspaces_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ func (a *App) GetWorkspaceHandler(w http.ResponseWriter, r *http.Request, ps htt
workspaceName := ps.ByName(ResourceNamePathParam)

// validate path parameters
var valErrs field.ErrorList
valErrs = append(valErrs, helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace)...)
valErrs = append(valErrs, helper.ValidateWorkspaceName(field.NewPath(ResourceNamePathParam), workspaceName)...)
valErrs := append(
helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace),
helper.ValidateWorkspaceName(field.NewPath(ResourceNamePathParam), workspaceName)...,
)
if len(valErrs) > 0 {
a.failedValidationResponse(w, r, errMsgPathParamsInvalid, valErrs, nil)
return
Expand Down Expand Up @@ -406,9 +407,10 @@ func (a *App) DeleteWorkspaceHandler(w http.ResponseWriter, r *http.Request, ps
workspaceName := ps.ByName(ResourceNamePathParam)

// validate path parameters
var valErrs field.ErrorList
valErrs = append(valErrs, helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace)...)
valErrs = append(valErrs, helper.ValidateWorkspaceName(field.NewPath(ResourceNamePathParam), workspaceName)...)
valErrs := append(
helper.ValidateKubernetesNamespaceName(field.NewPath(NamespacePathParam), namespace),
helper.ValidateWorkspaceName(field.NewPath(ResourceNamePathParam), workspaceName)...,
)
if len(valErrs) > 0 {
a.failedValidationResponse(w, r, errMsgPathParamsInvalid, valErrs, nil)
return
Expand Down
Loading
Loading