1
0
mirror of synced 2026-03-17 08:36:56 +00:00

Refactor manifest generation

Signed-off-by: Philip Laine <philip.laine@xenit.se>
This commit is contained in:
Philip Laine
2020-10-28 15:47:24 +01:00
parent bd4d4d927e
commit b0d2a38ff6
9 changed files with 186 additions and 93 deletions

View File

@@ -28,13 +28,13 @@ import (
// Generate returns the install manifests as a multi-doc YAML.
// The manifests are built from a GitHub release or from a
// Kustomize overlay if the supplied Options.BaseURL is a local path.
func Generate(options Options) ([]byte, error) {
func Generate(options Options) (string, string, error) {
ctx, cancel := context.WithTimeout(context.Background(), options.Timeout)
defer cancel()
tmpDir, err := ioutil.TempDir("", options.Namespace)
if err != nil {
return nil, fmt.Errorf("temp dir error: %w", err)
return "", "", fmt.Errorf("temp dir error: %w", err)
}
defer os.RemoveAll(tmpDir)
@@ -42,26 +42,26 @@ func Generate(options Options) ([]byte, error) {
if !strings.HasPrefix(options.BaseURL, "http") {
if err := build(options.BaseURL, output); err != nil {
return nil, err
return "", "", err
}
} else {
if err := fetch(ctx, options.BaseURL, options.Version, tmpDir); err != nil {
return nil, err
return "", "", err
}
if err := generate(tmpDir, options); err != nil {
return nil, err
return "", "", err
}
if err := build(tmpDir, output); err != nil {
return nil, err
return "", "", err
}
}
content, err := ioutil.ReadFile(output)
if err != nil {
return nil, err
return "", "", err
}
return content, nil
return path.Join(options.TargetPath, options.Namespace, options.ManifestsFile), string(content), nil
}

View File

@@ -24,7 +24,7 @@ import (
func TestGenerate(t *testing.T) {
opts := MakeDefaultOptions()
output, err := Generate(opts)
_, output, err := Generate(opts)
if err != nil {
t.Fatal(err)
}

View File

@@ -33,6 +33,7 @@ type Options struct {
NotificationController string
ManifestsFile string
Timeout time.Duration
TargetPath string
}
func MakeDefaultOptions() Options {
@@ -51,6 +52,7 @@ func MakeDefaultOptions() Options {
NotificationController: "notification-controller",
ManifestsFile: "toolkit-components.yaml",
Timeout: time.Minute,
TargetPath: "",
}
}