mirror of
https://github.com/hanzoai/cd.git
synced 2026-10-30 14:56:45 +00:00
Rename test names, comments, fixture data, and mock GitHub/webhook responses that still said Argo/ArgoCD/argocd/argoproj in our own voice, matching the hanzocd-* binary/configmap names and the apps.hanzo.ai CRD/annotation domain already established elsewhere in the fork. Also drop the dated argov1alpha1/argoprojiov1alpha1 import aliases for our own v1alpha1 API package. Restore the CRD groups a prior blind rename had mangled on a vendored third-party Argo Workflows example manifest back to the real argoproj.io, and fix several places where an earlier half-finished rename had gone silently wrong instead of just being cosmetic: stale CD_BINARY_NAME values and a stale --argocd-repo-server flag no longer recognized by the binary, cert filenames and an ssh_known_hosts alias that didn't match what's actually on disk, a namespace and a kustomize image substitution that were silent no-ops, and a test assertion regex that could never match its own fixture. External lookup keys we don't control are left byte-exact: quay.io/argoprojlabs images, the docker.io/argoproj CI builder image, live argoproj/argo-workflows release URLs, the generated ArgoprojV1alpha1() clientset method, and the Makefile-coupled /tmp/argo-e2e and GOPATH mount conventions.
91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
package generators
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/yaml"
|
|
|
|
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
)
|
|
|
|
var _ Generator = (*ListGenerator)(nil)
|
|
|
|
type ListGenerator struct{}
|
|
|
|
func NewListGenerator() Generator {
|
|
g := &ListGenerator{}
|
|
return g
|
|
}
|
|
|
|
func (g *ListGenerator) GetRequeueAfter(_ *v1alpha1.ApplicationSetGenerator) time.Duration {
|
|
return NoRequeueAfter
|
|
}
|
|
|
|
func (g *ListGenerator) GetTemplate(appSetGenerator *v1alpha1.ApplicationSetGenerator) *v1alpha1.ApplicationSetTemplate {
|
|
return &appSetGenerator.List.Template
|
|
}
|
|
|
|
func (g *ListGenerator) GenerateParams(appSetGenerator *v1alpha1.ApplicationSetGenerator, appSet *v1alpha1.ApplicationSet, _ client.Client) ([]map[string]any, error) {
|
|
if appSetGenerator == nil {
|
|
return nil, ErrEmptyAppSetGenerator
|
|
}
|
|
|
|
if appSetGenerator.List == nil {
|
|
return nil, ErrEmptyAppSetGenerator
|
|
}
|
|
|
|
res := make([]map[string]any, len(appSetGenerator.List.Elements))
|
|
|
|
for i, tmpItem := range appSetGenerator.List.Elements {
|
|
params := map[string]any{}
|
|
var element map[string]any
|
|
err := json.Unmarshal(tmpItem.Raw, &element)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error unmarshling list element %w", err)
|
|
}
|
|
|
|
if appSet.Spec.GoTemplate {
|
|
res[i] = element
|
|
} else {
|
|
for key, value := range element {
|
|
if key == "values" {
|
|
values, ok := (value).(map[string]any)
|
|
if !ok {
|
|
return nil, errors.New("error parsing values map")
|
|
}
|
|
for k, v := range values {
|
|
value, ok := v.(string)
|
|
if !ok {
|
|
return nil, fmt.Errorf("error parsing value as string %w", err)
|
|
}
|
|
params["values."+k] = value
|
|
}
|
|
} else {
|
|
v, ok := value.(string)
|
|
if !ok {
|
|
return nil, fmt.Errorf("error parsing value as string %w", err)
|
|
}
|
|
params[key] = v
|
|
}
|
|
res[i] = params
|
|
}
|
|
}
|
|
}
|
|
|
|
// Append elements from ElementsYaml to the response
|
|
if appSetGenerator.List.ElementsYaml != "" {
|
|
var yamlElements []map[string]any
|
|
err := yaml.Unmarshal([]byte(appSetGenerator.List.ElementsYaml), &yamlElements)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error unmarshling decoded ElementsYaml %w", err)
|
|
}
|
|
res = append(res, yamlElements...)
|
|
}
|
|
|
|
return res, nil
|
|
}
|