refactor: use const for prefix

This commit is contained in:
Jose Diaz-Gonzalez committed 2024-03-06 03:39:11 -05:00
1 parent 3bd61d8c7f
commit 14f0e2fb72
3 files changed
+5 -4

No files matched your search

+2 -2
View File
@@ -536,14 +536,14 @@ func getAutoscaling(input GetAutoscalingInput) (ProcessAutoscaling, error) {
// getKedaValues retrieves keda values for a given app and process type // getKedaValues retrieves keda values for a given app and process type
func getKedaValues(appName string) (GlobalKedaValues, error) { func getKedaValues(appName string) (GlobalKedaValues, error) {
properties, err := common.PropertyGetAllByPrefix("scheduler-k3s", appName, "trigger-auth-") properties, err := common.PropertyGetAllByPrefix("scheduler-k3s", appName, TriggerAuthPropertyPrefix)
if err != nil { if err != nil {
return GlobalKedaValues{}, fmt.Errorf("Error getting trigger-auth properties: %w", err) return GlobalKedaValues{}, fmt.Errorf("Error getting trigger-auth properties: %w", err)
} }
auths := map[string]KedaAuthentication{} auths := map[string]KedaAuthentication{}
for key, value := range properties { for key, value := range properties {
parts := strings.SplitN(strings.TrimPrefix(key, "trigger-auth-"), ":", 2) parts := strings.SplitN(strings.TrimPrefix(key, TriggerAuthPropertyPrefix), ".", 2)
if len(parts) != 2 { if len(parts) != 2 {
return GlobalKedaValues{}, fmt.Errorf("Invalid trigger-auth property format: %s", key) return GlobalKedaValues{}, fmt.Errorf("Invalid trigger-auth property format: %s", key)
} }
+1
View File
@@ -45,6 +45,7 @@ const DefaultIngressClass = "traefik"
const GlobalProcessType = "--global" const GlobalProcessType = "--global"
const KubeConfigPath = "/etc/rancher/k3s/k3s.yaml" const KubeConfigPath = "/etc/rancher/k3s/k3s.yaml"
const DefaultKubeContext = "" const DefaultKubeContext = ""
const TriggerAuthPropertyPrefix = "trigger-auth."
var ( var (
runtimeScheme = runtime.NewScheme() runtimeScheme = runtime.NewScheme()
+2 -2
View File
@@ -65,7 +65,7 @@ func CommandAutoscalingAuthSet(appName string, trigger string, metadata map[stri
} }
if len(metadata) == 0 { if len(metadata) == 0 {
properties, err := common.PropertyGetAllByPrefix("scheduler-k3s", appName, fmt.Sprintf("trigger-auth.%s.", trigger)) properties, err := common.PropertyGetAllByPrefix("scheduler-k3s", appName, fmt.Sprintf("%s%s.", TriggerAuthPropertyPrefix, trigger))
if err != nil { if err != nil {
return fmt.Errorf("Unable to get property list: %w", err) return fmt.Errorf("Unable to get property list: %w", err)
} }
@@ -79,7 +79,7 @@ func CommandAutoscalingAuthSet(appName string, trigger string, metadata map[stri
} }
for key, value := range metadata { for key, value := range metadata {
if err := common.PropertyWrite("scheduler-k3s", appName, fmt.Sprintf("trigger-auth.%s.%s", trigger, key), value); err != nil { if err := common.PropertyWrite("scheduler-k3s", appName, fmt.Sprintf("%s%s.%s", TriggerAuthPropertyPrefix, trigger, key), value); err != nil {
return fmt.Errorf("Unable to set property: %w", err) return fmt.Errorf("Unable to set property: %w", err)
} }
} }