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
6 changes: 6 additions & 0 deletions .changes/unreleased/changed-20261012-121128.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Changed
body: |-
PodGroup webhook logs validate update at verbosity 4 instead of the default level
custom:
Author: "sam-huang1223"
Issue: "24"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/kai-scheduler/api
go 1.26.3

require (
github.com/go-logr/logr v1.4.3
github.com/onsi/ginkgo/v2 v2.28.1
github.com/onsi/gomega v1.39.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.88.0
Expand All @@ -27,7 +28,6 @@ require (
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-openapi/jsonpointer v0.21.2 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
Expand Down
2 changes: 1 addition & 1 deletion scheduling/v2alpha2/podgroup_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (_ *PodGroup) ValidateCreate(ctx context.Context, podGroup *PodGroup) (admi
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (_ *PodGroup) ValidateUpdate(ctx context.Context, oldPodGroup *PodGroup, podGroup *PodGroup) (admission.Warnings, error) {
logger := log.FromContext(ctx)
logger.Info("validate update", "namespace", podGroup.Namespace, "name", podGroup.Name)
logger.V(4).Info("validate update", "namespace", podGroup.Namespace, "name", podGroup.Name)

validationErrors := validatePodGroupSpec(&podGroup.Spec)

Expand Down
32 changes: 32 additions & 0 deletions scheduling/v2alpha2/podgroup_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"strings"
"testing"

"github.com/go-logr/logr/funcr"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/log"
)

func TestValidateSubGroups(t *testing.T) {
Expand Down Expand Up @@ -536,3 +538,33 @@ func errorsListEqual(want, got []error) bool {
}
return true
}

func TestValidateUpdateLogsAboveDefaultVerbosity(t *testing.T) {
for _, tt := range []struct {
verbosity int
wantLog bool
}{
{verbosity: 3, wantLog: false},
{verbosity: 4, wantLog: true},
} {
var logs strings.Builder
ctx := log.IntoContext(context.Background(), funcr.New(func(_, args string) {
logs.WriteString(args + "\n")
}, funcr.Options{Verbosity: tt.verbosity}))
podGroup := &PodGroup{}

if _, err := podGroup.ValidateUpdate(ctx, podGroup, podGroup); err != nil {
t.Fatalf("ValidateUpdate() error = %v", err)
}
if got := strings.Contains(logs.String(), "validate update"); got != tt.wantLog {
t.Errorf("verbosity %d: logged validate update = %v, want %v", tt.verbosity, got, tt.wantLog)
}

if _, err := podGroup.ValidateCreate(ctx, podGroup); err != nil {
t.Fatalf("ValidateCreate() error = %v", err)
}
if !strings.Contains(logs.String(), "validate create") {
t.Errorf("verbosity %d: validate create was not logged", tt.verbosity)
}
}
}