mirror of
https://github.com/holos-run/holos.git
synced 2026-03-20 09:15:02 +00:00
Holos does not post-process a KubernetesObjects core package build plan with kustomize. This is necessary to pass the ArgoCD version through to Kustomize to fetch the correct crds. This patch enables the kustomization and provides an example in the argocd schematic. Result: The KubernetesObjects component doesn't actually have any resources defined, so holos creates an empty `build-plan-resources.yaml` file. This is fine, the kustomize post-processing adds the actual resources via https URL passing in the correct ArgoCD version. ``` ❯ holos render component --cluster-name=workload ./projects/platform/components/argocd/crds --log-level=debug --log-format=text 9:20AM DBG config.go:166 finalized config from flags version=0.93.4 state=finalized 9:20AM DBG builder.go:234 cue: building instances version=0.93.4 9:20AM DBG builder.go:251 cue: validating instance version=0.93.4 dir=/Users/jeff/Holos/holos-manage-a-project-guide/projects/platform/components/argocd/crds 9:20AM DBG builder.go:256 cue: decoding holos build plan version=0.93.4 dir=/Users/jeff/Holos/holos-manage-a-project-guide/projects/platform/components/argocd/crds 9:20AM DBG builder.go:270 cue: discriminated build kind: BuildPlan version=0.93.4 dir=/Users/jeff/Holos/holos-manage-a-project-guide/projects/platform/components/argocd/crds kind=BuildPlan apiVersion=v1alpha3 9:20AM DBG builder.go:314 allocated results slice version=0.93.4 cap=1 9:20AM DBG result.go:156 wrote: /var/folders/22/zt67pphj6h1fgknqfy23ppl80000gn/T/holos.kustomize3526125146/build-plan-resources.yaml version=0.93.4 op=write path=/var/folders/22/zt67pphj6h1fgknqfy23ppl80000gn/T/holos.kustomize3526125146/build-plan-resources.yaml bytes=0 9:20AM DBG result.go:169 wrote: /var/folders/22/zt67pphj6h1fgknqfy23ppl80000gn/T/holos.kustomize3526125146/kustomization.yaml version=0.93.4 op=write path=/var/folders/22/zt67pphj6h1fgknqfy23ppl80000gn/T/holos.kustomize3526125146/kustomization.yaml bytes=174 9:20AM DBG run.go:40 running: kubectl version=0.93.4 name=kubectl args="[kustomize /var/folders/22/zt67pphj6h1fgknqfy23ppl80000gn/T/holos.kustomize3526125146]" 9:20AM DBG remove.go:16 tmp: removed version=0.93.4 path=/var/folders/22/zt67pphj6h1fgknqfy23ppl80000gn/T/holos.kustomize3526125146 9:20AM DBG builder.go:350 returning results version=0.93.4 len=1 9:20AM DBG result.go:214 out: wrote deploy/clusters/workload/components/argocd-crds/argocd-crds.gen.yaml version=0.93.4 action=write path=deploy/clusters/workload/components/argocd-crds/argocd-crds.gen.yaml status=ok 9:20AM INF render.go:79 rendered argocd-crds version=0.93.4 cluster=workload name=argocd-crds status=ok action=rendered ``` Closes: #246
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package render
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/holos-run/holos"
|
|
core "github.com/holos-run/holos/api/core/v1alpha3"
|
|
"github.com/holos-run/holos/internal/errors"
|
|
"github.com/holos-run/holos/internal/server/middleware/logger"
|
|
"github.com/holos-run/holos/internal/util"
|
|
)
|
|
|
|
const KubernetesObjectsKind = "KubernetesObjects"
|
|
|
|
// KubernetesObjects represents CUE output which directly provides Kubernetes api objects to holos.
|
|
type KubernetesObjects struct {
|
|
Component core.KubernetesObjects `json:"component" yaml:"component"`
|
|
}
|
|
|
|
// Render produces kubernetes api objects from the APIObjectMap of the holos component.
|
|
func (o *KubernetesObjects) Render(ctx context.Context, path holos.InstancePath) (*Result, error) {
|
|
result := NewResult(o.Component.Component)
|
|
result.addObjectMap(ctx, o.Component.APIObjectMap)
|
|
if err := result.kustomize(ctx); err != nil {
|
|
return nil, errors.Wrap(fmt.Errorf("could not kustomize: %w", err))
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// KustomizeBuild renders plain yaml files in the holos component directory
|
|
// using kubectl kustomize build.
|
|
type KustomizeBuild struct {
|
|
Component core.KustomizeBuild `json:"component" yaml:"component"`
|
|
}
|
|
|
|
// Render produces a Result by executing kubectl kustomize on the holos
|
|
// component path. Useful for processing raw yaml files.
|
|
func (kb *KustomizeBuild) Render(ctx context.Context, path holos.InstancePath) (*Result, error) {
|
|
if kb == nil {
|
|
return nil, nil
|
|
}
|
|
log := logger.FromContext(ctx)
|
|
result := NewResult(kb.Component.Component)
|
|
// Run kustomize.
|
|
kOut, err := util.RunCmd(ctx, "kubectl", "kustomize", string(path))
|
|
if err != nil {
|
|
log.ErrorContext(ctx, kOut.Stderr.String())
|
|
return nil, errors.Wrap(err)
|
|
}
|
|
// Replace the accumulated output
|
|
result.accumulatedOutput = kOut.Stdout.String()
|
|
// Add CUE based api objects.
|
|
result.addObjectMap(ctx, kb.Component.APIObjectMap)
|
|
return result, nil
|
|
}
|