Skip to content

Commit ad6e8fa

Browse files
committed
Field name change from Namespace to Selectors
1 parent 293306a commit ad6e8fa

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

pkg/config/config.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,24 +275,23 @@ type Config struct {
275275

276276
type MaximumMaxReplicasPerGroup struct {
277277
// ServiceGroupName refers to one ServiceGroup at Config.ServiceGroups
278-
// If nil, this MaximumMaxReplica would apply to all services.
279278
ServiceGroupName *string `yaml:"ServiceGroupName"`
280279

281280
MaximumMaxReplica int32 `yaml:"MaximumMaxReplica"`
282281
}
283282

284-
// Namespace represents a Kubernetes namespace and its associated label selectors.
285-
type Namespace struct {
286-
Name string `yaml:"name"` // Namespace name
287-
LabelSelectors []*metav1.LabelSelector `yaml:"labelSelectors"` // Slice of label selectors within this namespace
283+
// Selector selects a group of pods by matching its namespace and labels.
284+
type Selector struct {
285+
Namespace string `yaml:"Namespace"` // Namespace name
286+
LabelSelectors []*metav1.LabelSelector `yaml:"Labels,omitempty"` // Slice of label selectors within this namespace
288287
}
289288

290289
// ServiceGroup represents a collection of services grouped together with namespace awareness.
291290
type ServiceGroup struct {
292291
// Name is the group's name (e.g., big-service, fintech-service, etc).
293-
Name string `yaml:"name"`
294-
// Namespaces represent multiple namespaces with their label selectors.
295-
Namespaces []Namespace `yaml:"namespaces"` // A slice of Namespace structs
292+
Name string `yaml:"Name"`
293+
// Selectors represent multiple pod groups that belong to this ServiceGroup.
294+
Selectors []Selector `yaml:"Selectors"` // Slice of namespaces and labels within this service group
296295
}
297296

298297
func defaultConfig() *Config {
@@ -402,11 +401,18 @@ func validate(config *Config) error {
402401
seenServiceGroups := make(map[string]bool)
403402
for _, sg := range config.ServiceGroups {
404403
if seenServiceGroups[sg.Name] {
405-
return fmt.Errorf("Duplicate ServiceGroupName found: %s", sg.Name)
404+
return fmt.Errorf("duplicate ServiceGroupName found: %s", sg.Name)
406405
}
407406
seenServiceGroups[sg.Name] = true
408407
}
409408

409+
// Check all entries in MaximumMaxReplicasPerService have non-nil ServiceGroupName
410+
for _, maxReplicas := range config.MaximumMaxReplicasPerService {
411+
if maxReplicas.ServiceGroupName == nil {
412+
return fmt.Errorf("ServiceGroupName should not be nil in MaximumMaxReplicasPerService entries")
413+
}
414+
}
415+
410416
if config.MaximumMinReplicas > minOfMaximumMaxReplicas {
411417
return fmt.Errorf("MaximumMinReplicas should be less than or equal to MaximumMaxReplicas")
412418
}

pkg/hpa/service.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,16 @@ var globalRecommendedHPABehavior = &v2.HorizontalPodAutoscalerBehavior{
246246
},
247247
}
248248

249-
// Determine which service group is applicable for a given Tortoise using its namespace.
249+
// Determine which service group is applicable for a given Tortoise using its selectors.
250250
func (c *Service) determineServiceGroup(tortoise *autoscalingv1beta3.Tortoise) string {
251251
tortoiseNamespace := tortoise.Namespace
252252
for _, serviceGroup := range c.serviceGroups {
253-
for _, namespace := range serviceGroup.Namespaces {
254-
if namespace.Name == tortoiseNamespace {
253+
for _, selector := range serviceGroup.Selectors {
254+
if selector.Namespace == tortoiseNamespace {
255255
klog.InfoS("Namespace matched", "serviceGroup", serviceGroup.Name, "namespace", tortoiseNamespace)
256256
return serviceGroup.Name
257257
}
258+
// TODO(avs): Add logic for matching labels in the future.
258259
}
259260
}
260261
// Returning an empty string to denote a default value when no match.

0 commit comments

Comments
 (0)