Use install pkg in CLI
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
@@ -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) (string, error) {
|
||||
func Generate(options Options) ([]byte, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), options.Timeout)
|
||||
defer cancel()
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", options.Namespace)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("temp dir error: %w", err)
|
||||
return nil, fmt.Errorf("temp dir error: %w", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
@@ -42,26 +42,26 @@ func Generate(options Options) (string, error) {
|
||||
|
||||
if !strings.HasPrefix(options.BaseURL, "http") {
|
||||
if err := build(options.BaseURL, output); err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err := fetch(ctx, options.BaseURL, options.Version, tmpDir); err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := generate(tmpDir, options); err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := build(tmpDir, output); err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
content, err := ioutil.ReadFile(output)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return string(content), nil
|
||||
return content, nil
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ func TestGenerate(t *testing.T) {
|
||||
|
||||
for _, component := range opts.Components {
|
||||
img := fmt.Sprintf("%s/%s", opts.Registry, component)
|
||||
if !strings.Contains(output, img) {
|
||||
if !strings.Contains(string(output), img) {
|
||||
t.Errorf("component image '%s' not found", img)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(output)
|
||||
fmt.Println(string(output))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user