api

package
v5.18.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 13 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var PossibleColumnNames = []string{
	"NAME",
	"FILEPATH",
	"NAMESPACE",
	"KIND",
	"VERSION",
	"REPLACEMENT",
	"DEPRECATED",
	"DEPRECATED IN",
	"REMOVED",
	"REMOVED IN",
	"COMPONENT",
	"REPL AVAIL",
	"REPL AVAIL IN",
}

PossibleColumnNames is the list of implmented columns

Functions

func IsFileOrStdin

func IsFileOrStdin(name string) bool

IsFileOrStdin detects if a file exists, or returns true if - is passed

func StringInSlice

func StringInSlice(s string, slice []string) bool

StringInSlice returns true if the string is contained in the slice

Types

type Instance

type Instance struct {
	Outputs                       []*Output         `json:"items,omitempty" yaml:"items,omitempty"`
	IgnoreDeprecations            bool              `json:"-" yaml:"-"`
	IgnoreRemovals                bool              `json:"-" yaml:"-"`
	IgnoreUnavailableReplacements bool              `json:"-" yaml:"-"`
	OnlyShowRemoved               bool              `json:"-" yaml:"-"`
	NoHeaders                     bool              `json:"-" yaml:"-"`
	OutputFormat                  string            `json:"-" yaml:"-"`
	TargetVersions                map[string]string `json:"target-versions,omitempty" yaml:"target-versions,omitempty"`
	DeprecatedVersions            []Version         `json:"-" yaml:"-"`
	CustomColumns                 []string          `json:"-" yaml:"-"`
	Components                    []string          `json:"-" yaml:"-"`
}

Instance is an instance of the API. This holds configuration for a "run" of Pluto

Example (PrintVersionsTabular)
instance := Instance{
	DeprecatedVersions: []Version{
		testVersionDeployment,
		{Kind: "testkind", Name: "testname", DeprecatedIn: "", RemovedIn: "", ReplacementAvailableIn: "", Component: "custom"},
	},
}
_ = instance.printVersionsTabular()
Output:

KIND-------- NAME---------------- DEPRECATED IN-- REMOVED IN-- REPLACEMENT-- REPL AVAIL IN-- COMPONENT--
Deployment-- extensions/v1beta1-- v1.9.0--------- v1.16.0----- apps/v1------ v1.10.0-------- k8s--------
testkind---- testname------------ n/a------------ n/a--------- n/a---------- n/a------------ custom-----
Example (PrintVersionsTabular_noHeaders)
instance := Instance{
	DeprecatedVersions: []Version{
		testVersionDeployment,
		{Kind: "testkind", Name: "testname", DeprecatedIn: "", RemovedIn: "", ReplacementAvailableIn: "", Component: "custom"},
	},
	NoHeaders: true,
}
_ = instance.printVersionsTabular()
Output:

Deployment-- extensions/v1beta1-- v1.9.0-- v1.16.0-- apps/v1-- v1.10.0-- k8s-----
testkind---- testname------------ n/a----- n/a------ n/a------ n/a------ custom--

func (*Instance) DisplayOutput

func (instance *Instance) DisplayOutput() error

DisplayOutput prints the output based on desired variables

Example (Csv)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutput1,
		testOutput2,
	},
	Components:   []string{"foo"},
	OutputFormat: "csv",
}
_ = instance.DisplayOutput()
Output:

NAME,NAMESPACE,KIND,VERSION,REPLACEMENT,DEPRECATED,DEPRECATED IN,REMOVED,REMOVED IN,REPL AVAIL,REPL AVAIL IN
some name one,pluto-namespace,Deployment,extensions/v1beta1,apps/v1,true,v1.9.0,true,v1.16.0,true,v1.10.0
some name two,<UNKNOWN>,Deployment,extensions/v1beta1,apps/v1,true,v1.9.0,true,v1.16.0,true,v1.10.0
Example (Csv_customcolumns)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutput1,
		testOutput2,
	},
	Components:    []string{"foo"},
	OutputFormat:  "csv",
	CustomColumns: []string{"NAMESPACE", "NAME", "DEPRECATED IN", "DEPRECATED", "REPLACEMENT", "VERSION", "KIND", "COMPONENT", "FILEPATH"},
}
_ = instance.DisplayOutput()
Output:

NAMESPACE,NAME,DEPRECATED IN,DEPRECATED,REPLACEMENT,VERSION,KIND,COMPONENT,FILEPATH
pluto-namespace,some name one,v1.9.0,true,apps/v1,extensions/v1beta1,Deployment,foo,path-to-file
<UNKNOWN>,some name two,v1.9.0,true,apps/v1,extensions/v1beta1,Deployment,foo,<UNKNOWN>
Example (Csv_noHeaders)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutput1,
		testOutput2,
	},
	Components:   []string{"foo"},
	OutputFormat: "csv",
	NoHeaders:    true,
}
_ = instance.DisplayOutput()
Output:

