mirror of
https://github.com/holos-run/holos.git
synced 2026-03-20 17:25:01 +00:00
Show subcommand:
This is large change that accomplishes a number of goals. First, there
was no convenient way to show a build plan without using the debug logs
to indentify the tags to inject, then calling the cue command with the
right incantation to inspect the BuildPlan.
This patch addresses the problem by adding a `holos show buildplans`
command. The command loads the Platform spec from the platform
directory, then iterates over all Components to produce the BuildPlan.
This patch adds labels and annotations to the platform Components
collection in order to select and filter the output.
Result:
```
❯ holos show components --selector app.holos.run/cluster=local --format=yaml | head
kind: BuildPlan
apiversion: v1alpha5
metadata:
name: podinfo
spec:
artifacts:
- artifact: clusters/local/components/podinfo/podinfo.gen.yaml
generators:
- kind: Helm
output: helm.gen.yaml
```
---
Interface refactor:
This refactors the interface between the `holos` Go CLI layer and the
various core schema data structures. We now use a proper Go interface.
Concurrent execution over platform components has been improved to
accept a closure function so we can use the same interface method to
process the components. We use this to show each component and render
each component from different subcommands using the same interface
embedded in the builder.Platform struct.
The embedded interface allows us to easily swap in different versions,
e.g. v1beta1 and eventually v1. The number of interface methods are
quite small. 14 methods across 4 interfaces in holos/interface.go.
---
Remove old versions:
This patch removes support for versions prior to v1alpha5 in an effort
to clean up cruft.
58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
// Deprecated: use cli instead
|
|
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
|
|
}
|