diff options
author | Niall Crowe <nicrowe@redhat.com> | 2022-06-24 15:43:05 +0100 |
---|---|---|
committer | Niall Crowe <nicrowe@redhat.com> | 2022-07-13 15:27:03 +0100 |
commit | e08a77ce64eec5cd0192ae1970fa859c00440174 (patch) | |
tree | 434b8a11abe0eb43a5a4e5e99ac4e04fdcc1730f /pkg/bindings/play | |
parent | 4df6122aaa3bc858e9488d366a2c9c91b6671170 (diff) | |
download | podman-e08a77ce64eec5cd0192ae1970fa859c00440174.tar.gz podman-e08a77ce64eec5cd0192ae1970fa859c00440174.tar.bz2 podman-e08a77ce64eec5cd0192ae1970fa859c00440174.zip |
Add "podman kube play" cmd
The "podman kube play" command is designed to be a replacement for the
"podman play kube" command.
It performs the same function as "play kube" while also still working with the same flags and options.
The "podman play kube" command is still functional as an alias of "kube play".
Closes #12475
Signed-off-by: Niall Crowe <nicrowe@redhat.com>
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
Diffstat (limited to 'pkg/bindings/play')
-rw-r--r-- | pkg/bindings/play/play.go | 88 | ||||
-rw-r--r-- | pkg/bindings/play/types.go | 48 | ||||
-rw-r--r-- | pkg/bindings/play/types_kube_options.go | 289 |
3 files changed, 9 insertions, 416 deletions
diff --git a/pkg/bindings/play/play.go b/pkg/bindings/play/play.go index 0261b0250..d5d649135 100644 --- a/pkg/bindings/play/play.go +++ b/pkg/bindings/play/play.go @@ -3,95 +3,25 @@ package play import ( "context" "io" - "net/http" - "os" - "strconv" - "github.com/containers/image/v5/types" - "github.com/containers/podman/v4/pkg/auth" - "github.com/containers/podman/v4/pkg/bindings" + "github.com/containers/podman/v4/pkg/bindings/kube" "github.com/containers/podman/v4/pkg/domain/entities" - "github.com/sirupsen/logrus" ) -func Kube(ctx context.Context, path string, options *KubeOptions) (*entities.PlayKubeReport, error) { - f, err := os.Open(path) - if err != nil { - return nil, err - } - defer f.Close() +type KubeOptions = kube.PlayOptions - return KubeWithBody(ctx, f, options) +func Kube(ctx context.Context, path string, options *KubeOptions) (*entities.PlayKubeReport, error) { + return kube.Play(ctx, path, options) } func KubeWithBody(ctx context.Context, body io.Reader, options *KubeOptions) (*entities.PlayKubeReport, error) { - var report entities.PlayKubeReport - if options == nil { - options = new(KubeOptions) - } - - conn, err := bindings.GetClient(ctx) - if err != nil { - return nil, err - } - - params, err := options.ToParams() - if err != nil { - return nil, err - } - if options.SkipTLSVerify != nil { - params.Set("tlsVerify", strconv.FormatBool(options.GetSkipTLSVerify())) - } - if options.Start != nil { - params.Set("start", strconv.FormatBool(options.GetStart())) - } - - header, err := auth.MakeXRegistryAuthHeader(&types.SystemContext{AuthFilePath: options.GetAuthfile()}, options.GetUsername(), options.GetPassword()) - if err != nil { - return nil, err - } - - response, err := conn.DoRequest(ctx, body, http.MethodPost, "/play/kube", params, header) - if err != nil { - return nil, err - } - defer response.Body.Close() - - if err := response.Process(&report); err != nil { - return nil, err - } - - return &report, nil + return kube.PlayWithBody(ctx, body, options) } -func KubeDown(ctx context.Context, path string) (*entities.PlayKubeReport, error) { - f, err := os.Open(path) - if err != nil { - return nil, err - } - defer func() { - if err := f.Close(); err != nil { - logrus.Warn(err) - } - }() - - return KubeDownWithBody(ctx, f) +func Down(ctx context.Context, path string) (*entities.PlayKubeReport, error) { + return kube.Down(ctx, path) } -func KubeDownWithBody(ctx context.Context, body io.Reader) (*entities.PlayKubeReport, error) { - var report entities.PlayKubeReport - conn, err := bindings.GetClient(ctx) - if err != nil { - return nil, err - } - - response, err := conn.DoRequest(ctx, body, http.MethodDelete, "/play/kube", nil, nil) - if err != nil { - return nil, err - } - if err := response.Process(&report); err != nil { - return nil, err - } - - return &report, nil +func DownWithBody(ctx context.Context, body io.Reader) (*entities.PlayKubeReport, error) { + return kube.DownWithBody(ctx, body) } diff --git a/pkg/bindings/play/types.go b/pkg/bindings/play/types.go deleted file mode 100644 index 5aaa87b8c..000000000 --- a/pkg/bindings/play/types.go +++ /dev/null @@ -1,48 +0,0 @@ -package play - -import ( - "net" -) - -//go:generate go run ../generator/generator.go KubeOptions -// KubeOptions are optional options for replaying kube YAML files -type KubeOptions struct { - // Annotations - Annotations to add to Pods - Annotations map[string]string - // Authfile - path to an authentication file. - Authfile *string - // CertDir - to a directory containing TLS certifications and keys. - CertDir *string - // Username for authenticating against the registry. - Username *string - // Password for authenticating against the registry. - Password *string - // Network - name of the networks to connect to. - Network *[]string - // NoHosts - do not generate /etc/hosts file in pod's containers - NoHosts *bool - // Quiet - suppress output when pulling images. - Quiet *bool - // SignaturePolicy - path to a signature-policy file. - SignaturePolicy *string - // SkipTLSVerify - skip https and certificate validation when - // contacting container registries. - SkipTLSVerify *bool - // SeccompProfileRoot - path to a directory containing seccomp - // profiles. - SeccompProfileRoot *string - // StaticIPs - Static IP address used by the pod(s). - StaticIPs *[]net.IP - // StaticMACs - Static MAC address used by the pod(s). - StaticMACs *[]net.HardwareAddr - // ConfigMaps - slice of pathnames to kubernetes configmap YAMLs. - ConfigMaps *[]string - // LogDriver for the container. For example: journald - LogDriver *string - // LogOptions for the container. For example: journald - LogOptions *[]string - // Start - don't start the pod if false - Start *bool - // Userns - define the user namespace to use. - Userns *string -} diff --git a/pkg/bindings/play/types_kube_options.go b/pkg/bindings/play/types_kube_options.go deleted file mode 100644 index 54c9a8e74..000000000 --- a/pkg/bindings/play/types_kube_options.go +++ /dev/null @@ -1,289 +0,0 @@ -// Code generated by go generate; DO NOT EDIT. -package play - -import ( - "net" - "net/url" - - "github.com/containers/podman/v4/pkg/bindings/internal/util" -) - -// Changed returns true if named field has been set -func (o *KubeOptions) Changed(fieldName string) bool { - return util.Changed(o, fieldName) -} - -// ToParams formats struct fields to be passed to API service -func (o *KubeOptions) ToParams() (url.Values, error) { - return util.ToParams(o) -} - -// WithAnnotations set field Annotations to given value -func (o *KubeOptions) WithAnnotations(value map[string]string) *KubeOptions { - o.Annotations = value - return o -} - -// GetAnnotations returns value of field Annotations -func (o *KubeOptions) GetAnnotations() map[string]string { - if o.Annotations == nil { - var z map[string]string - return z - } - return o.Annotations -} - -// WithAuthfile set field Authfile to given value -func (o *KubeOptions) WithAuthfile(value string) *KubeOptions { - o.Authfile = &value - return o -} - -// GetAuthfile returns value of field Authfile -func (o *KubeOptions) GetAuthfile() string { - if o.Authfile == nil { - var z string - return z - } - return *o.Authfile -} - -// WithCertDir set field CertDir to given value -func (o *KubeOptions) WithCertDir(value string) *KubeOptions { - o.CertDir = &value - return o -} - -// GetCertDir returns value of field CertDir -func (o *KubeOptions) GetCertDir() string { - if o.CertDir == nil { - var z string - return z - } - return *o.CertDir -} - -// WithUsername set field Username to given value -func (o *KubeOptions) WithUsername(value string) *KubeOptions { - o.Username = &value - return o -} - -// GetUsername returns value of field Username -func (o *KubeOptions) GetUsername() string { - if o.Username == nil { - var z string - return z - } - return *o.Username -} - -// WithPassword set field Password to given value -func (o *KubeOptions) WithPassword(value string) *KubeOptions { - o.Password = &value - return o -} - -// GetPassword returns value of field Password -func (o *KubeOptions) GetPassword() string { - if o.Password == nil { - var z string - return z - } - return *o.Password -} - -// WithNetwork set field Network to given value -func (o *KubeOptions) WithNetwork(value []string) *KubeOptions { - o.Network = &value - return o -} - -// GetNetwork returns value of field Network -func (o *KubeOptions) GetNetwork() []string { - if o.Network == nil { - var z []string - return z - } - return *o.Network -} - -// WithNoHosts set field NoHosts to given value -func (o *KubeOptions) WithNoHosts(value bool) *KubeOptions { - o.NoHosts = &value - return o -} - -// GetNoHosts returns value of field NoHosts -func (o *KubeOptions) GetNoHosts() bool { - if o.NoHosts == nil { - var z bool - return z - } - return *o.NoHosts -} - -// WithQuiet set field Quiet to given value -func (o *KubeOptions) WithQuiet(value bool) *KubeOptions { - o.Quiet = &value - return o -} - -// GetQuiet returns value of field Quiet -func (o *KubeOptions) GetQuiet() bool { - if o.Quiet == nil { - var z bool - return z - } - return *o.Quiet -} - -// WithSignaturePolicy set field SignaturePolicy to given value -func (o *KubeOptions) WithSignaturePolicy(value string) *KubeOptions { - o.SignaturePolicy = &value - return o -} - -// GetSignaturePolicy returns value of field SignaturePolicy -func (o *KubeOptions) GetSignaturePolicy() string { - if o.SignaturePolicy == nil { - var z string - return z - } - return *o.SignaturePolicy -} - -// WithSkipTLSVerify set field SkipTLSVerify to given value -func (o *KubeOptions) WithSkipTLSVerify(value bool) *KubeOptions { - o.SkipTLSVerify = &value - return o -} - -// GetSkipTLSVerify returns value of field SkipTLSVerify -func (o *KubeOptions) GetSkipTLSVerify() bool { - if o.SkipTLSVerify == nil { - var z bool - return z - } - return *o.SkipTLSVerify -} - -// WithSeccompProfileRoot set field SeccompProfileRoot to given value -func (o *KubeOptions) WithSeccompProfileRoot(value string) *KubeOptions { - o.SeccompProfileRoot = &value - return o -} - -// GetSeccompProfileRoot returns value of field SeccompProfileRoot -func (o *KubeOptions) GetSeccompProfileRoot() string { - if o.SeccompProfileRoot == nil { - var z string - return z - } - return *o.SeccompProfileRoot -} - -// WithStaticIPs set field StaticIPs to given value -func (o *KubeOptions) WithStaticIPs(value []net.IP) *KubeOptions { - o.StaticIPs = &value - return o -} - -// GetStaticIPs returns value of field StaticIPs -func (o *KubeOptions) GetStaticIPs() []net.IP { - if o.StaticIPs == nil { - var z []net.IP - return z - } - return *o.StaticIPs -} - -// WithStaticMACs set field StaticMACs to given value -func (o *KubeOptions) WithStaticMACs(value []net.HardwareAddr) *KubeOptions { - o.StaticMACs = &value - return o -} - -// GetStaticMACs returns value of field StaticMACs -func (o *KubeOptions) GetStaticMACs() []net.HardwareAddr { - if o.StaticMACs == nil { - var z []net.HardwareAddr - return z - } - return *o.StaticMACs -} - -// WithConfigMaps set field ConfigMaps to given value -func (o *KubeOptions) WithConfigMaps(value []string) *KubeOptions { - o.ConfigMaps = &value - return o -} - -// GetConfigMaps returns value of field ConfigMaps -func (o *KubeOptions) GetConfigMaps() []string { - if o.ConfigMaps == nil { - var z []string - return z - } - return *o.ConfigMaps -} - -// WithLogDriver set field LogDriver to given value -func (o *KubeOptions) WithLogDriver(value string) *KubeOptions { - o.LogDriver = &value - return o -} - -// GetLogDriver returns value of field LogDriver -func (o *KubeOptions) GetLogDriver() string { - if o.LogDriver == nil { - var z string - return z - } - return *o.LogDriver -} - -// WithLogOptions set field LogOptions to given value -func (o *KubeOptions) WithLogOptions(value []string) *KubeOptions { - o.LogOptions = &value - return o -} - -// GetLogOptions returns value of field LogOptions -func (o *KubeOptions) GetLogOptions() []string { - if o.LogOptions == nil { - var z []string - return z - } - return *o.LogOptions -} - -// WithStart set field Start to given value -func (o *KubeOptions) WithStart(value bool) *KubeOptions { - o.Start = &value - return o -} - -// GetStart returns value of field Start -func (o *KubeOptions) GetStart() bool { - if o.Start == nil { - var z bool - return z - } - return *o.Start -} - -// WithUserns set field Userns to given value -func (o *KubeOptions) WithUserns(value string) *KubeOptions { - o.Userns = &value - return o -} - -// GetUserns returns value of field Userns -func (o *KubeOptions) GetUserns() string { - if o.Userns == nil { - var z string - return z - } - return *o.Userns -} |