some name one,pluto-namespace,Deployment,extensions/v1beta1,apps/v1,true,v1.9.0,true,v1.16.0,true,v1.10.0
some name two,<UNKNOWN>,Deployment,extensions/v1beta1,apps/v1,true,v1.9.0,true,v1.16.0,true,v1.10.0
Example (Custom)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutput1,
		testOutput2,
	},
	OutputFormat:  "custom",
	Components:    []string{"foo"},
	CustomColumns: []string{"NAMESPACE", "NAME", "DEPRECATED IN", "DEPRECATED", "REPLACEMENT", "VERSION", "KIND", "COMPONENT", "FILEPATH"},
}
_ = instance.DisplayOutput()
Output:

NAMESPACE-------- NAME----------- DEPRECATED IN-- DEPRECATED-- REPLACEMENT-- VERSION------------- KIND-------- COMPONENT-- FILEPATH------
pluto-namespace-- some name one-- v1.9.0--------- true-------- apps/v1------ extensions/v1beta1-- Deployment-- foo-------- path-to-file--
<UNKNOWN>-------- some name two-- v1.9.0--------- true-------- apps/v1------ extensions/v1beta1-- Deployment-- foo-------- <UNKNOWN>-----
Example (Json)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutput1,
		testOutput2,
	},
	OutputFormat: "json",
	Components:   []string{"foo"},
}
_ = instance.DisplayOutput()
Output:

{"items":[{"name":"some name one","filePath":"path-to-file","namespace":"pluto-namespace","api":{"version":"extensions/v1beta1","kind":"Deployment","deprecated-in":"v1.9.0","removed-in":"v1.16.0","replacement-api":"apps/v1","replacement-available-in":"v1.10.0","component":"foo"},"deprecated":true,"removed":true,"replacementAvailable":true},{"name":"some name two","api":{"version":"extensions/v1beta1","kind":"Deployment","deprecated-in":"v1.9.0","removed-in":"v1.16.0","replacement-api":"apps/v1","replacement-available-in":"v1.10.0","component":"foo"},"deprecated":true,"removed":true,"replacementAvailable":true}],"target-versions":{"foo":"v1.16.0"}}
Example (Markdown)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutput1,
		testOutput2,
	},
	OutputFormat: "markdown",
	Components:   []string{"foo"},
}
_ = instance.DisplayOutput()
Output:

|     NAME      |    NAMESPACE    |    KIND    |      VERSION       | REPLACEMENT | DEPRECATED | DEPRECATED IN | REMOVED | REMOVED IN | REPL AVAIL | REPL AVAIL IN |
|---------------|-----------------|------------|--------------------|-------------|------------|---------------|---------|------------|------------|---------------|
| some name one | pluto-namespace | Deployment | extensions/v1beta1 | apps/v1     | true       | v1.9.0        | true    | v1.16.0    | true       | v1.10.0       |
| some name two | <UNKNOWN>       | Deployment | extensions/v1beta1 | apps/v1     | true       | v1.9.0        | true    | v1.16.0    | true       | v1.10.0       |
Example (Markdown_customcolumns)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutput1,
		testOutput2,
	},
	OutputFormat:  "markdown",
	Components:    []string{"foo"},
	CustomColumns: []string{"NAMESPACE", "NAME", "DEPRECATED IN", "DEPRECATED", "REPLACEMENT", "VERSION", "KIND", "COMPONENT", "FILEPATH"},
}
_ = instance.DisplayOutput()
Output:

|    NAMESPACE    |     NAME      | DEPRECATED IN | DEPRECATED | REPLACEMENT |      VERSION       |    KIND    | COMPONENT |   FILEPATH   |
|-----------------|---------------|---------------|------------|-------------|--------------------|------------|-----------|--------------|
| pluto-namespace | some name one | v1.9.0        | true       | apps/v1     | extensions/v1beta1 | Deployment | foo       | path-to-file |
| <UNKNOWN>       | some name two | v1.9.0        | true       | apps/v1     | extensions/v1beta1 | Deployment | foo       | <UNKNOWN>    |
Example (NoOutput)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutputNoOutput,
	},
	OutputFormat: "normal",
	Components:   []string{"foo"},
}
_ = instance.DisplayOutput()
Output:

No output to display
Example (Normal)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutput1,
		testOutput2,
		testOutputDeprecatedNotRemoved,
	},
	OutputFormat: "normal",
	Components:   []string{"foo"},
}
_ = instance.DisplayOutput()
Output:

