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]>
102 lines
3.8 KiB
Go
102 lines
3.8 KiB
Go
package template
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/hanzoai/cd/applicationset/generators"
|
|
"github.com/hanzoai/cd/applicationset/utils"
|
|
|
|
argov1alpha1 "github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
)
|
|
|
|
func GenerateApplications(logCtx *log.Entry, applicationSetInfo argov1alpha1.ApplicationSet, g map[string]generators.Generator, renderer utils.Renderer, client client.Client) ([]argov1alpha1.Application, argov1alpha1.ApplicationSetReasonType, error) {
|
|
var res []argov1alpha1.Application
|
|
|
|
var firstError error
|
|
var applicationSetReason argov1alpha1.ApplicationSetReasonType
|
|
|
|
for _, requestedGenerator := range applicationSetInfo.Spec.Generators {
|
|
t, err := generators.Transform(requestedGenerator, g, applicationSetInfo.Spec.Template, &applicationSetInfo, map[string]any{}, client)
|
|
if err != nil {
|
|
logCtx.WithError(err).WithField("generator", requestedGenerator).
|
|
Error("error generating application from params")
|
|
if firstError == nil {
|
|
firstError = err
|
|
applicationSetReason = argov1alpha1.ApplicationSetReasonApplicationParamsGenerationError
|
|
}
|
|
continue
|
|
}
|
|
|
|
for _, a := range t {
|
|
tmplApplication := GetTempApplication(a.Template)
|
|
|
|
for _, p := range a.Params {
|
|
app, err := renderer.RenderTemplateParams(tmplApplication, applicationSetInfo.Spec.SyncPolicy, p, applicationSetInfo.Spec.GoTemplate, applicationSetInfo.Spec.GoTemplateOptions)
|
|
if err != nil {
|
|
logCtx.WithError(err).WithField("params", a.Params).WithField("generator", requestedGenerator).
|
|
Error("error generating application from params")
|
|
|
|
if firstError == nil {
|
|
firstError = err
|
|
applicationSetReason = argov1alpha1.ApplicationSetReasonRenderTemplateParamsError
|
|
}
|
|
continue
|
|
}
|
|
|
|
if applicationSetInfo.Spec.TemplatePatch != nil {
|
|
patchedApplication, err := renderTemplatePatch(renderer, app, applicationSetInfo, p)
|
|
if err != nil {
|
|
log.WithError(err).WithField("params", a.Params).WithField("generator", requestedGenerator).
|
|
Error("error generating application from params")
|
|
|
|
if firstError == nil {
|
|
firstError = err
|
|
applicationSetReason = argov1alpha1.ApplicationSetReasonRenderTemplateParamsError
|
|
}
|
|
continue
|
|
}
|
|
|
|
app = patchedApplication
|
|
}
|
|
|
|
// The app's namespace must be the same as the AppSet's namespace to preserve the appsets-in-any-namespace
|
|
// security boundary.
|
|
app.Namespace = applicationSetInfo.Namespace
|
|
res = append(res, *app)
|
|
}
|
|
}
|
|
if log.IsLevelEnabled(log.DebugLevel) {
|
|
logCtx.WithField("generator", requestedGenerator).Debugf("apps from generator: %+v", res)
|
|
} else {
|
|
logCtx.Infof("generated %d applications", len(res))
|
|
}
|
|
}
|
|
|
|
return res, applicationSetReason, firstError
|
|
}
|
|
|
|
func renderTemplatePatch(r utils.Renderer, app *argov1alpha1.Application, applicationSetInfo argov1alpha1.ApplicationSet, params map[string]any) (*argov1alpha1.Application, error) {
|
|
replacedTemplate, err := r.Replace(*applicationSetInfo.Spec.TemplatePatch, params, applicationSetInfo.Spec.GoTemplate, applicationSetInfo.Spec.GoTemplateOptions)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error replacing values in templatePatch: %w", err)
|
|
}
|
|
|
|
return applyTemplatePatch(app, replacedTemplate)
|
|
}
|
|
|
|
func GetTempApplication(applicationSetTemplate argov1alpha1.ApplicationSetTemplate) *argov1alpha1.Application {
|
|
var tmplApplication argov1alpha1.Application
|
|
tmplApplication.Annotations = applicationSetTemplate.Annotations
|
|
tmplApplication.Labels = applicationSetTemplate.Labels
|
|
tmplApplication.Namespace = applicationSetTemplate.Namespace
|
|
tmplApplication.Name = applicationSetTemplate.Name
|
|
tmplApplication.Spec = applicationSetTemplate.Spec
|
|
tmplApplication.Finalizers = applicationSetTemplate.Finalizers
|
|
|
|
return &tmplApplication
|
|
}
|