feat: associate matching authentication info to a given autoscaler

This commit is contained in:
Jose Diaz-Gonzalez
2024-02-27 23:09:39 -05:00
parent b3b3a93789
commit f23cdffe49
2 changed files with 38 additions and 10 deletions

View File

@@ -456,23 +456,38 @@ func getAnnotations(appName string, processType string) (ProcessAnnotations, err
return annotations, nil return annotations, nil
} }
// GetAutoscalingInput contains all the information needed to get autoscaling config
type GetAutoscalingInput struct {
// AppName is the name of the app
AppName string
// ProcessType is the process type
ProcessType string
// Replicas is the number of replicas
Replicas int
// KedaValues is the keda values
KedaValues GlobalKedaValues
}
// getAutoscaling retrieves autoscaling config for a given app and process type // getAutoscaling retrieves autoscaling config for a given app and process type
func getAutoscaling(appName string, processType string, replicas int) (ProcessAutoscaling, error) { func getAutoscaling(input GetAutoscalingInput) (ProcessAutoscaling, error) {
config, ok, err := appjson.GetAutoscalingConfig(appName, processType, replicas) config, ok, err := appjson.GetAutoscalingConfig(input.AppName, input.ProcessType, input.Replicas)
if err != nil { if err != nil {
common.LogWarn(fmt.Sprintf("Error getting autoscaling config for %s: %v", appName, err)) common.LogWarn(fmt.Sprintf("Error getting autoscaling config for %s: %v", input.AppName, err))
return ProcessAutoscaling{}, err return ProcessAutoscaling{}, err
} }
if !ok { if !ok {
common.LogWarn(fmt.Sprintf("No autoscaling config found for %s", appName)) common.LogWarn(fmt.Sprintf("No autoscaling config found for %s", input.AppName))
return ProcessAutoscaling{}, nil return ProcessAutoscaling{}, nil
} }
replacements := map[string]string{ replacements := map[string]string{
"APP_NAME": appName, "APP_NAME": input.AppName,
"PROCESS_TYPE": processType, "PROCESS_TYPE": input.ProcessType,
"DEPLOYMENT_NAME": fmt.Sprintf("%s-%s", appName, processType), "DEPLOYMENT_NAME": fmt.Sprintf("%s-%s", input.AppName, input.ProcessType),
} }
triggers := []ProcessAutoscalingTrigger{} triggers := []ProcessAutoscalingTrigger{}
@@ -491,11 +506,19 @@ func getAutoscaling(appName string, processType string, replicas int) (ProcessAu
metadata[key] = output.String() metadata[key] = output.String()
} }
triggers = append(triggers, ProcessAutoscalingTrigger{ trigger := ProcessAutoscalingTrigger{
Name: trigger.Name, Name: trigger.Name,
Type: trigger.Type, Type: trigger.Type,
Metadata: metadata, Metadata: metadata,
}) }
if _, ok := input.KedaValues.Authentications[trigger.Type]; ok {
trigger.AuthenticationRef = &ProcessAutoscalingTriggerAuthenticationRef{
Name: fmt.Sprintf("%s-%s", input.AppName, trigger.Type),
}
}
triggers = append(triggers, trigger)
} }
autoscaling := ProcessAutoscaling{ autoscaling := ProcessAutoscaling{

View File

@@ -354,7 +354,12 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
return fmt.Errorf("Error getting process labels: %w", err) return fmt.Errorf("Error getting process labels: %w", err)
} }
autoscaling, err := getAutoscaling(appName, processType, int(processCount)) autoscaling, err := getAutoscaling(GetAutoscalingInput{
AppName: appName,
ProcessType: processType,
Replicas: int(processCount),
KedaValues: kedaValues,
})
if err != nil { if err != nil {
return fmt.Errorf("Error getting autoscaling: %w", err) return fmt.Errorf("Error getting autoscaling: %w", err)
} }