NAME-------------------- KIND-------- VERSION------------- REPLACEMENT-- REMOVED-- DEPRECATED-- REPL AVAIL--
some name one----------- Deployment-- extensions/v1beta1-- apps/v1------ true----- true-------- true--------
some name two----------- Deployment-- extensions/v1beta1-- apps/v1------ true----- true-------- true--------
deprecated not removed-- Deployment-- apps/v1------------- none--------- false---- true-------- true--------
Example (OnlyShowRemoved)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	OnlyShowRemoved: true,
	Outputs: []*Output{
		testOutput1,
		testOutput2,
		testOutputDeprecatedNotRemoved,
	},
	OutputFormat: "normal",
	Components:   []string{"foo"},
}
_ = instance.DisplayOutput()
Output:

NAME----------- KIND-------- VERSION------------- REPLACEMENT-- REMOVED-- DEPRECATED-- REPL AVAIL--
some name one-- Deployment-- extensions/v1beta1-- apps/v1------ true----- true-------- true--------
some name two-- Deployment-- extensions/v1beta1-- apps/v1------ true----- true-------- true--------
Example (Wide)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutput1,
		testOutput2,
	},
	OutputFormat: "wide",
	Components:   []string{"foo"},
}
_ = instance.DisplayOutput()
Output:

NAME----------- NAMESPACE-------- KIND-------- VERSION------------- REPLACEMENT-- DEPRECATED-- DEPRECATED IN-- REMOVED-- REMOVED IN-- REPL AVAIL-- REPL AVAIL IN--
some name one-- pluto-namespace-- Deployment-- extensions/v1beta1-- apps/v1------ true-------- v1.9.0--------- true----- v1.16.0----- true-------- v1.10.0--------
some name two-- <UNKNOWN>-------- Deployment-- extensions/v1beta1-- apps/v1------ true-------- v1.9.0--------- true----- v1.16.0----- true-------- v1.10.0--------
Example (Yaml)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs: []*Output{
		testOutput1,
		testOutput2,
	},
	Components:   []string{"foo"},
	OutputFormat: "yaml",
}
_ = instance.DisplayOutput()
Output:

items:
    - name: some name one
      filePath: path-to-file
      namespace: pluto-namespace
      api:
        version: extensions/v1beta1
        kind: Deployment
        deprecated-in: v1.9.0
        removed-in: v1.16.0
        replacement-api: apps/v1
        replacement-available-in: v1.10.0
        component: foo
      deprecated: true
      removed: true
      replacementAvailable: true
    - name: some name two
      api:
        version: extensions/v1beta1
        kind: Deployment
        deprecated-in: v1.9.0
        removed-in: v1.16.0
        replacement-api: apps/v1
        replacement-available-in: v1.10.0
        component: foo
      deprecated: true
      removed: true
      replacementAvailable: true
target-versions:
    foo: v1.16.0
Example (ZeroLength)
instance := &Instance{
	TargetVersions: map[string]string{
		"foo": "v1.16.0",
	},
	Outputs:      []*Output{},
	OutputFormat: "normal",
}
_ = instance.DisplayOutput()
Output:

There were no resources found with known deprecated apiVersions.

func (*Instance) FilterOutput added in v5.10.0

func (instance *Instance) FilterOutput()

FilterOutput filters the outputs that get printed first it fills out the Deprecated and Removed booleans then it returns the outputs that are either deprecated or removed and in the component list additionally, if instance.OnlyShowDeprecated is true, it will remove the apiVersions that are deprecated but not removed

func (*Instance) GetReturnCode

func (instance *Instance) GetReturnCode() int

GetReturnCode checks for deprecated versions and returns a code. takes a boolean to ignore any errors. exit 2 - version deprecated exit 3 - version removed exit 4 - replacement is unavailable in target version

func (*Instance) IsVersioned

func (instance *Instance) IsVersioned(data []byte) ([]*Output, error)

IsVersioned returns a version if the file data sent can be unmarshaled into a stub and matches a known version in the VersionList

func (*Instance) PrintVersionList

func (instance *Instance) PrintVersionList(outputFormat string) error

PrintVersionList prints out the list of versions in a specific format

Example (Badformat)
instance := Instance{
	DeprecatedVersions: []Version{testVersionDeployment},
}
_ = instance.PrintVersionList("foo")
Output:

The output format must one of (normal|wide|json|yaml)
Example (Json)
instance := Instance{
	DeprecatedVersions: []Version{testVersionDeployment},
}
_ = instance.PrintVersionList("json")
Output:

{"deprecated-versions":[{"version":"extensions/v1beta1","kind":"Deployment","deprecated-in":"v1.9.0","removed-in":"v1.16.0","replacement-api":"apps/v1","replacement-available-in":"v1.10.0","component":"k8s"}]}
Example (Normal)
instance := Instance{
	DeprecatedVersions: []Version{testVersionDeployment},
}
_ = instance.PrintVersionList("normal")
Output:

