Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
targetVersions map[string]string
customColumns []string
componentsFromUser []string
ignoredKinds []string
onlyShowRemoved bool
kubeContext string
noHeaders bool
Expand Down Expand Up @@ -94,6 +95,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "normal", "The output format to use. (normal|wide|custom|json|yaml|markdown|csv)")
rootCmd.PersistentFlags().StringSliceVar(&customColumns, "columns", nil, "A list of columns to print. Mandatory when using --output custom, optional with --output markdown")
rootCmd.PersistentFlags().StringSliceVar(&componentsFromUser, "components", nil, "A list of components to run checks for. If nil, will check for all found in versions.")
rootCmd.PersistentFlags().StringSliceVar(&ignoredKinds, "ignore-kinds", nil, "A list of resource kinds to exclude from the results (e.g. CronJob,Ingress).")

rootCmd.AddCommand(detectFilesCmd)
detectFilesCmd.PersistentFlags().StringVarP(&directory, "directory", "d", "", "The directory to scan. If blank, defaults to current working dir.")
Expand Down Expand Up @@ -288,6 +290,7 @@ var rootCmd = &cobra.Command{
NoHeaders: noHeaders,
DeprecatedVersions: deprecatedVersionList,
Components: componentList,
IgnoredKinds: ignoredKinds,
}

return nil
Expand Down
5 changes: 5 additions & 0 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ Notice that there is no output, despite the fact that we might have recognized a

By default Pluto will scan for all components in the versionsList that it can find. If you wish to only see deprecations for a specific component, you can use the `--components` flag to specify a list.

## Ignore Kinds

If you wish to exclude specific resource kinds from the results, you can use the `--ignore-kinds` flag to specify a list. For example, `--ignore-kinds CronJob,Ingress` will hide any detections for kinds named `CronJob` or `Ingress`. The match is case-sensitive and applies to the kind of the deprecated apiVersion.

## Only Show Removed

If you are targeting an upgrade, you may only wish to see apiVersions that have been `removed` rather than both `deprecated` and `removed`. You can pass the `--only-show-removed` or `-r` flag for this. It will remove any detections that are deprecated, but not yet removed. This will affect the exit code of the command as well as the json and yaml output.
Expand Down Expand Up @@ -223,4 +227,5 @@ All environment variables are prefixed with `PLUTO` and use `_` instead of `-`.
| --output | PLUTO_OUTPUT |
| --columns | PLUTO_COLUMNS |
| --components | PLUTO_COMPONENTS |
| --ignore-kinds | PLUTO_IGNORE_KINDS |
| --no-headers | PLUTO_NO_HEADERS |
5 changes: 5 additions & 0 deletions pkg/api/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Instance struct {
DeprecatedVersions []Version `json:"-" yaml:"-"`
CustomColumns []string `json:"-" yaml:"-"`
Components []string `json:"-" yaml:"-"`
IgnoredKinds []string `json:"-" yaml:"-"`
}

// DisplayOutput prints the output based on desired variables
Expand Down Expand Up @@ -156,6 +157,10 @@ func (instance *Instance) DisplayOutput() error {
func (instance *Instance) FilterOutput() {
var usableOutputs []*Output
for _, output := range instance.Outputs {
// skip any kinds that the user has asked to ignore
if StringInSlice(output.APIVersion.Kind, instance.IgnoredKinds) {
continue
}
output.Deprecated = output.APIVersion.isDeprecatedIn(instance.TargetVersions)
output.Removed = output.APIVersion.isRemovedIn(instance.TargetVersions)
output.ReplacementAvailable = output.APIVersion.isReplacementAvailableIn(instance.TargetVersions)
Expand Down
67 changes: 67 additions & 0 deletions pkg/api/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,70 @@ func TestGetReturnCode(t *testing.T) {
})
}
}

func TestFilterOutput(t *testing.T) {
newOutputs := func() []*Output {
return []*Output{
{
Name: "cronjob one",
APIVersion: &Version{
Name: "batch/v1beta1",
Kind: "CronJob",
DeprecatedIn: "v1.21.0",
RemovedIn: "v1.25.0",
Component: "k8s",
},
},
{
Name: "ingress one",
APIVersion: &Version{
Name: "extensions/v1beta1",
Kind: "Ingress",
DeprecatedIn: "v1.14.0",
RemovedIn: "v1.22.0",
Component: "k8s",
},
},
}
}

tests := []struct {
name string
ignoredKinds []string
wantNames []string
}{
{
name: "no ignored kinds keeps everything",
ignoredKinds: nil,
wantNames: []string{"cronjob one", "ingress one"},
},
{
name: "ignored kind is excluded",
ignoredKinds: []string{"CronJob"},
wantNames: []string{"ingress one"},
},
{
name: "all kinds ignored",
ignoredKinds: []string{"CronJob", "Ingress"},
wantNames: []string{},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
instance := &Instance{
Outputs: newOutputs(),
TargetVersions: map[string]string{"k8s": "v1.26.0"},
Components: []string{"k8s"},
IgnoredKinds: tt.ignoredKinds,
}
instance.FilterOutput()

gotNames := []string{}
for _, o := range instance.Outputs {
gotNames = append(gotNames, o.Name)
}
assert.Equal(t, tt.wantNames, gotNames)
})
}
}