Skip to content

Commit 838baa5

Browse files
committed
fix lint problems
Signed-off-by: Adem Baccara <[email protected]>
1 parent 37bcc19 commit 838baa5

File tree

7 files changed

+63
-56
lines changed

7 files changed

+63
-56
lines changed

workspaces/controller/api/v1beta1/workspace_types.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type WorkspaceSpec struct {
3838

3939
// DisableCulling controls whether automatic culling is disabled for the workspace.
4040
// If true, the workspace will not be culled
41-
//+kubebuilder:validation:Optional
42-
//+kubebuilder:default=false
41+
// +kubebuilder:validation:Optional
42+
// +kubebuilder:default=false
4343
DisableCulling *bool `json:"disableCulling,omitempty"`
4444

4545
// if true, pending updates are NOT applied when the Workspace is paused
@@ -233,24 +233,24 @@ type WorkspacePodOptionRedirectStep struct {
233233
type ProbeStatus struct {
234234

235235
// the time the probe was started (UNIX epoch in milliseconds)
236-
//+kubebuilder:validation:Minimum=0
237-
//+kubebuilder:example=1710435303000
236+
// +kubebuilder:validation:Minimum=0
237+
// +kubebuilder:example=1710435303000
238238
StartTimeMs int64 `json:"startTimeMs"`
239239

240240
// the time the probe was completed (UNIX epoch in milliseconds)
241-
//+kubebuilder:validation:Minimum=0
242-
//+kubebuilder:example=1710435305000
241+
// +kubebuilder:validation:Minimum=0
242+
// +kubebuilder:example=1710435305000
243243
EndTimeMs int64 `json:"endTimeMs"`
244244

245245
// the result of the probe
246246
// ENUM: "Success" | "Failure" | "Timeout" | ""
247-
//+kubebuilder:default=""
247+
// +kubebuilder:default=""
248248
Result ProbeResult `json:"result"`
249249

250250
// a human-readable message about the probe result
251251
// WARNING: this field is NOT FOR MACHINE USE, subject to change without notice
252-
//+kubebuilder:default=""
253-
//+kubebuilder:example="Jupyter probe succeeded"
252+
// +kubebuilder:default=""
253+
// +kubebuilder:example="Jupyter probe succeeded"
254254
Message string `json:"message"`
255255
}
256256

@@ -282,10 +282,10 @@ const (
282282
===============================================================================
283283
*/
284284

285-
//+kubebuilder:object:root=true
286-
//+kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="The current state of the Workspace"
287-
//+kubebuilder:subresource:status
288-
//+kubebuilder:resource:shortName=ws
285+
// +kubebuilder:object:root=true
286+
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="The current state of the Workspace"
287+
// +kubebuilder:subresource:status
288+
// +kubebuilder:resource:shortName=ws
289289

290290
// Workspace is the Schema for the Workspaces API
291291
type Workspace struct {

workspaces/controller/api/v1beta1/workspacekind_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ type WorkspaceKindCullingConfig struct {
185185
MaxInactiveSeconds *int32 `json:"maxInactiveSeconds,omitempty"`
186186

187187
// the maximum number of seconds between probes
188-
//+kubebuilder:validation:Optional
189-
//+kubebuilder:validation:Minimum:=60
190-
//+kubebuilder:default=300
188+
// +kubebuilder:validation:Optional
189+
// +kubebuilder:validation:Minimum:=60
190+
// +kubebuilder:default=300
191191
MaxProbeIntervalSeconds *int32 `json:"maxProbeIntervalSeconds,omitempty"`
192192

193193
// the minimum number of seconds between probes to avoid spamming in case on failure
194-
//+kubebuilder:validation:Optional
195-
//+kubebuilder:validation:Minimum:=10
196-
//+kubebuilder:default=20
194+
// +kubebuilder:validation:Optional
195+
// +kubebuilder:validation:Minimum:=10
196+
// +kubebuilder:default=20
197197
MinProbeIntervalSeconds *int32 `json:"minProbeIntervalSeconds,omitempty"`
198198

199199
// the probe used to determine if the Workspace is active
@@ -219,7 +219,7 @@ type ActivityProbe struct {
219219
type ActivityProbeExec struct {
220220
// the script should write a JSON file at this path.
221221
// any existing file in this path will be REMOVED before the script is run
222-
//+kubebuilder:example="/tmp/activity_probe.json"
222+
// +kubebuilder:example="/tmp/activity_probe.json"
223223
OutputPath string `json:"outputPath"`
224224

225225
// the number of seconds to wait for the script to complete

workspaces/controller/cmd/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ package main
1919
import (
2020
"crypto/tls"
2121
"flag"
22-
"k8s.io/client-go/kubernetes"
2322
"os"
2423

24+
"k8s.io/client-go/kubernetes"
25+
2526
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2627
// to ensure that exec-entrypoint and run can make use of them.
2728
_ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -163,7 +164,7 @@ func main() {
163164
setupLog.Error(err, "unable to create controller", "controller", "Culler")
164165
os.Exit(1)
165166
}
166-
//+kubebuilder:scaffold:builder
167+
// +kubebuilder:scaffold:builder
167168

168169
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
169170
if err = (&webhookInternal.WorkspaceValidator{

workspaces/controller/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ require (
3939
github.com/josharian/intern v1.0.0 // indirect
4040
github.com/json-iterator/go v1.1.12 // indirect
4141
github.com/mailru/easyjson v0.7.7 // indirect
42-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
4342
github.com/moby/spdystream v0.4.0 // indirect
4443
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4544
github.com/modern-go/reflect2 v1.0.2 // indirect

workspaces/controller/go.sum

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
2+
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
13
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
24
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
35
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@@ -44,18 +46,12 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
4446
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
4547
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
4648
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
47-
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
48-
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
4949
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af h1:kmjWCqn2qkEml422C2Rrd27c3VGxi6a/6HNq8QmHRKM=
5050
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
51-
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
52-
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5351
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
5452
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
55-
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
5653
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
5754
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
58-
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
5955
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
6056
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
6157
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
@@ -73,10 +69,7 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
7369
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
7470
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
7571
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
76-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
77-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
78-
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
79-
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
72+
github.com/moby/spdystream v0.4.0 h1:Vy79D6mHeJJjiPdFEL2yku1kl0chZpJfZcPpb16BRl8=
8073
github.com/moby/spdystream v0.4.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
8174
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
8275
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
@@ -87,12 +80,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
8780
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
8881
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
8982
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
90-
github.com/onsi/ginkgo/v2 v2.14.0 h1:vSmGj2Z5YPb9JwCWT6z6ihcUvDhuXLc3sJiqd3jMKAY=
91-
github.com/onsi/ginkgo/v2 v2.14.0/go.mod h1:JkUdW7JkN0V6rFvsHcJ478egV3XH9NxpD27Hal/PhZw=
9283
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
9384
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
94-
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
95-
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
9685
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
9786
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
9887
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

workspaces/controller/internal/controller/culling_controller.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ import (
2222
"encoding/json"
2323
"errors"
2424
"fmt"
25+
"net"
26+
"net/http"
27+
"net/url"
28+
"os"
29+
"strconv"
30+
"strings"
31+
"time"
32+
2533
"github.com/go-logr/logr"
26-
kubefloworgv1beta1 "github.com/kubeflow/notebooks/workspaces/controller/api/v1beta1"
27-
"github.com/kubeflow/notebooks/workspaces/controller/internal/helper"
2834
appsv1 "k8s.io/api/apps/v1"
2935
corev1 "k8s.io/api/core/v1"
3036
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -36,16 +42,12 @@ import (
3642
"k8s.io/client-go/rest"
3743
"k8s.io/client-go/tools/remotecommand"
3844
"k8s.io/utils/ptr"
39-
"net"
40-
"net/http"
41-
"net/url"
42-
"os"
4345
ctrl "sigs.k8s.io/controller-runtime"
4446
"sigs.k8s.io/controller-runtime/pkg/client"
4547
"sigs.k8s.io/controller-runtime/pkg/log"
46-
"strconv"
47-
"strings"
48-
"time"
48+
49+
kubefloworgv1beta1 "github.com/kubeflow/notebooks/workspaces/controller/api/v1beta1"
50+
"github.com/kubeflow/notebooks/workspaces/controller/internal/helper"
4951
)
5052

5153
const (
@@ -69,7 +71,7 @@ type ActivityProbe struct {
6971

7072
// +kubebuilder:rbac:groups="core",resources=pods/exec,verbs=create
7173

72-
func (r *CullingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { // nolint:gocyclo
74+
func (r *CullingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { //nolint:gocyclo
7375
log := log.FromContext(ctx)
7476
log.V(2).Info("reconciling Workspace for culling")
7577
// fetch the Workspace
@@ -176,7 +178,7 @@ func (r *CullingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
176178
Message: "Failed to fetch service name for workspace",
177179
}, nil, nil)
178180
}
179-
port, err := r.getWorkspacePort(ctx, workspace, workspaceKind)
181+
port, err := r.getWorkspacePort(workspace, workspaceKind)
180182
if err != nil {
181183
log.Error(err, "Error fetching port for workspace")
182184
return r.updateWorkspaceActivityStatus(ctx, log, workspace, &minRequeueAfter, &kubefloworgv1beta1.ProbeStatus{
@@ -261,7 +263,7 @@ func (r *CullingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
261263
lastActivity := time.Now().Unix()
262264
if activityProbe.HasActivity != nil && !*activityProbe.HasActivity {
263265
log.V(2).Info("Culling the workspace due to inactivity")
264-
//TODO: figure out how to set the last activity time
266+
// TODO: figure out how to set the last activity time
265267
lastActivity = time.Now().Unix()
266268
workspace.Spec.Paused = ptr.To(true)
267269
err := r.Update(ctx, workspace)
@@ -324,7 +326,7 @@ func (r *CullingReconciler) SetupWithManager(mgr ctrl.Manager) error {
324326
}
325327

326328
// updateWorkspaceActivityStatus attempts to immediately update the Workspace activity status with the provided status.
327-
func (r *CullingReconciler) updateWorkspaceActivityStatus(ctx context.Context, log logr.Logger, workspace *kubefloworgv1beta1.Workspace, requeueAfter *time.Duration, probeStatus *kubefloworgv1beta1.ProbeStatus, lastUpdate, lastActivity *int64) (ctrl.Result, error) { // nolint:unparam
329+
func (r *CullingReconciler) updateWorkspaceActivityStatus(ctx context.Context, log logr.Logger, workspace *kubefloworgv1beta1.Workspace, requeueAfter *time.Duration, probeStatus *kubefloworgv1beta1.ProbeStatus, lastUpdate, lastActivity *int64) (ctrl.Result, error) {
328330
if workspace == nil {
329331
return ctrl.Result{}, fmt.Errorf("provided Workspace was nil")
330332
}
@@ -381,7 +383,7 @@ func (r *CullingReconciler) getServiceName(ctx context.Context, workspace *kubef
381383
return ownedServices.Items[0].Name, nil
382384
}
383385

384-
func (r *CullingReconciler) getWorkspacePort(ctx context.Context, workspace *kubefloworgv1beta1.Workspace, workspaceKind *kubefloworgv1beta1.WorkspaceKind) (int32, error) {
386+
func (r *CullingReconciler) getWorkspacePort(workspace *kubefloworgv1beta1.Workspace, workspaceKind *kubefloworgv1beta1.WorkspaceKind) (int32, error) {
385387
for _, imageConfigValue := range workspaceKind.Spec.PodTemplate.Options.ImageConfig.Values {
386388
if imageConfigValue.Id == workspace.Spec.PodTemplate.Options.ImageConfig {
387389
for _, port := range imageConfigValue.Spec.Ports {
@@ -449,7 +451,7 @@ func (r *CullingReconciler) execCommand(ctx context.Context, podName, podNamespa
449451

450452
executor, err := createExecutor(req.URL(), r.Config)
451453
if err != nil {
452-
return "", "", fmt.Errorf("error creating executor: %v", err)
454+
return "", "", fmt.Errorf("error creating executor: %w", err)
453455
}
454456

455457
var stdout, stderr bytes.Buffer
@@ -492,7 +494,7 @@ func fetchLastActivityFromJupyterAPI(apiEndpoint string) (*time.Time, error, str
492494
LastActivity string `json:"last_activity"`
493495
}
494496

495-
defer resp.Body.Close()
497+
defer resp.Body.Close() //nolint:errcheck
496498
if err := json.NewDecoder(resp.Body).Decode(&status); err != nil {
497499
return nil, fmt.Errorf("failed to parse JupyterLab API response: %w", err),
498500
"Jupyter probe failed: invalid response body", kubefloworgv1beta1.ProbeResultFailure
@@ -509,13 +511,13 @@ func fetchLastActivityFromJupyterAPI(apiEndpoint string) (*time.Time, error, str
509511
}
510512

511513
// createExecutor creates a new Executor for the given URL and REST config.
512-
func createExecutor(url *url.URL, config *rest.Config) (remotecommand.Executor, error) {
513-
exec, err := remotecommand.NewSPDYExecutor(config, "POST", url)
514+
func createExecutor(requestUrl *url.URL, config *rest.Config) (remotecommand.Executor, error) {
515+
exec, err := remotecommand.NewSPDYExecutor(config, "POST", requestUrl)
514516
if err != nil {
515517
return nil, err
516518
}
517519
// WebSocketExecutor must be "GET" method as described in RFC 6455 Sec. 4.1 (page 17).
518-
websocketExec, err := remotecommand.NewWebSocketExecutor(config, "GET", url.String())
520+
websocketExec, err := remotecommand.NewWebSocketExecutor(config, "GET", requestUrl.String())
519521
if err != nil {
520522
return nil, err
521523
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package controller

0 commit comments

Comments
 (0)