Skip to content

Commit 6e7b85a

Browse files
committed
Resolve pre-commit linting errors
- Remove unused context assignment in config_merge_test.go - Fix empty branch in scheduler.go with explicit error ignore - Remove unnecessary string conversions for Condition types - Fix error handling in deleteAlpha2* functions to properly check IsNotFound - Auto-format code with go fmt (config_merge.go, openapi_generated.go) Signed-off-by: Killian Golds <[email protected]> rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED
1 parent 254f381 commit 6e7b85a

File tree

4 files changed

+39
-47
lines changed

4 files changed

+39
-47
lines changed

pkg/controller/llmisvc/config_merge.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,28 +144,28 @@ func (r *LLMInferenceServiceReconciler) combineBaseRefsConfig(ctx context.Contex
144144
}
145145

146146
if llmSvcCfg.Spec.Router != nil &&
147-
llmSvcCfg.Spec.Router.Scheduler != nil &&
148-
llmSvcCfg.Spec.Router.Scheduler.Pool != nil &&
149-
llmSvcCfg.Spec.Router.Scheduler.Pool.Spec != nil {
150-
// Start with any existing matchLabels (typed in v1).
151-
dst := make(map[igwv1.LabelKey]igwv1.LabelValue, len(llmSvcCfg.Spec.Router.Scheduler.Pool.Spec.Selector.MatchLabels))
152-
for k, v := range llmSvcCfg.Spec.Router.Scheduler.Pool.Spec.Selector.MatchLabels {
153-
dst[k] = v
154-
}
147+
llmSvcCfg.Spec.Router.Scheduler != nil &&
148+
llmSvcCfg.Spec.Router.Scheduler.Pool != nil &&
149+
llmSvcCfg.Spec.Router.Scheduler.Pool.Spec != nil {
150+
// Start with any existing matchLabels (typed in v1).
151+
dst := make(map[igwv1.LabelKey]igwv1.LabelValue, len(llmSvcCfg.Spec.Router.Scheduler.Pool.Spec.Selector.MatchLabels))
152+
for k, v := range llmSvcCfg.Spec.Router.Scheduler.Pool.Spec.Selector.MatchLabels {
153+
dst[k] = v
154+
}
155155

156-
// Merge in the controller's workload labels (plain strings) as typed keys/values.
157-
// GetWorkloadLabelSelector returns map[string]string.
158-
if extra := GetWorkloadLabelSelector(llmSvc.ObjectMeta, &llmSvcCfg.Spec); len(extra) > 0 {
159-
for k, v := range extra {
160-
dst[igwv1.LabelKey(k)] = igwv1.LabelValue(v)
156+
// Merge in the controller's workload labels (plain strings) as typed keys/values.
157+
// GetWorkloadLabelSelector returns map[string]string.
158+
if extra := GetWorkloadLabelSelector(llmSvc.ObjectMeta, &llmSvcCfg.Spec); len(extra) > 0 {
159+
for k, v := range extra {
160+
dst[igwv1.LabelKey(k)] = igwv1.LabelValue(v)
161+
}
161162
}
162-
}
163163

164-
// v1 uses igwv1.LabelSelector{ MatchLabels map[LabelKey]LabelValue } (typed), not map[string]string.
165-
llmSvcCfg.Spec.Router.Scheduler.Pool.Spec.Selector = igwv1.LabelSelector{
166-
MatchLabels: dst,
164+
// v1 uses igwv1.LabelSelector{ MatchLabels map[LabelKey]LabelValue } (typed), not map[string]string.
165+
llmSvcCfg.Spec.Router.Scheduler.Pool.Spec.Selector = igwv1.LabelSelector{
166+
MatchLabels: dst,
167+
}
167168
}
168-
}
169169

170170
if llmSvcCfg.Spec.Router != nil &&
171171
llmSvcCfg.Spec.Router.Scheduler != nil &&

pkg/controller/llmisvc/config_merge_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"testing"
2121

2222
. "github.com/onsi/gomega"
23-
"sigs.k8s.io/controller-runtime/pkg/log"
2423
"sigs.k8s.io/yaml"
2524

2625
ktesting "github.com/kserve/kserve/pkg/testing"
@@ -37,7 +36,6 @@ import (
3736
gatewayapi "sigs.k8s.io/gateway-api/apis/v1"
3837

3938
"github.com/kserve/kserve/pkg/apis/serving/v1alpha1"
40-
pkgtest "github.com/kserve/kserve/pkg/testing"
4139
)
4240

4341
func TestMergeSpecs(t *testing.T) {
@@ -1310,9 +1308,7 @@ func TestMergeSpecs(t *testing.T) {
13101308
}
13111309
for _, tt := range tests {
13121310
t.Run(tt.name, func(t *testing.T) {
1313-
ctx := t.Context()
1314-
ctx = log.IntoContext(ctx, pkgtest.NewTestLogger(t))
1315-
1311+
// Remove unused context assignment - MergeSpecs doesn't need context
13161312
got, err := llmisvc.MergeSpecs(tt.cfgs...)
13171313
if (err != nil) != tt.wantErr {
13181314
t.Errorf("MergeSpecs() error = %v, wantErr %v", err, tt.wantErr)

pkg/controller/llmisvc/scheduler.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ func (r *LLMInferenceServiceReconciler) reconcileSchedulerInferencePool(ctx cont
187187

188188
// Fetch current v1 to read Status (expected has no Status).
189189
cur := &igwv1.InferencePool{}
190-
if err := r.Client.Get(ctx, crclient.ObjectKey{
190+
// Intentionally ignore error - if v1 pool doesn't exist or can't be fetched,
191+
// cur remains empty and isV1PoolReady will return false, allowing fallback to alpha2
192+
_ = r.Client.Get(ctx, crclient.ObjectKey{
191193
Namespace: expected.Namespace,
192-
Name: expected.Name,
193-
}, cur); err != nil {
194-
// If we can't fetch v1, treat v1 as not ready and rely on alpha2 below.
195-
}
194+
Name: expected.Name,
195+
}, cur)
196196

197197
v1Ready := isV1PoolReady(cur)
198198
alpha2Ready := r.isAlpha2PoolReady(ctx, llmSvc.GetNamespace(), expected.GetName())
@@ -662,10 +662,11 @@ func isV1PoolReady(p *igwv1.InferencePool) bool {
662662
for _, ps := range p.Status.Parents {
663663
accepted, resolved := false, false
664664
for _, c := range ps.Conditions {
665-
if string(c.Type) == "Accepted" && string(c.Status) == "True" {
665+
// c.Type is string, c.Status is ConditionStatus (string alias) - no conversion needed
666+
if c.Type == "Accepted" && c.Status == "True" {
666667
accepted = true
667668
}
668-
if string(c.Type) == "ResolvedRefs" && string(c.Status) == "True" {
669+
if c.Type == "ResolvedRefs" && c.Status == "True" {
669670
resolved = true
670671
}
671672
}
@@ -935,7 +936,12 @@ func (r *LLMInferenceServiceReconciler) deleteAlpha2PoolIfExists(ctx context.Con
935936
res := r.DynamicClient.Resource(GVRInferencePoolV1Alpha2).Namespace(llmSvc.Namespace)
936937
_, err := res.Get(ctx, name, metav1.GetOptions{})
937938
if err != nil {
938-
return nil // nothing to delete or not found
939+
// If resource doesn't exist (NotFound), that's fine - nothing to delete
940+
if apierrors.IsNotFound(err) {
941+
return nil
942+
}
943+
// For other errors, propagate them
944+
return err
939945
}
940946
return res.Delete(ctx, name, metav1.DeleteOptions{})
941947
}
@@ -945,7 +951,12 @@ func (r *LLMInferenceServiceReconciler) deleteAlpha2InferenceModelIfExists(ctx c
945951
res := r.DynamicClient.Resource(GVRInferenceModelV1Alpha2).Namespace(llmSvc.Namespace)
946952
_, err := res.Get(ctx, name, metav1.GetOptions{})
947953
if err != nil {
948-
return nil // not found or not installed so ignore
954+
// If resource doesn't exist (NotFound) or CRD not installed, that's fine
955+
if apierrors.IsNotFound(err) {
956+
return nil
957+
}
958+
// For other errors, propagate them
959+
return err
949960
}
950961
return res.Delete(ctx, name, metav1.DeleteOptions{})
951962
}

pkg/openapi/openapi_generated.go

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)