Skip to content

Commit

Permalink
Added test cases for scenarios with sericeGroups and MaximumMaxReplic…
Browse files Browse the repository at this point in the history
…asPerGroup
  • Loading branch information
AVSBharadwaj committed Jan 21, 2025
1 parent ad6e8fa commit 343c435
Show file tree
Hide file tree
Showing 3 changed files with 457 additions and 7 deletions.
12 changes: 6 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ type Config struct {
// IstioSidecarProxyDefaultMemory is the default Memory resource request of the istio sidecar proxy (default: 200Mi)
IstioSidecarProxyDefaultMemory string `yaml:"IstioSidecarProxyDefaultMemory"`

// serviceGroups defines a list of service category names.
// ServiceGroups defines a list of service category names.
ServiceGroups []ServiceGroup `yaml:"ServiceGroups"`
// MaximumMaxReplicasPerService is the maximum maxReplicas that tortoise can give to the HPA per service category.
// If the service category is not found in this list, tortoise uses the default value which is the value set in MaximumMaxReplicas.
Expand All @@ -275,7 +275,7 @@ type Config struct {

type MaximumMaxReplicasPerGroup struct {
// ServiceGroupName refers to one ServiceGroup at Config.ServiceGroups
ServiceGroupName *string `yaml:"ServiceGroupName"`
ServiceGroupName string `yaml:"ServiceGroupName"`

MaximumMaxReplica int32 `yaml:"MaximumMaxReplica"`
}
Expand Down Expand Up @@ -390,9 +390,9 @@ func validate(config *Config) error {
}

for _, maxReplicas := range config.MaximumMaxReplicasPerService {
if maxReplicas.ServiceGroupName != nil {
if _, exists := serviceGroupMap[*maxReplicas.ServiceGroupName]; !exists {
return fmt.Errorf("ServiceGroupName %s in MaximumMaxReplicas is not defined in ServiceGroups", *maxReplicas.ServiceGroupName)
if maxReplicas.ServiceGroupName != "" {
if _, exists := serviceGroupMap[maxReplicas.ServiceGroupName]; !exists {
return fmt.Errorf("ServiceGroupName %s in MaximumMaxReplicas is not defined in ServiceGroups", maxReplicas.ServiceGroupName)
}
}
}
Expand All @@ -408,7 +408,7 @@ func validate(config *Config) error {

// Check all entries in MaximumMaxReplicasPerService have non-nil ServiceGroupName
for _, maxReplicas := range config.MaximumMaxReplicasPerService {
if maxReplicas.ServiceGroupName == nil {
if maxReplicas.ServiceGroupName == "" {
return fmt.Errorf("ServiceGroupName should not be nil in MaximumMaxReplicasPerService entries")
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/hpa/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (c *Service) getMaximumMaxReplicasForGroup(groupName string) int32 {

// Look for a specific service group match
for _, group := range c.maximumMaxReplicasPerService {
if group.ServiceGroupName != nil && *group.ServiceGroupName == groupName {
if group.ServiceGroupName != "" && group.ServiceGroupName == groupName {
return group.MaximumMaxReplica
}
}
Expand Down
Loading

0 comments on commit 343c435

Please sign in to comment.