-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Operator Skeleton Generators #1222
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6521271
starting skeleton operator creation
kensipe 3062108
add params started and working
kensipe 45dbad8
add parameter working with plans
kensipe 30b8061
working add task generator without pipes
kensipe 38b3959
refactoring to encapsulate prompts for kudo objects and adding godoc
kensipe 410eaab
added pipe tasks
kensipe 5f2f663
adding structure for add plan, redefine cli docs and godocs
kensipe 5b95503
adding structure for add plan, redefine cli docs and godocs
kensipe eb19763
list of things todo
kensipe 87a2d1e
working version of add plan. needs better ux
kensipe 8347140
working version for add plan
kensipe 7618b33
organized and forced pipe kinds to secret or configmap
kensipe c484174
give option to not require tasks, reduce task list to those task not …
kensipe abb9745
clog levels are wrong. needed for tracing but otherwise should not b…
kensipe 4b5be7e
adding confirmation to add a trigger for params. validation added to…
kensipe a704f63
test for maintainer
kensipe 5c4e4e4
test for adding parameters
kensipe 81070a1
test for adding plans
kensipe 661ca79
test for adding tasks
kensipe 34e900f
clean up
kensipe ca5c539
updating based on pr feedback
kensipe 9ea5451
Merge branch 'master' into ken/skeleton-generators
kensipe 26f7fbe
Update pkg/kudoctl/cmd/generate/task.go
kensipe 82ad31d
happy linter
kensipe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package generate | ||
|
||
import ( | ||
"github.com/spf13/afero" | ||
|
||
"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1" | ||
"github.com/kudobuilder/kudo/pkg/kudoctl/packages/reader" | ||
) | ||
|
||
// AddMaintainer adds a maintainer to the operator.yaml | ||
func AddMaintainer(fs afero.Fs, path string, m *v1beta1.Maintainer) error { | ||
|
||
p, err := reader.ReadDir(fs, path) | ||
if err != nil { | ||
return err | ||
} | ||
o := p.Files.Operator | ||
|
||
o.Maintainers = append(o.Maintainers, m) | ||
|
||
return writeOperator(fs, path, o) | ||
} | ||
|
||
// MaintainerList provides a list of operator maintainers | ||
func MaintainerList(fs afero.Fs, path string) ([]*v1beta1.Maintainer, error) { | ||
p, err := reader.ReadDir(fs, path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return p.Files.Operator.Maintainers, nil | ||
} |
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,56 @@ | ||
package generate | ||
|
||
import ( | ||
"flag" | ||
"io/ioutil" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1" | ||
"github.com/kudobuilder/kudo/pkg/kudoctl/files" | ||
) | ||
|
||
var updateGolden = flag.Bool("update", false, "update .golden files and manifests in /config/crd") | ||
|
||
func TestAddMaintainer(t *testing.T) { | ||
goldenFile := "maintainer" | ||
fs := afero.NewMemMapFs() | ||
files.CopyOperatorToFs(fs, "../../packages/testdata/zk", "/opt") | ||
m := v1beta1.Maintainer{ | ||
Name: "Cat in the hat", | ||
Email: "c@hat.com", | ||
} | ||
|
||
err := AddMaintainer(fs, "/opt/zk", &m) | ||
assert.NoError(t, err) | ||
|
||
operator, err := afero.ReadFile(fs, "/opt/zk/operator.yaml") | ||
assert.NoError(t, err) | ||
|
||
gp := filepath.Join("testdata", goldenFile+".golden") | ||
|
||
if *updateGolden { | ||
t.Logf("updating golden file %s", goldenFile) | ||
if err := ioutil.WriteFile(gp, operator, 0644); err != nil { | ||
t.Fatalf("failed to update golden file: %s", err) | ||
} | ||
} | ||
g, err := ioutil.ReadFile(gp) | ||
if err != nil { | ||
t.Fatalf("failed reading .golden: %s", err) | ||
} | ||
|
||
assert.Equal(t, g, operator, "for golden file: %s", gp) | ||
} | ||
|
||
func TestListMaintainers(t *testing.T) { | ||
fs := afero.OsFs{} | ||
m, err := MaintainerList(fs, "../../packages/testdata/zk") | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, 3, len(m)) | ||
assert.Equal(t, "Alena Varkockova", m[0].Name) | ||
} |
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,35 @@ | ||
package generate | ||
|
||
import ( | ||
"github.com/spf13/afero" | ||
|
||
"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1" | ||
"github.com/kudobuilder/kudo/pkg/kudoctl/packages/reader" | ||
) | ||
|
||
// AddParameter writes a parameter to the params.yaml file | ||
func AddParameter(fs afero.Fs, path string, p *v1beta1.Parameter) error { | ||
|
||
pf, err := reader.ReadDir(fs, path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
params := pf.Files.Params | ||
params.Parameters = append(params.Parameters, *p) | ||
|
||
return writeParameters(fs, path, *params) | ||
} | ||
|
||
func ParameterNameList(fs afero.Fs, path string) (paramNames []string, err error) { | ||
pf, err := reader.ReadDir(fs, path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, parameter := range pf.Files.Params.Parameters { | ||
paramNames = append(paramNames, parameter.Name) | ||
} | ||
|
||
return paramNames, nil | ||
} |
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,71 @@ | ||
package generate | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1" | ||
"github.com/kudobuilder/kudo/pkg/kudoctl/files" | ||
) | ||
|
||
func TestAddParameter(t *testing.T) { | ||
goldenFile := "parameter" | ||
path := "/opt/zk" | ||
fs := afero.NewMemMapFs() | ||
files.CopyOperatorToFs(fs, "../../packages/testdata/zk", "/opt") | ||
|
||
bar := "Bar" | ||
p := v1beta1.Parameter{ | ||
Name: "Foo", | ||
Default: &bar, | ||
} | ||
|
||
err := AddParameter(fs, path, &p) | ||
assert.NoError(t, err) | ||
|
||
params, err := afero.ReadFile(fs, "/opt/zk/params.yaml") | ||
assert.NoError(t, err) | ||
|
||
gp := filepath.Join("testdata", goldenFile+".golden") | ||
|
||
if *updateGolden { | ||
t.Logf("updating golden file %s", goldenFile) | ||
if err := ioutil.WriteFile(gp, params, 0644); err != nil { | ||
t.Fatalf("failed to update golden file: %s", err) | ||
} | ||
} | ||
golden, err := ioutil.ReadFile(gp) | ||
if err != nil { | ||
t.Fatalf("failed reading .golden: %s", err) | ||
} | ||
|
||
assert.Equal(t, golden, params, "for golden file: %s", gp) | ||
} | ||
|
||
func TestAddParameter_bad_path(t *testing.T) { | ||
path, _ := os.Getwd() | ||
fs := afero.OsFs{} | ||
|
||
bar := "Bar" | ||
p := v1beta1.Parameter{ | ||
Name: "Foo", | ||
Default: &bar, | ||
} | ||
|
||
err := AddParameter(fs, path, &p) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestListParams(t *testing.T) { | ||
fs := afero.OsFs{} | ||
ps, err := ParameterNameList(fs, "../../packages/testdata/zk") | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, 2, len(ps)) | ||
assert.Equal(t, "memory", ps[0]) | ||
} |
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,51 @@ | ||
package generate | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/spf13/afero" | ||
|
||
"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1" | ||
"github.com/kudobuilder/kudo/pkg/kudoctl/packages/reader" | ||
) | ||
|
||
// AddPlan adds a plan to the operator.yaml file | ||
func AddPlan(fs afero.Fs, path string, planName string, plan *v1beta1.Plan) error { | ||
|
||
pf, err := reader.ReadDir(fs, path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
o := pf.Files.Operator | ||
plans := o.Plans | ||
plans[planName] = *plan | ||
pf.Files.Operator.Plans = plans | ||
|
||
return writeOperator(fs, path, o) | ||
} | ||
|
||
// PlanList provides a list of operator plans | ||
func PlanList(fs afero.Fs, path string) (map[string]v1beta1.Plan, error) { | ||
p, err := reader.ReadDir(fs, path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return p.Files.Operator.Plans, nil | ||
} | ||
|
||
// PlanNameList provides a list of operator plan names | ||
func PlanNameList(fs afero.Fs, path string) ([]string, error) { | ||
|
||
names := []string{} | ||
p, err := reader.ReadDir(fs, path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for name := range p.Files.Operator.Plans { | ||
names = append(names, name) | ||
} | ||
sort.Strings(names) | ||
return names, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stylistic, mind adding whitespace between each } and next statement?