Skip to content

Commit

Permalink
fix lint problems
Browse files Browse the repository at this point in the history
Signed-off-by: Adem Baccara <[email protected]>
  • Loading branch information
Adembc committed Feb 12, 2025
1 parent 37bcc19 commit 838baa5
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 56 deletions.
26 changes: 13 additions & 13 deletions workspaces/controller/api/v1beta1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type WorkspaceSpec struct {

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

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

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

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

// the result of the probe
// ENUM: "Success" | "Failure" | "Timeout" | ""
//+kubebuilder:default=""
// +kubebuilder:default=""
Result ProbeResult `json:"result"`

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

Expand Down Expand Up @@ -282,10 +282,10 @@ const (
===============================================================================
*/

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

// Workspace is the Schema for the Workspaces API
type Workspace struct {
Expand Down
14 changes: 7 additions & 7 deletions workspaces/controller/api/v1beta1/workspacekind_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ type WorkspaceKindCullingConfig struct {
MaxInactiveSeconds *int32 `json:"maxInactiveSeconds,omitempty"`

// the maximum number of seconds between probes
//+kubebuilder:validation:Optional
//+kubebuilder:validation:Minimum:=60
//+kubebuilder:default=300
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum:=60
// +kubebuilder:default=300
MaxProbeIntervalSeconds *int32 `json:"maxProbeIntervalSeconds,omitempty"`

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

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

// the number of seconds to wait for the script to complete
Expand Down
5 changes: 3 additions & 2 deletions workspaces/controller/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package main
import (
"crypto/tls"
"flag"
"k8s.io/client-go/kubernetes"
"os"

"k8s.io/client-go/kubernetes"

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

if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&webhookInternal.WorkspaceValidator{
Expand Down
1 change: 0 additions & 1 deletion workspaces/controller/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/moby/spdystream v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down
17 changes: 3 additions & 14 deletions workspaces/controller/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down Expand Up @@ -44,18 +46,12 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af h1:kmjWCqn2qkEml422C2Rrd27c3VGxi6a/6HNq8QmHRKM=
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand All @@ -73,10 +69,7 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/moby/spdystream v0.4.0 h1:Vy79D6mHeJJjiPdFEL2yku1kl0chZpJfZcPpb16BRl8=
github.com/moby/spdystream v0.4.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
Expand All @@ -87,12 +80,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/onsi/ginkgo/v2 v2.14.0 h1:vSmGj2Z5YPb9JwCWT6z6ihcUvDhuXLc3sJiqd3jMKAY=
github.com/onsi/ginkgo/v2 v2.14.0/go.mod h1:JkUdW7JkN0V6rFvsHcJ478egV3XH9NxpD27Hal/PhZw=
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
40 changes: 21 additions & 19 deletions workspaces/controller/internal/controller/culling_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"

"github.com/go-logr/logr"
kubefloworgv1beta1 "github.com/kubeflow/notebooks/workspaces/controller/api/v1beta1"
"github.com/kubeflow/notebooks/workspaces/controller/internal/helper"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -36,16 +42,12 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/utils/ptr"
"net"
"net/http"
"net/url"
"os"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
"strconv"
"strings"
"time"

kubefloworgv1beta1 "github.com/kubeflow/notebooks/workspaces/controller/api/v1beta1"
"github.com/kubeflow/notebooks/workspaces/controller/internal/helper"
)

const (
Expand All @@ -69,7 +71,7 @@ type ActivityProbe struct {

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

func (r *CullingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { // nolint:gocyclo
func (r *CullingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { //nolint:gocyclo
log := log.FromContext(ctx)
log.V(2).Info("reconciling Workspace for culling")
// fetch the Workspace
Expand Down Expand Up @@ -176,7 +178,7 @@ func (r *CullingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
Message: "Failed to fetch service name for workspace",
}, nil, nil)
}
port, err := r.getWorkspacePort(ctx, workspace, workspaceKind)
port, err := r.getWorkspacePort(workspace, workspaceKind)
if err != nil {
log.Error(err, "Error fetching port for workspace")
return r.updateWorkspaceActivityStatus(ctx, log, workspace, &minRequeueAfter, &kubefloworgv1beta1.ProbeStatus{
Expand Down Expand Up @@ -261,7 +263,7 @@ func (r *CullingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
lastActivity := time.Now().Unix()
if activityProbe.HasActivity != nil && !*activityProbe.HasActivity {
log.V(2).Info("Culling the workspace due to inactivity")
//TODO: figure out how to set the last activity time
// TODO: figure out how to set the last activity time
lastActivity = time.Now().Unix()
workspace.Spec.Paused = ptr.To(true)
err := r.Update(ctx, workspace)
Expand Down Expand Up @@ -324,7 +326,7 @@ func (r *CullingReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

// updateWorkspaceActivityStatus attempts to immediately update the Workspace activity status with the provided status.
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
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) {
if workspace == nil {
return ctrl.Result{}, fmt.Errorf("provided Workspace was nil")
}
Expand Down Expand Up @@ -381,7 +383,7 @@ func (r *CullingReconciler) getServiceName(ctx context.Context, workspace *kubef
return ownedServices.Items[0].Name, nil
}

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

executor, err := createExecutor(req.URL(), r.Config)
if err != nil {
return "", "", fmt.Errorf("error creating executor: %v", err)
return "", "", fmt.Errorf("error creating executor: %w", err)
}

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

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

// createExecutor creates a new Executor for the given URL and REST config.
func createExecutor(url *url.URL, config *rest.Config) (remotecommand.Executor, error) {
exec, err := remotecommand.NewSPDYExecutor(config, "POST", url)
func createExecutor(requestUrl *url.URL, config *rest.Config) (remotecommand.Executor, error) {
exec, err := remotecommand.NewSPDYExecutor(config, "POST", requestUrl)
if err != nil {
return nil, err
}
// WebSocketExecutor must be "GET" method as described in RFC 6455 Sec. 4.1 (page 17).
websocketExec, err := remotecommand.NewWebSocketExecutor(config, "GET", url.String())
websocketExec, err := remotecommand.NewWebSocketExecutor(config, "GET", requestUrl.String())
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
/*
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.
*/

package controller

0 comments on commit 838baa5

Please sign in to comment.