mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
go.mod still declared `module github.com/hanzoai/deploy` after the repo was renamed. A Go module path is not cosmetic — it is the resolvable location. So `go get github.com/hanzoai/cd` could not work, and anything importing this module had to spell a name that no longer exists at that address. The build log of v3.6.0 is where it surfaced: the compiler was still emitting github.com/hanzoai/deploy/cmd/cd/commands. 3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from the module path, replaced separately so neither could clobber the other. go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean. Co-authored-by: Hanzo Dev <[email protected]>
91 lines
2.3 KiB
Go
91 lines
2.3 KiB
Go
package generators
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/yaml"
|
|
|
|
argoprojiov1alpha1 "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(_ *argoprojiov1alpha1.ApplicationSetGenerator) time.Duration {
|
|
return NoRequeueAfter
|
|
}
|
|
|
|
func (g *ListGenerator) GetTemplate(appSetGenerator *argoprojiov1alpha1.ApplicationSetGenerator) *argoprojiov1alpha1.ApplicationSetTemplate {
|
|
return &appSetGenerator.List.Template
|
|
}
|
|
|
|
func (g *ListGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha1.ApplicationSetGenerator, appSet *argoprojiov1alpha1.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
|
|
}
|