mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
The fork was already ours everywhere that matters — our image, our IAM (dex is not deployed), hanzo kv behind what the env still called REDIS. Only the vocabulary was upstream's: ARGOCD_* across the Go, the manifests, the docs and the plugin contract, and mkdocs still titled 'Argo CD' pointing at argoproj/argo-cd. ARGOCD_ -> CD_ and REDIS_ -> KV_ across 345 files, plus the 8 e2e/cmp fixtures that assert the plugin env contract — those had to move with the binary, which now emits CD_APP_NAME where they expected ARGOCD_APP_NAME. Left alone deliberately, because renaming them would be wrong: - util/helm/testdata/redis/ and gitops-engine/.../statefulset*.yaml are fixtures for a THIRD-PARTY chart named redis, not our config - util/kustomize/testdata/ likewise - generated.proto regenerates from types.go, which is already clean go build ./... exit 0. LOCKSTEP: the live StatefulSet sets 47 ARGOCD_* names the binary no longer reads. universe 4a5375735 carries the matching manifest change; they deploy together or the controller falls back to defaults. Co-authored-by: Hanzo Dev <[email protected]>
105 lines
1.8 KiB
Go
105 lines
1.8 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/csv"
|
|
"errors"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/kballard/go-shellquote"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var flags map[string]string
|
|
|
|
func init() {
|
|
err := LoadFlags()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func LoadFlags() error {
|
|
flags = make(map[string]string)
|
|
|
|
opts, err := shellquote.Split(os.Getenv("CD_OPTS"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var key string
|
|
for _, opt := range opts {
|
|
switch {
|
|
case strings.HasPrefix(opt, "--"):
|
|
if key != "" {
|
|
flags[key] = "true"
|
|
}
|
|
key = strings.TrimPrefix(opt, "--")
|
|
case key != "":
|
|
flags[key] = opt
|
|
key = ""
|
|
default:
|
|
return errors.New("CD_OPTS invalid at '" + opt + "'")
|
|
}
|
|
}
|
|
if key != "" {
|
|
flags[key] = "true"
|
|
}
|
|
// pkg shellquota doesn't recognize `=` so that the opts in format `foo=bar` could not work.
|
|
// issue ref: https://github.com/argoproj/argo-cd/issues/6822
|
|
for k, v := range flags {
|
|
if strings.Contains(k, "=") && v == "true" {
|
|
kv := strings.SplitN(k, "=", 2)
|
|
actualKey, actualValue := kv[0], kv[1]
|
|
if _, ok := flags[actualKey]; !ok {
|
|
flags[actualKey] = actualValue
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func GetFlag(key, fallback string) string {
|
|
val, ok := flags[key]
|
|
if ok {
|
|
return val
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
func GetBoolFlag(key string) bool {
|
|
return GetFlag(key, "false") == "true"
|
|
}
|
|
|
|
func GetIntFlag(key string, fallback int) int {
|
|
val, ok := flags[key]
|
|
if !ok {
|
|
return fallback
|
|
}
|
|
|
|
v, err := strconv.Atoi(val)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
func GetStringSliceFlag(key string, fallback []string) []string {
|
|
val, ok := flags[key]
|
|
if !ok {
|
|
return fallback
|
|
}
|
|
|
|
if val == "" {
|
|
return []string{}
|
|
}
|
|
stringReader := strings.NewReader(val)
|
|
csvReader := csv.NewReader(stringReader)
|
|
v, err := csvReader.Read()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
return v
|
|
}
|