Skip to content

Commit

Permalink
Support labels
Browse files Browse the repository at this point in the history
Add labels to installations, credential sets and parameter sets.

Signed-off-by: Carolyn Van Slyck <[email protected]>
  • Loading branch information
carolynvs committed Aug 9, 2021
1 parent dae3283 commit d960c9a
Show file tree
Hide file tree
Showing 39 changed files with 311 additions and 123 deletions.
5 changes: 4 additions & 1 deletion cmd/porter/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ The first argument is the name of the installation to create. This defaults to t
Porter uses the Docker driver as the default runtime for executing a bundle's invocation image, but an alternate driver may be supplied via '--driver/-d'.
For example, the 'debug' driver may be specified, which simply logs the info given to it and then exits.`,
Example: ` porter bundle install
porter bundle install MyAppFromReference --reference getporter/kubernetes:v0.1.0
porter bundle install MyAppFromReference --reference getporter/kubernetes:v0.1.0 --namespace dev
porter bundle install --reference localhost:5000/getporter/kubernetes:v0.1.0 --insecure-registry --force
porter bundle install MyAppInDev --file myapp/bundle.json
porter bundle install --parameter-set azure --param test-mode=true --param header-color=blue
porter bundle install --cred azure --cred kubernetes
porter bundle install --driver debug
porter bundle install --label env=dev --label owner=myuser
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args, p)
Expand All @@ -162,6 +163,8 @@ For example, the 'debug' driver may be specified, which simply logs the info giv
"Specify a driver to use. Allowed values: docker, debug")
f.StringVarP(&opts.Namespace, "namespace", "n", "",
"Create the installation in the specified namespace. Defaults to the global namespace.")
f.StringSliceVarP(&opts.Labels, "label", "l", nil,
"Associate the specified labels with the installation. May be specified multiple times.")
addBundlePullFlags(f, &opts.BundlePullOptions)
return cmd
}
Expand Down
15 changes: 12 additions & 3 deletions cmd/porter/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ will then provide it to the bundle in the correct location. `,
f := cmd.Flags()
f.StringVarP(&opts.Namespace, "namespace", "n", "",
"Namespace in which the credential set is defined. Defaults to the global namespace.")
f.StringSliceVarP(&opts.Labels, "label", "l", nil,
"Associate the specified labels with the credential set. May be specified multiple times.")
f.StringVarP(&opts.File, "file", "f", "",
"Path to the porter manifest file. Defaults to the bundle in the current directory.")
f.StringVar(&opts.CNABFile, "cnab-file", "",
Expand All @@ -97,13 +99,18 @@ func buildCredentialsListCommand(p *porter.Porter) *cobra.Command {
opts := porter.ListOptions{}

cmd := &cobra.Command{
Use: "list",
Use: "list [QUERY]",
Aliases: []string{"ls"},
Short: "List credentials",
Long: `List named sets of credentials defined by the user.`,
Long: `List named sets of credentials defined by the user.
Optionally filters the results name, which returns all results whose name contain the provided query.
The results may also be filtered by associated labels and the namespace in which the credential set is defined.`,
Example: ` porter credentials list
porter credentials list --namespace prod
porter credentials list --namespace "*"`,
porter credentials list --namespace "*"
porter credentials list kube
porter credentials list --label env=dev`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.ParseFormat()
},
Expand All @@ -115,6 +122,8 @@ func buildCredentialsListCommand(p *porter.Porter) *cobra.Command {
f := cmd.Flags()
f.StringVarP(&opts.Namespace, "namespace", "n", "",
"Namespace in which the credential set is defined. Defaults to the global namespace. Use * to list across all namespaces.")
f.StringSliceVarP(&opts.Labels, "label", "l", nil,
"Filter the credential sets by a label formatted as: KEY=VALUE. May be specified multiple times.")
f.StringVarP(&opts.RawFormat, "output", "o", "table",
"Specify an output format. Allowed values: table, json, yaml")

Expand Down
12 changes: 9 additions & 3 deletions cmd/porter/installations.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ func buildInstallationsListCommand(p *porter.Porter) *cobra.Command {
opts := porter.ListOptions{}

cmd := &cobra.Command{
Use: "list",
Use: "list [QUERY]",
Short: "List installed bundles",
Long: `List all bundles installed by Porter.
A listing of bundles currently installed by Porter will be provided, along with metadata such as creation time, last action, last status, etc.
Optionally filters the results name, which returns all results whose name contain the provided query.
The results may also be filtered by associated labels and the namespace in which the installation is defined.
Optional output formats include json and yaml.`,
Example: ` porter installations list
porter installations list -o json`,
porter installations list -o json
porter installations list --label owner=me
porter installations list my`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.ParseFormat()
return opts.Validate(args)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.PrintInstallations(opts)
Expand All @@ -49,6 +53,8 @@ Optional output formats include json and yaml.`,
f := cmd.Flags()
f.StringVarP(&opts.Namespace, "namespace", "n", "",
"Filter the installations by namespace. Defaults to the global namespace.")
f.StringSliceVarP(&opts.Labels, "label", "l", nil,
"Filter the installations by a label formatted as: KEY=VALUE. May be specified multiple times.")
f.StringVarP(&opts.RawFormat, "output", "o", "table",
"Specify an output format. Allowed values: table, json, yaml")

Expand Down
15 changes: 12 additions & 3 deletions cmd/porter/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ will then provide it to the bundle in the correct location. `,
f := cmd.Flags()
f.StringVarP(&opts.Namespace, "namespace", "n", "",
"Namespace in which the parameter set is defined. Defaults to the global namespace.")
f.StringSliceVarP(&opts.Labels, "label", "l", nil,
"Associate the specified labels with the parameter set. May be specified multiple times.")
f.StringVarP(&opts.File, "file", "f", "",
"Path to the porter manifest file. Defaults to the bundle in the current directory.")
f.StringVar(&opts.CNABFile, "cnab-file", "",
Expand All @@ -97,13 +99,18 @@ func buildParametersListCommand(p *porter.Porter) *cobra.Command {
opts := porter.ListOptions{}

cmd := &cobra.Command{
Use: "list",
Use: "list [QUERY]",
Aliases: []string{"ls"},
Short: "List parameter sets",
Long: `List named sets of parameters defined by the user.`,
Long: `List named sets of parameters defined by the user.
Optionally filters the results name, which returns all results whose name contain the provided query.
The results may also be filtered by associated labels and the namespace in which the parameter set is defined.`,
Example: ` porter parameters list
porter parameters list --namespace prod -o json
porter parameters list --namespace "*"`,
porter parameters list --namespace "*"
porter parameters list myapp
porter parameters list --label env=dev`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.ParseFormat()
},
Expand All @@ -115,6 +122,8 @@ func buildParametersListCommand(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. Use * to list across all namespaces.")
f.StringSliceVarP(&opts.Labels, "label", "l", nil,
"Filter the parameter sets by a label formatted as: KEY=VALUE. May be specified multiple times.")
f.StringVarP(&opts.RawFormat, "output", "o", "table",
"Specify an output format. Allowed values: table, json, yaml")

Expand Down
4 changes: 3 additions & 1 deletion docs/content/cli/bundles_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ porter bundles install [INSTALLATION] [flags]

```
porter bundle install
porter bundle install MyAppFromReference --reference getporter/kubernetes:v0.1.0
porter bundle install MyAppFromReference --reference getporter/kubernetes:v0.1.0 --namespace dev
porter bundle install --reference localhost:5000/getporter/kubernetes:v0.1.0 --insecure-registry --force
porter bundle install MyAppInDev --file myapp/bundle.json
porter bundle install --parameter-set azure --param test-mode=true --param header-color=blue
porter bundle install --cred azure --cred kubernetes
porter bundle install --driver debug
porter bundle install --label env=dev --label owner=myuser
```

Expand All @@ -44,6 +45,7 @@ porter bundles install [INSTALLATION] [flags]
--force Force a fresh pull of the bundle
-h, --help help for install
--insecure-registry Don't require TLS for the registry
-l, --label strings Associate the specified labels with the installation. May be specified multiple times.
-n, --namespace string Create the installation in the specified namespace. Defaults to the global namespace.
--param strings Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times.
-p, --parameter-set strings Name of a parameter set file for the bundle. May be either a named set of parameters or a filepath, and specified multiple times.
Expand Down
1 change: 1 addition & 0 deletions docs/content/cli/credentials_generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ porter credentials generate [NAME] [flags]
--force Force a fresh pull of the bundle
-h, --help help for generate
--insecure-registry Don't require TLS for the registry
-l, --label strings Associate the specified labels with the credential set. May be specified multiple times.
-n, --namespace string Namespace in which the credential set is defined. Defaults to the global namespace.
-r, --reference string Use a bundle in an OCI registry specified by the given reference.
```
Expand Down
8 changes: 7 additions & 1 deletion docs/content/cli/credentials_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ List credentials

List named sets of credentials defined by the user.

Optionally filters the results name, which returns all results whose name contain the provided query.
The results may also be filtered by associated labels and the namespace in which the credential set is defined.

```
porter credentials list [flags]
porter credentials list [QUERY] [flags]
```

### Examples
Expand All @@ -21,12 +24,15 @@ porter credentials list [flags]
porter credentials list
porter credentials list --namespace prod
porter credentials list --namespace "*"
porter credentials list kube
porter credentials list --label env=dev
```

### Options

```
-h, --help help for list
-l, --label strings Filter the credential sets by a label formatted as: KEY=VALUE. May be specified multiple times.
-n, --namespace string Namespace in which the credential set is defined. Defaults to the global namespace. Use * to list across all namespaces.
-o, --output string Specify an output format. Allowed values: table, json, yaml (default "table")
```
Expand Down
4 changes: 3 additions & 1 deletion docs/content/cli/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ porter install [INSTALLATION] [flags]

```
porter install
porter install MyAppFromReference --reference getporter/kubernetes:v0.1.0
porter install MyAppFromReference --reference getporter/kubernetes:v0.1.0 --namespace dev
porter install --reference localhost:5000/getporter/kubernetes:v0.1.0 --insecure-registry --force
porter install MyAppInDev --file myapp/bundle.json
porter install --parameter-set azure --param test-mode=true --param header-color=blue
porter install --cred azure --cred kubernetes
porter install --driver debug
porter install --label env=dev --label owner=myuser
```

Expand All @@ -44,6 +45,7 @@ porter install [INSTALLATION] [flags]
--force Force a fresh pull of the bundle
-h, --help help for install
--insecure-registry Don't require TLS for the registry
-l, --label strings Associate the specified labels with the installation. May be specified multiple times.
-n, --namespace string Create the installation in the specified namespace. Defaults to the global namespace.
--param strings Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times.
-p, --parameter-set strings Name of a parameter set file for the bundle. May be either a named set of parameters or a filepath, and specified multiple times.
Expand Down
7 changes: 6 additions & 1 deletion docs/content/cli/installations_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@ List installed bundles
List all bundles installed by Porter.

A listing of bundles currently installed by Porter will be provided, along with metadata such as creation time, last action, last status, etc.
Optionally filters the results name, which returns all results whose name contain the provided query.
The results may also be filtered by associated labels and the namespace in which the installation is defined.

Optional output formats include json and yaml.

```
porter installations list [flags]
porter installations list [QUERY] [flags]
```

### Examples

```
porter installations list
porter installations list -o json
porter installations list --label owner=me
porter installations list my
```

### Options

```
-h, --help help for list
-l, --label strings Filter the installations by a label formatted as: KEY=VALUE. May be specified multiple times.
-n, --namespace string Filter the installations by namespace. Defaults to the global namespace.
-o, --output string Specify an output format. Allowed values: table, json, yaml (default "table")
```
Expand Down
7 changes: 6 additions & 1 deletion docs/content/cli/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@ List installed bundles
List all bundles installed by Porter.

A listing of bundles currently installed by Porter will be provided, along with metadata such as creation time, last action, last status, etc.
Optionally filters the results name, which returns all results whose name contain the provided query.
The results may also be filtered by associated labels and the namespace in which the installation is defined.

Optional output formats include json and yaml.

```
porter list [flags]
porter list [QUERY] [flags]
```

### Examples

```
porter list
porter list -o json
porter list --label owner=me
porter list my
```

### Options

```
-h, --help help for list
-l, --label strings Filter the installations by a label formatted as: KEY=VALUE. May be specified multiple times.
-n, --namespace string Filter the installations by namespace. Defaults to the global namespace.
-o, --output string Specify an output format. Allowed values: table, json, yaml (default "table")
```
Expand Down
1 change: 1 addition & 0 deletions docs/content/cli/parameters_generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ porter parameters generate [NAME] [flags]
--force Force a fresh pull of the bundle
-h, --help help for generate
--insecure-registry Don't require TLS for the registry
-l, --label strings Associate the specified labels with the parameter set. May be specified multiple times.
-n, --namespace string Namespace in which the parameter set is defined. Defaults to the global namespace.
-r, --reference string Use a bundle in an OCI registry specified by the given reference.
```
Expand Down
8 changes: 7 additions & 1 deletion docs/content/cli/parameters_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ List parameter sets

List named sets of parameters defined by the user.

Optionally filters the results name, which returns all results whose name contain the provided query.
The results may also be filtered by associated labels and the namespace in which the parameter set is defined.

```
porter parameters list [flags]
porter parameters list [QUERY] [flags]
```

### Examples
Expand All @@ -21,12 +24,15 @@ porter parameters list [flags]
porter parameters list
porter parameters list --namespace prod -o json
porter parameters list --namespace "*"
porter parameters list myapp
porter parameters list --label env=dev
```

### Options

```
-h, --help help for list
-l, --label strings Filter the parameter sets by a label formatted as: KEY=VALUE. May be specified multiple times.
-n, --namespace string Namespace in which the parameter set is defined. Defaults to the global namespace. Use * to list across all namespaces.
-o, --output string Specify an output format. Allowed values: table, json, yaml (default "table")
```
Expand Down
15 changes: 6 additions & 9 deletions pkg/claims/claimstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,14 @@ func (s ClaimStore) Initialize() error {
return bigErr.ErrorOrNil()
}

func (s ClaimStore) ListInstallations(namespace string) ([]Installation, error) {
func (s ClaimStore) ListInstallations(namespace string, name string, labels map[string]string) ([]Installation, error) {
var out []Installation
opts := storage.FindOptions{
Sort: []string{"namespace", "name"},
}
if namespace != "*" {
opts.Filter = bson.M{
"namespace": namespace,
}
findOpts := storage.FindOptions{
Sort: []string{"namespace", "name"},
Filter: storage.CreateListFiler(namespace, name, labels),
}
err := s.store.Find(CollectionInstallations, opts, &out)

err := s.store.Find(CollectionInstallations, findOpts, &out)
return out, err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/claims/claimstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestClaimStore_Installations(t *testing.T) {
defer cp.Teardown()

t.Run("ListInstallations", func(t *testing.T) {
installations, err := cp.ListInstallations("dev")
installations, err := cp.ListInstallations("dev", "", nil)
require.NoError(t, err, "ListInstallations failed")

require.Len(t, installations, 3, "Expected 3 installations")
Expand Down Expand Up @@ -188,14 +188,14 @@ func TestClaimStore_DeleteInstallation(t *testing.T) {
cp := generateClaimData(t)
defer cp.Teardown()

installations, err := cp.ListInstallations("dev")
installations, err := cp.ListInstallations("dev", "", nil)
require.NoError(t, err, "ListInstallations failed")
assert.Len(t, installations, 3, "expected 3 installations")

err = cp.RemoveInstallation("dev", "foo")
require.NoError(t, err, "RemoveInstallation failed")

installations, err = cp.ListInstallations("dev")
installations, err = cp.ListInstallations("dev", "", nil)
require.NoError(t, err, "ListInstallations failed")
assert.Len(t, installations, 2, "expected foo to be deleted")

Expand Down
5 changes: 2 additions & 3 deletions pkg/claims/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ type Provider interface {
// GetInstallation retrieves an Installation document by name.
GetInstallation(namespace string, name string) (Installation, error)

// ListInstallations returns Installation documents sorted in ascending order by name.
ListInstallations(namespace string) ([]Installation, error)

// ListInstallations returns Installations sorted in ascending order by the namespace and then name.
ListInstallations(namespace string, name string, labels map[string]string) ([]Installation, error)
// ListRuns returns Run documents sorted in ascending order by ID.
ListRuns(namespace string, installation string) ([]Run, error)

Expand Down
Loading

0 comments on commit d960c9a

Please sign in to comment.