@@ -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
5153const (
@@ -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 }
0 commit comments