feat: implement replacements
This commit is contained in:
@@ -98,7 +98,7 @@ type FormationAutoscalingTrigger struct {
|
|||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
|
|
||||||
// Metadata is a map of metadata to use for the trigger
|
// Metadata is a map of metadata to use for the trigger
|
||||||
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
Metadata map[string]string `json:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Healthcheck is a struct that represents a single healthcheck from an app.json file
|
// Healthcheck is a struct that represents a single healthcheck from an app.json file
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package scheduler_k3s
|
package scheduler_k3s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
appjson "github.com/dokku/dokku/plugins/app-json"
|
appjson "github.com/dokku/dokku/plugins/app-json"
|
||||||
@@ -442,8 +444,8 @@ func getAnnotations(appName string, processType string) (ProcessAnnotations, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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, processName string, replicas int) (ProcessAutoscaling, error) {
|
func getAutoscaling(appName string, processType string, replicas int) (ProcessAutoscaling, error) {
|
||||||
config, ok, err := appjson.GetAutoscalingConfig(appName, processName, replicas)
|
config, ok, err := appjson.GetAutoscalingConfig(appName, processType, 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", appName, err))
|
||||||
return ProcessAutoscaling{}, err
|
return ProcessAutoscaling{}, err
|
||||||
@@ -454,12 +456,32 @@ func getAutoscaling(appName string, processName string, replicas int) (ProcessAu
|
|||||||
return ProcessAutoscaling{}, nil
|
return ProcessAutoscaling{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replacements := map[string]string{
|
||||||
|
"APP_NAME": appName,
|
||||||
|
"PROCESS_TYPE": processType,
|
||||||
|
"DEPLOYMENT_NAME": fmt.Sprintf("%s-%s", appName, processType),
|
||||||
|
}
|
||||||
|
|
||||||
triggers := []ProcessAutoscalingTrigger{}
|
triggers := []ProcessAutoscalingTrigger{}
|
||||||
for _, trigger := range config.Triggers {
|
for _, trigger := range config.Triggers {
|
||||||
|
metadata := map[string]string{}
|
||||||
|
for key, value := range trigger.Metadata {
|
||||||
|
tmpl, err := template.New("").Delims("[[", "]]").Parse(value)
|
||||||
|
if err != nil {
|
||||||
|
return ProcessAutoscaling{}, fmt.Errorf("Error parsing autoscaling trigger metadata: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var output bytes.Buffer
|
||||||
|
if err := tmpl.Execute(&output, replacements); err != nil {
|
||||||
|
return ProcessAutoscaling{}, fmt.Errorf("Error executing autoscaling trigger metadata template: %w", err)
|
||||||
|
}
|
||||||
|
metadata[key] = output.String()
|
||||||
|
}
|
||||||
|
|
||||||
triggers = append(triggers, ProcessAutoscalingTrigger{
|
triggers = append(triggers, ProcessAutoscalingTrigger{
|
||||||
Name: trigger.Name,
|
Name: trigger.Name,
|
||||||
Type: trigger.Type,
|
Type: trigger.Type,
|
||||||
Metadata: trigger.Metadata,
|
Metadata: metadata,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ type ProcessAutoscalingTrigger struct {
|
|||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
|
|
||||||
// Metadata is a map of key-value pairs that can be used to store arbitrary trigger data
|
// Metadata is a map of key-value pairs that can be used to store arbitrary trigger data
|
||||||
Metadata map[string]interface{} `yaml:"metadata,omitempty"`
|
Metadata map[string]string `yaml:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProcessHealthchecks struct {
|
type ProcessHealthchecks struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user