KIND-------- NAME---------------- DEPRECATED IN-- REMOVED IN-- REPLACEMENT-- REPL AVAIL IN-- COMPONENT--
Deployment-- extensions/v1beta1-- v1.9.0--------- v1.16.0----- apps/v1------ v1.10.0-------- k8s--------
Example (Wide)
instance := Instance{
	DeprecatedVersions: []Version{testVersionDeployment},
}
_ = instance.PrintVersionList("wide")
Output:

KIND-------- NAME---------------- DEPRECATED IN-- REMOVED IN-- REPLACEMENT-- REPL AVAIL IN-- COMPONENT--
Deployment-- extensions/v1beta1-- v1.9.0--------- v1.16.0----- apps/v1------ v1.10.0-------- k8s--------
Example (Yaml)
instance := Instance{
	DeprecatedVersions: []Version{testVersionDeployment},
}
_ = instance.PrintVersionList("yaml")
Output:

deprecated-versions:
    - version: extensions/v1beta1
      kind: Deployment
      deprecated-in: v1.9.0
      removed-in: v1.16.0
      replacement-api: apps/v1
      replacement-available-in: v1.10.0
      component: k8s

type Output

type Output struct {
	// Name is the name of the object in question.
	// This might be an object name, or a release
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	// FilePath is the full path of the file if the output came from a file
	FilePath string `json:"filePath,omitempty" yaml:"filePath,omitempty"`
	// Namespace is the namespace that the object is in
	// The output may resolve this to UNKNOWN if there is no way of determining it
	Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
	// APIVersion is the version object corresponding to this output
	APIVersion *Version `json:"api,omitempty" yaml:"api,omitempty"`
	// Deprecated is a boolean indicating whether or not the version is deprecated
	Deprecated bool `json:"deprecated" yaml:"deprecated"`
	// Removed is a boolean indicating whether or not the version has been removed
	Removed bool `json:"removed" yaml:"removed"`
	// ReplacementAvailable is a boolean indicating whether or not the replacement is available
	ReplacementAvailable bool `json:"replacementAvailable" yaml:"replacementAvailable"`
	// CustomColumns is a list of column headers to be displayed with -ocustom or -omarkdown
	CustomColumns []string `json:"-" yaml:"-"`
}

Output is a thing that has an apiVersion in it

type Stub

type Stub struct {
	Kind       string   `json:"kind" yaml:"kind"`
	APIVersion string   `json:"apiVersion" yaml:"apiVersion"`
	Metadata   StubMeta `json:"metadata" yaml:"metadata"`
	Items      []Stub   `json:"items" yaml:"items"`
}

Stub is a stub of a Kubernetes manifest that has just the name and apiVersion

type StubMeta

type StubMeta struct {
	Name      string `json:"name" yaml:"name"`
	Namespace string `json:"namespace" yaml:"namespace"`
}

StubMeta will catch kube resource metadata

type Version

type Version struct {
	// Name is the name of the api version
	Name string `json:"version" yaml:"version"`
	// Kind is the kind of object associated with this version
	Kind string `json:"kind" yaml:"kind"`
	// DeprecatedIn is a string that indicates what version the api is deprecated in
	// an empty string indicates that the version is not deprecated
	DeprecatedIn string `json:"deprecated-in" yaml:"deprecated-in"`
	// RemovedIn denotes the version that the api was actually removed in
	// An empty string indicates that the version has not been removed yet
	RemovedIn string `json:"removed-in" yaml:"removed-in"`
	// ReplacementAPI is the apiVersion that replaces the deprecated one
	ReplacementAPI string `json:"replacement-api" yaml:"replacement-api"`
	// ReplacementAvailableIn is the version in which the replacement api is available
	ReplacementAvailableIn string `json:"replacement-available-in" yaml:"replacement-available-in"`
	// Component is the component associated with this version
	Component string `json:"component" yaml:"component"`
}

Version is an apiVersion and a flag for deprecation

func CombineAdditionalVersions

func CombineAdditionalVersions(additional []Version, defaults []Version) ([]Version, error)

CombineAdditionalVersions adds additional versions into the defaults. If the additional versions contain any that already exist in the defaults, return an error

func GetDefaultVersionList

func GetDefaultVersionList(versionFileData []byte) ([]Version, map[string]string, error)

GetDefaultVersionList gets the default versions from the versions.yaml file

func UnMarshalVersions

func UnMarshalVersions(data []byte) ([]Version, map[string]string, error)

UnMarshalVersions reads data from a versions file and returns the versions If included, it will also return the map of targetVersions

type VersionFile

type VersionFile struct {
	DeprecatedVersions []Version         `json:"deprecated-versions" yaml:"deprecated-versions"`
	TargetVersions     map[string]string `json:"target-versions,omitempty" yaml:"target-versions,omitempty"`
}

VersionFile is a file with a list of deprecated versions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL