Repository: kubernetes-sigs/kueue (Go)

Issue:
Implement generic strings Join util
<!-- Please only use this template for submitting clean up requests -->

**What would you like to be cleaned**:

I would like to implement a generic string `Join` util in https://github.com/kubernetes-sigs/kueue/tree/main/pkg/util/strings

```go
func Join[S ~string](a S, sep string) S { ... }
```

This has the same functionality with Go stdlib `strings.Join`, but this allows us to use strings type alias.

**Why is this needed**:

We have a lot of strings type alias and join those for messaging like:

- https://github.com/kubernetes-sigs/kueue/blob/b90208f86e490ef499bcfcc6d0b1242f5d880fae/pkg/config/validation.go#L277
- https://github.com/kubernetes-sigs/kueue/blob/04bee0db4000b298656c42a1ec44493e49bab5c8/pkg/cache/clusterqueue.go#L255

So, we want to generalize those.


Discussion: /assign



Fix (patch):
diff --git a/pkg/cache/clusterqueue.go b/pkg/cache/clusterqueue.go
index c571f5341ce..925051de79f 100644
--- a/pkg/cache/clusterqueue.go
+++ b/pkg/cache/clusterqueue.go
@@ -229,15 +229,15 @@ func (c *clusterQueue) inactiveReason() (string, string) {
 		}
 		if len(c.missingFlavors) > 0 {
 			reasons = append(reasons, kueue.ClusterQueueActiveReasonFlavorNotFound)
-			messages = append(messages, fmt.Sprintf("references missing ResourceFlavor(s): %v", c.missingFlavors))
+			messages = append(messages, fmt.Sprintf("references missing ResourceFlavor(s): %v", stringsutils.Join(c.missingFlavors, ",")))
 		}
 		if len(c.missingAdmissionChecks) > 0 {
 			reasons = append(reasons, kueue.ClusterQueueActiveReasonAdmissionCheckNotFound)
-			messages = append(messages, fmt.Sprintf("references missing AdmissionCheck(s): %v", c.missingAdmissionChecks))
+			messages = append(messages, fmt.Sprintf("references missing AdmissionCheck(s): %v", stringsutils.Join(c.missingAdmissionChecks, ",")))
 		}
 		if len(c.inactiveAdmissionChecks) > 0 {
 			reasons = append(reasons, kueue.ClusterQueueActiveReasonAdmissionCheckInactive)
-			messages = append(messages, fmt.Sprintf("references inactive AdmissionCheck(s): %v", c.inactiveAdmissionChecks))
+			messages = append(messages, fmt.Sprintf("references inactive AdmissionCheck(s): %v", stringsutils.Join(c.inactiveAdmissionChecks, ",")))
 		}
 
 		if len(c.multiKueueAdmissionChecks) > 1 {
@@ -271,7 +271,7 @@ func (c *clusterQueue) inactiveReason() (string, string) {
 			return kueue.ClusterQueueActiveReasonUnknown, "Can't admit new workloads."
 		}
 
-		return reasons[0], api.TruncateConditionMessage(strings.Join([]string{"Can't admit new workloads: ", strings.Join(messages, ", "), "."}, ""))
+		return reasons[0], api.TruncateConditionMessage(fmt.Sprintf("Can't admit new workloads: %v.", strings.Join(messages, ", ")))
 	}
 	return kueue.ClusterQueueActiveReasonReady, "Can admit new workloads"
 }
diff --git a/pkg/config/validation.go b/pkg/config/validation.go
index b4f0fab4e47..9637f6d545e 100644
--- a/pkg/config/validation.go
+++ b/pkg/config/validation.go
@@ -21,7 +21,6 @@ import (
 	"fmt"
 	"slices"
 	"strings"
-	"unsafe"
 
 	corev1 "k8s.io/api/core/v1"
 	apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation"
@@ -40,6 +39,7 @@ import (
 	"sigs.k8s.io/kueue/pkg/controller/jobframework"
 	podworkload "sigs.k8s.io/kueue/pkg/controller/jobs/pod"
 	"sigs.k8s.io/kueue/pkg/features"
+	stringsutils "sigs.k8s.io/kueue/pkg/util/strings"
 )
 
 const (
@@ -272,9 +272,7 @@ var (
 	validStrategySetsStr = func() []string {
 		var ss []string
 		for _, s := range validStrategySets {
-			// Casting because strings.Join requires a slice of strings
-			strategies := *(*[]string)(unsafe.Pointer(&s))
-			ss = append(ss, strings.Join(strategies, ","))
+			ss = append(ss, stringsutils.Join(s, ","))
 		}
 		return ss
 	}()
diff --git a/pkg/controller/core/workload_controller.go b/pkg/controller/core/workload_controller.go
index a230655b8bc..2799c6cc471 100644
--- a/pkg/controller/core/workload_controller.go
+++ b/pkg/controller/core/workload_controller.go
@@ -56,6 +56,7 @@ import (
 	"sigs.k8s.io/kueue/pkg/queue"
 	"sigs.k8s.io/kueue/pkg/util/admissioncheck"
 	utilslices "sigs.k8s.io/kueue/pkg/util/slices"
+	stringsutils "sigs.k8s.io/kueue/pkg/util/strings"
 	"sigs.k8s.io/kueue/pkg/workload"
 )
 
@@ -385,7 +386,7 @@ func (r *WorkloadReconciler) reconcileCheckBasedEviction(ctx context.Context, wl
 		for _, check := range workload.RejectedChecks(wl) {
 			rejectedCheckNames = append(rejectedCheckNames, check.Name)
 		}
-		workload.SetDeactivationTarget(wl, kueue.WorkloadEvictedByAdmissionCheck, fmt.Sprintf("Admission check(s): %v, were rejected", rejectedCheckNames))
+		workload.SetDeactivationTarget(wl, kueue.WorkloadEvictedByAdmissionCheck, fmt.Sprintf("Admission check(s): %v, were rejected", stringsutils.Join(rejectedCheckNames, ",")))
 		if err := workload.ApplyAdmissionStatus(ctx, r.client, wl, true, r.clock); err != nil {
 			return false, client.IgnoreNotFound(err)
 		}