Repository: kubernetes/kubernetes
File: pkg/scheduler/backend/workloadmanager/podgroupstate.go (Go)

Code before:
	"k8s.io/apimachinery/pkg/types"
	"k8s.io/apimachinery/pkg/util/sets"
	"k8s.io/klog/v2"
	"k8s.io/utils/ptr"
)

// DefaultSchedulingTimeoutDuration defines how long the gang pods should wait at the
// Permit stage for a quorum before being rejected.
// Variable is exported only for testing purposes.
var DefaultSchedulingTimeoutDuration = 5 * time.Minute

// podGroupKey uniquely identifies a specific instance of a PodGroup.
type podGroupKey struct {
	namespace    string
	workloadName string
	podGroupName string
	replicaKey   string
}

func (pgk podGroupKey) GetName() string {
	return pgk.podGroupName
}

func (pgk podGroupKey) GetNamespace() string {
	return pgk.namespace
}

var _ klog.KMetadata = &podGroupKey{}

func newPodGroupKey(namespace string, workloadRef *v1.WorkloadReference) podGroupKey {
	return podGroupKey{
		namespace:    namespace,
		workloadName: workloadRef.Name,
		podGroupName: workloadRef.PodGroup,
		replicaKey:   workloadRef.PodGroupReplicaKey,
	}
}

// podGroupState holds the runtime state of a pod group.
type podGroupState struct {
	lock sync.RWMutex
	// allPods tracks all pods belonging to the group that are known to the scheduler.
	allPods map[types.UID]*v1.Pod
	// unscheduledPods tracks all pods that are unscheduled for this group,
	// i.e., are neither assumed nor scheduled.
	unscheduledPods sets.Set[types.UID]
	// assumedPods tracks pods that have reached the Reserve stage and are waiting
	// for the rest of the gang to arrive before being allowed to bind.
	assumedPods sets.Set[types.UID]
	// assignedPods tracks all pods belonging to the group that are assigned (bound).
	assignedPods sets.Set[types.UID]

Review comment (suggestion):
Name should contain other data as well, e.g.
```suggestion
func (pgk podGroupKey) GetName() string {
    if pgk.replicaKey == "" {
        return fmt.Sprintf("%s-%s", pgk.workloadName, pgk.podGroupName)
    }
	return fmt.Sprintf("%s-%s-%s", pgk.workloadName, pgk.podGroupName, pgk.replicaKey)
}
```

Code after:
	v1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/types"
	"k8s.io/apimachinery/pkg/util/sets"
	"k8s.io/klog/v2"
	"k8s.io/utils/ptr"
)

// DefaultSchedulingTimeoutDuration defines how long the gang pods should wait at the
// Permit stage for a quorum before being rejected.
// Variable is exported only for testing purposes.
var DefaultSchedulingTimeoutDuration = 5 * time.Minute

// podGroupKey uniquely identifies a specific instance of a PodGroup.
type podGroupKey struct {
	namespace    string
	workloadName string
	podGroupName string
	replicaKey   string
}

func (pgk podGroupKey) GetName() string {
	if pgk.replicaKey == "" {
		return fmt.Sprintf("%s-%s", pgk.workloadName, pgk.podGroupName)
	}
	return fmt.Sprintf("%s-%s-%s", pgk.workloadName, pgk.podGroupName, pgk.replicaKey)
}

func (pgk podGroupKey) GetNamespace() string {
	return pgk.namespace
}

var _ klog.KMetadata = &podGroupKey{}

func newPodGroupKey(namespace string, workloadRef *v1.WorkloadReference) podGroupKey {
	return podGroupKey{
		namespace:    namespace,
		workloadName: workloadRef.Name,
		podGroupName: workloadRef.PodGroup,
		replicaKey:   workloadRef.PodGroupReplicaKey,
	}
}

// podGroupState holds the runtime state of a pod group.
type podGroupState struct {
	lock sync.RWMutex
	// allPods tracks all pods belonging to the group that are known to the scheduler.
	allPods map[types.UID]*v1.Pod
	// unscheduledPods tracks all pods that are unscheduled for this group,
	// i.e., are neither assumed nor scheduled.
	unscheduledPods sets.Set[types.UID]
	// assumedPods tracks pods that have reached the Reserve stage and are waiting