-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clearer prompts and better importing logic for 'mass bundle new'
- Loading branch information
1 parent
47b81e9
commit d1cd8a3
Showing
10 changed files
with
274 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package provisioners | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"os" | ||
"path" | ||
|
||
"github.com/massdriver-cloud/airlock/pkg/helm" | ||
) | ||
|
||
type HelmProvisioner struct{} | ||
|
||
func (p *HelmProvisioner) ExportMassdriverInputs(stepPath string, variables map[string]interface{}) error { | ||
// Nothing to do here. Helm doesn't required variables to be declared before use, nor does it require types to be specified | ||
|
||
return nil | ||
} | ||
|
||
func (p *HelmProvisioner) ReadProvisionerInputs(stepPath string) (map[string]interface{}, error) { | ||
helmParamsSchema, err := helm.HelmToSchema(path.Join(stepPath, "values.yaml")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
schemaBytes, marshallErr := json.Marshal(helmParamsSchema) | ||
if marshallErr != nil { | ||
return nil, marshallErr | ||
} | ||
|
||
variables := map[string]interface{}{} | ||
err = json.Unmarshal(schemaBytes, &variables) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return variables, nil | ||
} | ||
|
||
func (p *HelmProvisioner) InitializeStep(stepPath string, sourcePath string) error { | ||
pathInfo, statErr := os.Stat(sourcePath) | ||
if statErr != nil { | ||
return statErr | ||
} | ||
if !pathInfo.IsDir() { | ||
return errors.New("path is not a directory containing a helm chart") | ||
} | ||
|
||
if _, chartErr := os.Stat(path.Join(sourcePath, "Chart.yaml")); errors.Is(chartErr, os.ErrNotExist) { | ||
return errors.New("path does not contain 'Chart.yaml' file, and therefore isn't a valid Helm chart") | ||
} | ||
if _, valuesErr := os.Stat(path.Join(sourcePath, "values.yaml")); errors.Is(valuesErr, os.ErrNotExist) { | ||
return errors.New("path does not contain 'values.yaml' file, and therefore isn't a valid Helm chart") | ||
} | ||
|
||
return os.CopyFS(stepPath, os.DirFS(sourcePath)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package provisioners_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"reflect" | ||
"slices" | ||
"testing" | ||
|
||
"github.com/massdriver-cloud/mass/pkg/provisioners" | ||
) | ||
|
||
func TestHelmReadProvisionerInputs(t *testing.T) { | ||
type test struct { | ||
name string | ||
want map[string]interface{} | ||
} | ||
tests := []test{ | ||
{ | ||
name: "same", | ||
want: map[string]interface{}{ | ||
"required": []interface{}{"foo", "baz"}, | ||
"properties": map[string]interface{}{ | ||
"foo": map[string]interface{}{ | ||
"title": "foo", | ||
"type": "string", | ||
"default": "bar", | ||
}, | ||
"baz": map[string]interface{}{ | ||
"title": "baz", | ||
"type": "string", | ||
"default": "qux", | ||
}, | ||
}, | ||
"type": "object", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
testDir := t.TempDir() | ||
|
||
content, err := os.ReadFile(path.Join("testdata", "helm", fmt.Sprintf("%s.yaml", tc.name))) | ||
if err != nil { | ||
t.Fatalf("%d, unexpected error", err) | ||
} | ||
|
||
testFile := path.Join(testDir, "values.yaml") | ||
err = os.WriteFile(testFile, content, 0644) | ||
if err != nil { | ||
t.Fatalf("%d, unexpected error", err) | ||
} | ||
|
||
prov := provisioners.HelmProvisioner{} | ||
got, err := prov.ReadProvisionerInputs(testDir) | ||
if err != nil { | ||
t.Errorf("Error during validation: %s", err) | ||
} | ||
|
||
if !reflect.DeepEqual(got, tc.want) { | ||
t.Errorf("want %v got %v", got, tc.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestHelmInitializeStep(t *testing.T) { | ||
type test struct { | ||
name string | ||
chartPath string | ||
} | ||
tests := []test{ | ||
{ | ||
name: "same", | ||
chartPath: "testdata/helm/initializetest", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
testDir := t.TempDir() | ||
|
||
prov := provisioners.HelmProvisioner{} | ||
initErr := prov.InitializeStep(testDir, tc.chartPath) | ||
if initErr != nil { | ||
t.Fatalf("unexpected error: %s", initErr) | ||
} | ||
|
||
want := []string{} | ||
wanttErr := filepath.Walk(tc.chartPath, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if tc.chartPath == path { | ||
return nil | ||
} | ||
want = append(want, info.Name()) | ||
return nil | ||
}) | ||
if wanttErr != nil { | ||
t.Fatalf("unexpected error: %s", wanttErr) | ||
} | ||
|
||
got := []string{} | ||
gotErr := filepath.Walk(testDir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if testDir == path { | ||
return nil | ||
} | ||
got = append(got, info.Name()) | ||
return nil | ||
}) | ||
if gotErr != nil { | ||
t.Fatalf("unexpected error: %s", gotErr) | ||
} | ||
|
||
if len(got) != len(want) { | ||
t.Errorf("want %v got %v", got, want) | ||
} | ||
for _, curr := range got { | ||
if !slices.Contains(want, curr) { | ||
t.Errorf("%v doesn't exist in %v", curr, want) | ||
} | ||
} | ||
}) | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
foo: bar | ||
baz: qux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters