Skip to content

Commit

Permalink
Sweep for namespace support
Browse files Browse the repository at this point in the history
Signed-off-by: Carolyn Van Slyck <[email protected]>
  • Loading branch information
carolynvs committed Aug 3, 2021
1 parent b2a96b9 commit 100be2f
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 34 deletions.
4 changes: 3 additions & 1 deletion cmd/porter/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func buildInstallationLogShowCommand(p *porter.Porter) *cobra.Command {
Long: `Show the logs from an installation.
Either display the logs from a specific run of a bundle with --run, or use --installation to display the logs from its most recent run.`,
Example: ` porter installation logs show --installation wordpress
Example: ` porter installation logs show --installation wordpress --namespace dev
porter installations logs show --run 01EZSWJXFATDE24XDHS5D5PWK6`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(p.Context)
Expand All @@ -41,6 +41,8 @@ Either display the logs from a specific run of a bundle with --run, or use --ins
}

f := cmd.Flags()
f.StringVarP(&opts.Namespace, "namespace", "n", "",
"Namespace in which the installation is defined. Defaults to the global namespace.")
f.StringVarP(&opts.Name, "installation", "i", "",
"The installation that generated the logs.")
f.StringVarP(&opts.ClaimID, "run", "r", "",
Expand Down
4 changes: 4 additions & 0 deletions cmd/porter/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func buildBundleOutputListCommand(p *porter.Porter) *cobra.Command {
f := cmd.Flags()
f.StringVarP(&opts.RawFormat, "output", "o", "table",
"Specify an output format. Allowed values: table, json, yaml")
f.StringVarP(&opts.Namespace, "namespace", "n", "",
"Namespace in which the installation is defined. Defaults to the global namespace.")
f.StringVarP(&opts.Name, "installation", "i", "",
"Specify the installation to which the output belongs.")

Expand All @@ -66,6 +68,8 @@ func buildBundleOutputShowCommand(p *porter.Porter) *cobra.Command {
}

f := cmd.Flags()
f.StringVarP(&opts.Namespace, "namespace", "n", "",
"Namespace in which the installation is defined. Defaults to the global namespace.")
f.StringVarP(&opts.Name, "installation", "i", "",
"Specify the installation to which the output belongs.")

Expand Down
2 changes: 2 additions & 0 deletions cmd/porter/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ func buildParametersShowCommand(p *porter.Porter) *cobra.Command {
}

f := cmd.Flags()
f.StringVarP(&opts.Namespace, "namespace", "n", "",
"Namespace in which the parameter set is defined. Defaults to the global namespace.")
f.StringVarP(&opts.RawFormat, "output", "o", "table",
"Specify an output format. Allowed values: table, json, yaml")

Expand Down
2 changes: 0 additions & 2 deletions pkg/cnab/provider/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ func (r *Runtime) loadCredentials(b bundle.Bundle, args ActionArguments) (secret

// isPathy checks to see if a name looks like a path.
func (r *Runtime) isPathy(name string) bool {
// TODO: export back outta Compton

return strings.Contains(name, string(filepath.Separator))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/credentials/credentialset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func TestNewCredentialSet(t *testing.T) {
},
})

// TODO(carolynvs): support namespace
assert.Equal(t, "mycreds", cs.Name, "Name was not set")
assert.Equal(t, "dev", cs.Namespace, "Namespace was not set")
assert.NotEmpty(t, cs.Created, "Created was not set")
assert.NotEmpty(t, cs.Modified, "Modified was not set")
assert.Equal(t, cs.Created, cs.Modified, "Created and Modified should have the same timestamp")
Expand Down
6 changes: 2 additions & 4 deletions pkg/porter/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ func (e *dependencyExecutioner) identifyDependencies() error {

bun = cachedBundle.Bundle
} else if e.parentOpts.Name != "" {
// TODO(carolynvs): support namespace
c, err := e.Claims.GetLastRun("", e.parentOpts.Name)
c, err := e.Claims.GetLastRun(e.parentOpts.Namespace, e.parentOpts.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -288,8 +287,7 @@ func (e *dependencyExecutioner) executeDependency(dep *queuedDependency) error {
// will resolve to false and thus be a no-op
if uninstallOpts.shouldDelete() {
fmt.Fprintf(e.Out, installationDeleteTmpl, depArgs.Installation)
// TODO(carolynvs): support namespace
return e.Claims.RemoveInstallation("", depArgs.Installation)
return e.Claims.RemoveInstallation(depArgs.Namespace, depArgs.Installation)
}
return nil
}
3 changes: 1 addition & 2 deletions pkg/porter/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@ func (p *Porter) GetInstallationLogs(opts *LogsShowOptions) (string, bool, error
return p.Claims.GetLogs(opts.ClaimID)
}

// TODO(carolynvs): support namespace
return p.Claims.GetLastLogs("", installation)
return p.Claims.GetLastLogs(opts.Namespace, installation)
}
16 changes: 6 additions & 10 deletions pkg/porter/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ func (p *Porter) ShowBundleOutput(opts *OutputShowOptions) error {
if err != nil {
return err
}
name := opts.sharedOptions.Name

output, err := p.ReadBundleOutput(opts.Output, name)
output, err := p.ReadBundleOutput(opts.Output, opts.Name, opts.Namespace)
if err != nil {
return errors.Wrapf(err, "unable to read output '%s' for installation '%s'", opts.Output, name)
return errors.Wrapf(err, "unable to read output '%s' for installation '%s/%s'", opts.Output, opts.Namespace, opts.Name)
}

fmt.Fprintln(p.Out, output)
Expand Down Expand Up @@ -116,14 +115,12 @@ func (p *Porter) ListBundleOutputs(opts *OutputListOptions) (DisplayValues, erro
return nil, err
}

// TODO(carolynvs): support namespace
c, err := p.Claims.GetLastRun("", opts.Name)
c, err := p.Claims.GetLastRun(opts.Namespace, opts.Name)
if err != nil {
return nil, err
}

// TODO(carolynvs): support namespace
outputs, err := p.Claims.GetLastOutputs("", opts.Name)
outputs, err := p.Claims.GetLastOutputs(opts.Namespace, opts.Name)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -155,9 +152,8 @@ func (p *Porter) PrintBundleOutputs(opts OutputListOptions) error {
}

// ReadBundleOutput reads a bundle output from an installation
func (p *Porter) ReadBundleOutput(outputName, installation string) (string, error) {
// TODO(carolynvs):support namespace
o, err := p.Claims.GetLastOutput("", installation, outputName)
func (p *Porter) ReadBundleOutput(outputName, installation, namespace string) (string, error) {
o, err := p.Claims.GetLastOutput(namespace, installation, outputName)
if err != nil {
return "", err
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/porter/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ func (o *ParameterEditOptions) Validate(args []string) error {

// EditParameter edits the parameters of the provided name.
func (p *Porter) EditParameter(opts ParameterEditOptions) error {
// TODO(carolynvs): support namespace
paramSet, err := p.Parameters.GetParameterSet("", opts.Name)
paramSet, err := p.Parameters.GetParameterSet(opts.Namespace, opts.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -216,8 +215,7 @@ func (p *Porter) EditParameter(opts ParameterEditOptions) error {
// ShowParameter shows the parameter set corresponding to the provided name, using
// the provided printer.PrintOptions for display.
func (p *Porter) ShowParameter(opts ParameterShowOptions) error {
// TODO(carolynvs): support namespace
paramSet, err := p.Parameters.GetParameterSet("", opts.Name)
paramSet, err := p.Parameters.GetParameterSet(opts.Namespace, opts.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -320,7 +318,6 @@ func (p *Porter) loadParameterSets(namespace string, params []string) (secrets.S
if strings.Contains(name, string(filepath.Separator)) {
pset, err = p.loadParameterFromFile(name)
} else {
// TODO(carolynvs): support namespace
pset, err = p.Parameters.GetParameterSet(namespace, name)
}
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/porter/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ func (p *Porter) UninstallBundle(opts UninstallOptions) error {

if opts.shouldDelete() {
fmt.Fprintf(p.Out, installationDeleteTmpl, opts.Name)
// TODO(carolynvs): support namespace
return p.Claims.RemoveInstallation("", opts.Name)
return p.Claims.RemoveInstallation(opts.Namespace, opts.Name)
}
return nil
}
8 changes: 4 additions & 4 deletions tests/integration/outputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestExecOutputs(t *testing.T) {
defer CleanupCurrentBundle(p)

// Verify that its file output was captured
usersOutput, err := p.ReadBundleOutput("users.json", p.Manifest.Name)
usersOutput, err := p.ReadBundleOutput("users.json", p.Manifest.Name, "")
require.NoError(t, err, "could not read users output")
assert.Equal(t, fmt.Sprintln(`{"users": ["sally"]}`), usersOutput, "expected the users output to be populated correctly")

Expand All @@ -51,19 +51,19 @@ func TestExecOutputs(t *testing.T) {
invokeExecOutputsBundle(p, "get-users")

// Verify logs were captured as an output
logs, err := p.ReadBundleOutput(cnab.OutputInvocationImageLogs, p.Manifest.Name)
logs, err := p.ReadBundleOutput(cnab.OutputInvocationImageLogs, p.Manifest.Name, "")
require.NoError(t, err, "ListBundleOutputs failed")
assert.Contains(t, logs, "executing get-users action from exec-outputs", "expected the logs to contain bundle output from the last action")

// Verify that its jsonPath output was captured
userOutput, err := p.ReadBundleOutput("user-names", p.Manifest.Name)
userOutput, err := p.ReadBundleOutput("user-names", p.Manifest.Name, "")
require.NoError(t, err, "could not read user-names output")
assert.Equal(t, `["sally","wei"]`, userOutput, "expected the user-names output to be populated correctly")

invokeExecOutputsBundle(p, "test")

// Verify that its regex output was captured
testOutputs, err := p.ReadBundleOutput("failed-tests", p.Manifest.Name)
testOutputs, err := p.ReadBundleOutput("failed-tests", p.Manifest.Name, "")
require.NoError(t, err, "could not read failed-tests output")
assert.Equal(t, "TestInstall\nTestUpgrade", testOutputs, "expected the failed-tests output to be populated correctly")
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/suppress_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestSuppressOutput(t *testing.T) {
require.NoError(t, err)

// Verify that the bundle output was captured (despite stdout/err of command being suppressed)
bundleOutput, err := p.ReadBundleOutput("greeting", p.Manifest.Name)
bundleOutput, err := p.ReadBundleOutput("greeting", p.Manifest.Name, "")
require.NoError(t, err, "could not read config output")
require.Equal(t, "Hello World!", bundleOutput, "expected the bundle output to be populated correctly")

Expand Down
3 changes: 1 addition & 2 deletions tests/integration/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ func TestUninstall_DeleteInstallation(t *testing.T) {
require.NoError(t, err, "UninstallBundle failed")
}

// TODO(carolynvs): support namespace
_, err = p.Claims.GetInstallation("", opts.Name)
_, err = p.Claims.GetInstallation(opts.Namespace, opts.Name)
if tc.installationRemains {
require.NoError(t, err, "Installation is expected to exist")
} else {
Expand Down

0 comments on commit 100be2f

Please sign in to comment.