Skip to content

Commit 00134fe

Browse files
committed
Added test cases for scenarios with sericeGroups and MaximumMaxReplicasPerGroup
1 parent e93ac1b commit 00134fe

File tree

3 files changed

+457
-7
lines changed

3 files changed

+457
-7
lines changed

pkg/config/config.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ type Config struct {
262262
// IstioSidecarProxyDefaultMemory is the default Memory resource request of the istio sidecar proxy (default: 200Mi)
263263
IstioSidecarProxyDefaultMemory string `yaml:"IstioSidecarProxyDefaultMemory"`
264264

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

276276
type MaximumMaxReplicasPerGroup struct {
277277
// ServiceGroupName refers to one ServiceGroup at Config.ServiceGroups
278-
ServiceGroupName *string `yaml:"ServiceGroupName"`
278+
ServiceGroupName string `yaml:"ServiceGroupName"`
279279

280280
MaximumMaxReplica int32 `yaml:"MaximumMaxReplica"`
281281
}
@@ -390,9 +390,9 @@ func validate(config *Config) error {
390390
}
391391

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

409409
// Check all entries in MaximumMaxReplicasPerService have non-nil ServiceGroupName
410410
for _, maxReplicas := range config.MaximumMaxReplicasPerService {
411-
if maxReplicas.ServiceGroupName == nil {
411+
if maxReplicas.ServiceGroupName == "" {
412412
return fmt.Errorf("ServiceGroupName should not be nil in MaximumMaxReplicasPerService entries")
413413
}
414414
}

pkg/hpa/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (c *Service) getMaximumMaxReplicasForGroup(groupName string) int32 {
312312

313313
// Look for a specific service group match
314314
for _, group := range c.maximumMaxReplicasPerService {
315-
if group.ServiceGroupName != nil && *group.ServiceGroupName == groupName {
315+
if group.ServiceGroupName != "" && group.ServiceGroupName == groupName {
316316
return group.MaximumMaxReplica
317317
}
318318
}

0 commit comments

Comments
 (0)