From e08a77ce64eec5cd0192ae1970fa859c00440174 Mon Sep 17 00:00:00 2001 From: Niall Crowe Date: Fri, 24 Jun 2022 15:43:05 +0100 Subject: 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 Signed-off-by: Valentin Rothberg --- cmd/podman/kube/kube.go | 35 +++ cmd/podman/kube/play.go | 355 ++++++++++++++++++++++ cmd/podman/main.go | 2 +- cmd/podman/play/kube.go | 327 -------------------- cmd/podman/play/play.go | 23 -- docs/kubernetes_support.md | 175 +++++++++++ docs/play_kube_support.md | 175 ----------- docs/source/Commands.rst | 4 +- docs/source/markdown/links/podman-play-kube.1 | 1 + docs/source/markdown/podman-generate-kube.1.md | 2 +- docs/source/markdown/podman-generate-systemd.1.md | 2 +- docs/source/markdown/podman-kube-play.1.md | 331 ++++++++++++++++++++ docs/source/markdown/podman-kube.1.md | 20 ++ docs/source/markdown/podman-play-kube.1.md | 342 --------------------- docs/source/markdown/podman-play.1.md | 20 -- docs/source/markdown/podman-pod-create.1.md | 4 +- docs/source/markdown/podman.1.md | 2 +- hack/swagger-check | 4 +- pkg/api/handlers/libpod/kube.go | 123 ++++++++ pkg/api/handlers/libpod/play.go | 114 +------ pkg/api/handlers/swagger/responses.go | 2 +- pkg/api/server/register_kube.go | 82 +++++ pkg/api/server/register_play.go | 80 ----- pkg/api/server/server.go | 2 +- pkg/bindings/kube/kube.go | 96 ++++++ pkg/bindings/kube/types.go | 48 +++ pkg/bindings/kube/types_play_options.go | 289 ++++++++++++++++++ pkg/bindings/play/play.go | 88 +----- pkg/bindings/play/types.go | 48 --- pkg/bindings/play/types_kube_options.go | 289 ------------------ pkg/domain/entities/play.go | 2 + pkg/domain/infra/tunnel/play.go | 5 +- test/apiv2/25-containersMore.at | 28 -- test/apiv2/80-kube.at | 50 +++ test/apiv2/test-apiv2 | 4 +- test/system/700-play.bats | 34 ++- 36 files changed, 1660 insertions(+), 1548 deletions(-) create mode 100644 cmd/podman/kube/kube.go create mode 100644 cmd/podman/kube/play.go delete mode 100644 cmd/podman/play/kube.go delete mode 100644 cmd/podman/play/play.go create mode 100644 docs/kubernetes_support.md delete mode 100644 docs/play_kube_support.md create mode 100644 docs/source/markdown/links/podman-play-kube.1 create mode 100644 docs/source/markdown/podman-kube-play.1.md create mode 100644 docs/source/markdown/podman-kube.1.md delete mode 100644 docs/source/markdown/podman-play-kube.1.md delete mode 100644 docs/source/markdown/podman-play.1.md create mode 100644 pkg/api/handlers/libpod/kube.go create mode 100644 pkg/api/server/register_kube.go delete mode 100644 pkg/api/server/register_play.go create mode 100644 pkg/bindings/kube/kube.go create mode 100644 pkg/bindings/kube/types.go create mode 100644 pkg/bindings/kube/types_play_options.go delete mode 100644 pkg/bindings/play/types.go delete mode 100644 pkg/bindings/play/types_kube_options.go create mode 100644 test/apiv2/80-kube.at diff --git a/cmd/podman/kube/kube.go b/cmd/podman/kube/kube.go new file mode 100644 index 000000000..68f55a157 --- /dev/null +++ b/cmd/podman/kube/kube.go @@ -0,0 +1,35 @@ +package pods + +import ( + "github.com/containers/podman/v4/cmd/podman/registry" + "github.com/containers/podman/v4/cmd/podman/validate" + "github.com/spf13/cobra" +) + +var ( + // Command: podman _kube_ + kubeCmd = &cobra.Command{ + Use: "kube", + Short: "Play containers, pods or volumes from a structured file", + Long: "Play structured data (e.g., Kubernetes YAML) based on containers, pods or volumes.", + RunE: validate.SubCommandExists, + } + + playKubeParentCmd = &cobra.Command{ + Use: "play", + Short: "Play containers, pods or volumes from a structured file", + Long: "Play structured data (e.g., Kubernetes YAML) based on containers, pods or volumes.", + Hidden: true, + RunE: validate.SubCommandExists, + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Command: kubeCmd, + }) + + registry.Commands = append(registry.Commands, registry.CliCommand{ + Command: playKubeParentCmd, + }) +} diff --git a/cmd/podman/kube/play.go b/cmd/podman/kube/play.go new file mode 100644 index 000000000..685cb521c --- /dev/null +++ b/cmd/podman/kube/play.go @@ -0,0 +1,355 @@ +package pods + +import ( + "errors" + "fmt" + "net" + "os" + "strings" + + "github.com/containers/common/pkg/auth" + "github.com/containers/common/pkg/completion" + "github.com/containers/image/v5/types" + "github.com/containers/podman/v4/cmd/podman/common" + "github.com/containers/podman/v4/cmd/podman/registry" + "github.com/containers/podman/v4/cmd/podman/utils" + "github.com/containers/podman/v4/libpod/define" + "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/errorhandling" + "github.com/containers/podman/v4/pkg/util" + "github.com/spf13/cobra" +) + +// playKubeOptionsWrapper allows for separating CLI-only fields from API-only +// fields. +type playKubeOptionsWrapper struct { + entities.PlayKubeOptions + + TLSVerifyCLI bool + CredentialsCLI string + StartCLI bool + BuildCLI bool + annotations []string + macs []string +} + +var ( + // https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/ + defaultSeccompRoot = "/var/lib/kubelet/seccomp" + playOptions = playKubeOptionsWrapper{} + playDescription = `Command reads in a structured file of Kubernetes YAML. + + It creates pods or volumes based on the Kubernetes kind described in the YAML. Supported kinds are Pods, Deployments and PersistentVolumeClaims.` + + playCmd = &cobra.Command{ + Use: "play [options] KUBEFILE|-", + Short: "Play a pod or volume based on Kubernetes YAML.", + Long: playDescription, + RunE: Play, + Args: cobra.ExactArgs(1), + ValidArgsFunction: common.AutocompleteDefaultOneArg, + Example: `podman kube play nginx.yml + cat nginx.yml | podman kube play - + podman kube play --creds user:password --seccomp-profile-root /custom/path apache.yml`, + } +) + +var ( + playKubeCmd = &cobra.Command{ + Use: "kube [options] KUBEFILE|-", + Short: "Play a pod or volume based on Kubernetes YAML.", + Long: playDescription, + Hidden: true, + RunE: playKube, + Args: cobra.ExactArgs(1), + ValidArgsFunction: common.AutocompleteDefaultOneArg, + Example: `podman play kube nginx.yml + cat nginx.yml | podman play kube - + podman play kube --creds user:password --seccomp-profile-root /custom/path apache.yml`, + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Command: playCmd, + Parent: kubeCmd, + }) + playFlags(playCmd) + + registry.Commands = append(registry.Commands, registry.CliCommand{ + Command: playKubeCmd, + Parent: playKubeParentCmd, + }) + playFlags(playKubeCmd) +} + +func playFlags(cmd *cobra.Command) { + flags := cmd.Flags() + flags.SetNormalizeFunc(utils.AliasFlags) + + annotationFlagName := "annotation" + flags.StringSliceVar( + &playOptions.annotations, + annotationFlagName, []string{}, + "Add annotations to pods (key=value)", + ) + _ = cmd.RegisterFlagCompletionFunc(annotationFlagName, completion.AutocompleteNone) + credsFlagName := "creds" + flags.StringVar(&playOptions.CredentialsCLI, credsFlagName, "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") + _ = cmd.RegisterFlagCompletionFunc(credsFlagName, completion.AutocompleteNone) + + staticMACFlagName := "mac-address" + flags.StringSliceVar(&playOptions.macs, staticMACFlagName, nil, "Static MAC addresses to assign to the pods") + _ = cmd.RegisterFlagCompletionFunc(staticMACFlagName, completion.AutocompleteNone) + + networkFlagName := "network" + flags.StringArrayVar(&playOptions.Networks, networkFlagName, nil, "Connect pod to network(s) or network mode") + _ = cmd.RegisterFlagCompletionFunc(networkFlagName, common.AutocompleteNetworkFlag) + + staticIPFlagName := "ip" + flags.IPSliceVar(&playOptions.StaticIPs, staticIPFlagName, nil, "Static IP addresses to assign to the pods") + _ = cmd.RegisterFlagCompletionFunc(staticIPFlagName, completion.AutocompleteNone) + + logDriverFlagName := "log-driver" + flags.StringVar(&playOptions.LogDriver, logDriverFlagName, common.LogDriver(), "Logging driver for the container") + _ = cmd.RegisterFlagCompletionFunc(logDriverFlagName, common.AutocompleteLogDriver) + + logOptFlagName := "log-opt" + flags.StringSliceVar( + &playOptions.LogOptions, + logOptFlagName, []string{}, + "Logging driver options", + ) + _ = cmd.RegisterFlagCompletionFunc(logOptFlagName, common.AutocompleteLogOpt) + + usernsFlagName := "userns" + flags.StringVar(&playOptions.Userns, usernsFlagName, os.Getenv("PODMAN_USERNS"), + "User namespace to use", + ) + _ = cmd.RegisterFlagCompletionFunc(usernsFlagName, common.AutocompleteUserNamespace) + + flags.BoolVar(&playOptions.NoHosts, "no-hosts", false, "Do not create /etc/hosts within the pod's containers, instead use the version from the image") + flags.BoolVarP(&playOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images") + flags.BoolVar(&playOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries") + flags.BoolVar(&playOptions.StartCLI, "start", true, "Start the pod after creating it") + + authfileFlagName := "authfile" + flags.StringVar(&playOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override") + _ = cmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault) + + downFlagName := "down" + flags.BoolVar(&playOptions.Down, downFlagName, false, "Stop pods defined in the YAML file") + + replaceFlagName := "replace" + flags.BoolVar(&playOptions.Replace, replaceFlagName, false, "Delete and recreate pods defined in the YAML file") + + if !registry.IsRemote() { + certDirFlagName := "cert-dir" + flags.StringVar(&playOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys") + _ = cmd.RegisterFlagCompletionFunc(certDirFlagName, completion.AutocompleteDefault) + + seccompProfileRootFlagName := "seccomp-profile-root" + flags.StringVar(&playOptions.SeccompProfileRoot, seccompProfileRootFlagName, defaultSeccompRoot, "Directory path for seccomp profiles") + _ = cmd.RegisterFlagCompletionFunc(seccompProfileRootFlagName, completion.AutocompleteDefault) + + configmapFlagName := "configmap" + flags.StringSliceVar(&playOptions.ConfigMaps, configmapFlagName, []string{}, "`Pathname` of a YAML file containing a kubernetes configmap") + _ = cmd.RegisterFlagCompletionFunc(configmapFlagName, completion.AutocompleteDefault) + + buildFlagName := "build" + flags.BoolVar(&playOptions.BuildCLI, buildFlagName, false, "Build all images in a YAML (given Containerfiles exist)") + + contextDirFlagName := "context-dir" + flags.StringVar(&playOptions.ContextDir, contextDirFlagName, "", "Path to top level of context directory") + _ = cmd.RegisterFlagCompletionFunc(contextDirFlagName, completion.AutocompleteDefault) + + // NOTE: The service-container flag is marked as hidden as it + // is purely designed for running kube-play in systemd units. + // It is not something users should need to know or care about. + // + // Having a flag rather than an env variable is cleaner. + serviceFlagName := "service-container" + flags.BoolVar(&playOptions.ServiceContainer, serviceFlagName, false, "Starts a service container before all pods") + _ = flags.MarkHidden("service-container") + + flags.StringVar(&playOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)") + + _ = flags.MarkHidden("signature-policy") + } +} + +func Play(cmd *cobra.Command, args []string) error { + // TLS verification in c/image is controlled via a `types.OptionalBool` + // which allows for distinguishing among set-true, set-false, unspecified + // which is important to implement a sane way of dealing with defaults of + // boolean CLI flags. + if cmd.Flags().Changed("tls-verify") { + playOptions.SkipTLSVerify = types.NewOptionalBool(!playOptions.TLSVerifyCLI) + } + if cmd.Flags().Changed("start") { + playOptions.Start = types.NewOptionalBool(playOptions.StartCLI) + } + if cmd.Flags().Changed("build") { + playOptions.Build = types.NewOptionalBool(playOptions.BuildCLI) + } + if playOptions.Authfile != "" { + if _, err := os.Stat(playOptions.Authfile); err != nil { + return err + } + } + if playOptions.ContextDir != "" && playOptions.Build != types.OptionalBoolTrue { + return errors.New("--build must be specified when using --context-dir option") + } + if playOptions.CredentialsCLI != "" { + creds, err := util.ParseRegistryCreds(playOptions.CredentialsCLI) + if err != nil { + return err + } + playOptions.Username = creds.Username + playOptions.Password = creds.Password + } + + for _, annotation := range playOptions.annotations { + splitN := strings.SplitN(annotation, "=", 2) + if len(splitN) > 2 { + return fmt.Errorf("annotation %q must include an '=' sign", annotation) + } + if playOptions.Annotations == nil { + playOptions.Annotations = make(map[string]string) + } + annotation := splitN[1] + if len(annotation) > define.MaxKubeAnnotation { + return fmt.Errorf("annotation exceeds maximum size, %d, of kubernetes annotation: %s", define.MaxKubeAnnotation, annotation) + } + playOptions.Annotations[splitN[0]] = annotation + } + yamlfile := args[0] + if yamlfile == "-" { + yamlfile = "/dev/stdin" + } + + for _, mac := range playOptions.macs { + m, err := net.ParseMAC(mac) + if err != nil { + return err + } + playOptions.StaticMACs = append(playOptions.StaticMACs, m) + } + if playOptions.Down { + return teardown(yamlfile) + } + if playOptions.Replace { + if err := teardown(yamlfile); err != nil && !errorhandling.Contains(err, define.ErrNoSuchPod) { + return err + } + } + return kubeplay(yamlfile) +} + +func playKube(cmd *cobra.Command, args []string) error { + return Play(cmd, args) +} + +func teardown(yamlfile string) error { + var ( + podStopErrors utils.OutputErrors + podRmErrors utils.OutputErrors + ) + options := new(entities.PlayKubeDownOptions) + f, err := os.Open(yamlfile) + if err != nil { + return err + } + defer f.Close() + reports, err := registry.ContainerEngine().PlayKubeDown(registry.GetContext(), f, *options) + if err != nil { + return fmt.Errorf("%v: %w", yamlfile, err) + } + + // Output stopped pods + fmt.Println("Pods stopped:") + for _, stopped := range reports.StopReport { + if len(stopped.Errs) == 0 { + fmt.Println(stopped.Id) + } else { + podStopErrors = append(podStopErrors, stopped.Errs...) + } + } + // Dump any stop errors + lastStopError := podStopErrors.PrintErrors() + if lastStopError != nil { + fmt.Fprintf(os.Stderr, "Error: %s\n", lastStopError) + } + + // Output rm'd pods + fmt.Println("Pods removed:") + for _, removed := range reports.RmReport { + if removed.Err == nil { + fmt.Println(removed.Id) + } else { + podRmErrors = append(podRmErrors, removed.Err) + } + } + return podRmErrors.PrintErrors() +} + +func kubeplay(yamlfile string) error { + f, err := os.Open(yamlfile) + if err != nil { + return err + } + defer f.Close() + report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), f, playOptions.PlayKubeOptions) + if err != nil { + return fmt.Errorf("%s: %w", yamlfile, err) + } + // Print volumes report + for i, volume := range report.Volumes { + if i == 0 { + fmt.Println("Volumes:") + } + fmt.Println(volume.Name) + } + + // Print pods report + for _, pod := range report.Pods { + for _, l := range pod.Logs { + fmt.Fprint(os.Stderr, l) + } + } + + ctrsFailed := 0 + + for _, pod := range report.Pods { + fmt.Println("Pod:") + fmt.Println(pod.ID) + + switch len(pod.Containers) { + case 0: + continue + case 1: + fmt.Println("Container:") + default: + fmt.Println("Containers:") + } + for _, ctr := range pod.Containers { + fmt.Println(ctr) + } + ctrsFailed += len(pod.ContainerErrors) + // If We have errors, add a newline + if len(pod.ContainerErrors) > 0 { + fmt.Println() + } + for _, err := range pod.ContainerErrors { + fmt.Fprintln(os.Stderr, err) + } + // Empty line for space for next block + fmt.Println() + } + + if ctrsFailed > 0 { + return fmt.Errorf("failed to start %d containers", ctrsFailed) + } + + return nil +} diff --git a/cmd/podman/main.go b/cmd/podman/main.go index 929c8a757..dc21807b4 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -9,10 +9,10 @@ import ( _ "github.com/containers/podman/v4/cmd/podman/generate" _ "github.com/containers/podman/v4/cmd/podman/healthcheck" _ "github.com/containers/podman/v4/cmd/podman/images" + _ "github.com/containers/podman/v4/cmd/podman/kube" _ "github.com/containers/podman/v4/cmd/podman/machine" _ "github.com/containers/podman/v4/cmd/podman/manifest" _ "github.com/containers/podman/v4/cmd/podman/networks" - _ "github.com/containers/podman/v4/cmd/podman/play" _ "github.com/containers/podman/v4/cmd/podman/pods" "github.com/containers/podman/v4/cmd/podman/registry" _ "github.com/containers/podman/v4/cmd/podman/secrets" diff --git a/cmd/podman/play/kube.go b/cmd/podman/play/kube.go deleted file mode 100644 index 8fd12baaf..000000000 --- a/cmd/podman/play/kube.go +++ /dev/null @@ -1,327 +0,0 @@ -package pods - -import ( - "errors" - "fmt" - "net" - "os" - "strings" - - "github.com/containers/common/pkg/auth" - "github.com/containers/common/pkg/completion" - "github.com/containers/image/v5/types" - "github.com/containers/podman/v4/cmd/podman/common" - "github.com/containers/podman/v4/cmd/podman/registry" - "github.com/containers/podman/v4/cmd/podman/utils" - "github.com/containers/podman/v4/libpod/define" - "github.com/containers/podman/v4/pkg/domain/entities" - "github.com/containers/podman/v4/pkg/errorhandling" - "github.com/containers/podman/v4/pkg/util" - "github.com/spf13/cobra" -) - -// playKubeOptionsWrapper allows for separating CLI-only fields from API-only -// fields. -type playKubeOptionsWrapper struct { - entities.PlayKubeOptions - - TLSVerifyCLI bool - CredentialsCLI string - StartCLI bool - BuildCLI bool -} - -var ( - annotations []string - macs []string - // https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/ - defaultSeccompRoot = "/var/lib/kubelet/seccomp" - kubeOptions = playKubeOptionsWrapper{} - kubeDescription = `Command reads in a structured file of Kubernetes YAML. - - It creates pods or volumes based on the Kubernetes kind described in the YAML. Supported kinds are Pods, Deployments and PersistentVolumeClaims.` - - kubeCmd = &cobra.Command{ - Use: "kube [options] KUBEFILE|-", - Short: "Play a pod or volume based on Kubernetes YAML.", - Long: kubeDescription, - RunE: kube, - Args: cobra.ExactArgs(1), - ValidArgsFunction: common.AutocompleteDefaultOneArg, - Example: `podman play kube nginx.yml - cat nginx.yml | podman play kube - - podman play kube --creds user:password --seccomp-profile-root /custom/path apache.yml`, - } -) - -func init() { - registry.Commands = append(registry.Commands, registry.CliCommand{ - Command: kubeCmd, - Parent: playCmd, - }) - - flags := kubeCmd.Flags() - flags.SetNormalizeFunc(utils.AliasFlags) - - annotationFlagName := "annotation" - flags.StringSliceVar( - &annotations, - annotationFlagName, []string{}, - "Add annotations to pods (key=value)", - ) - _ = kubeCmd.RegisterFlagCompletionFunc(annotationFlagName, completion.AutocompleteNone) - credsFlagName := "creds" - flags.StringVar(&kubeOptions.CredentialsCLI, credsFlagName, "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") - _ = kubeCmd.RegisterFlagCompletionFunc(credsFlagName, completion.AutocompleteNone) - - staticMACFlagName := "mac-address" - flags.StringSliceVar(&macs, staticMACFlagName, nil, "Static MAC addresses to assign to the pods") - _ = kubeCmd.RegisterFlagCompletionFunc(staticMACFlagName, completion.AutocompleteNone) - - networkFlagName := "network" - flags.StringArrayVar(&kubeOptions.Networks, networkFlagName, nil, "Connect pod to network(s) or network mode") - _ = kubeCmd.RegisterFlagCompletionFunc(networkFlagName, common.AutocompleteNetworkFlag) - - staticIPFlagName := "ip" - flags.IPSliceVar(&kubeOptions.StaticIPs, staticIPFlagName, nil, "Static IP addresses to assign to the pods") - _ = kubeCmd.RegisterFlagCompletionFunc(staticIPFlagName, completion.AutocompleteNone) - - logDriverFlagName := "log-driver" - flags.StringVar(&kubeOptions.LogDriver, logDriverFlagName, common.LogDriver(), "Logging driver for the container") - _ = kubeCmd.RegisterFlagCompletionFunc(logDriverFlagName, common.AutocompleteLogDriver) - - logOptFlagName := "log-opt" - flags.StringSliceVar( - &kubeOptions.LogOptions, - logOptFlagName, []string{}, - "Logging driver options", - ) - _ = kubeCmd.RegisterFlagCompletionFunc(logOptFlagName, common.AutocompleteLogOpt) - - usernsFlagName := "userns" - flags.StringVar(&kubeOptions.Userns, usernsFlagName, os.Getenv("PODMAN_USERNS"), - "User namespace to use", - ) - _ = kubeCmd.RegisterFlagCompletionFunc(usernsFlagName, common.AutocompleteUserNamespace) - - flags.BoolVar(&kubeOptions.NoHosts, "no-hosts", false, "Do not create /etc/hosts within the pod's containers, instead use the version from the image") - flags.BoolVarP(&kubeOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images") - flags.BoolVar(&kubeOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries") - flags.BoolVar(&kubeOptions.StartCLI, "start", true, "Start the pod after creating it") - - authfileFlagName := "authfile" - flags.StringVar(&kubeOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override") - _ = kubeCmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault) - - downFlagName := "down" - flags.BoolVar(&kubeOptions.Down, downFlagName, false, "Stop pods defined in the YAML file") - - replaceFlagName := "replace" - flags.BoolVar(&kubeOptions.Replace, replaceFlagName, false, "Delete and recreate pods defined in the YAML file") - - if !registry.IsRemote() { - certDirFlagName := "cert-dir" - flags.StringVar(&kubeOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys") - _ = kubeCmd.RegisterFlagCompletionFunc(certDirFlagName, completion.AutocompleteDefault) - - seccompProfileRootFlagName := "seccomp-profile-root" - flags.StringVar(&kubeOptions.SeccompProfileRoot, seccompProfileRootFlagName, defaultSeccompRoot, "Directory path for seccomp profiles") - _ = kubeCmd.RegisterFlagCompletionFunc(seccompProfileRootFlagName, completion.AutocompleteDefault) - - configmapFlagName := "configmap" - flags.StringSliceVar(&kubeOptions.ConfigMaps, configmapFlagName, []string{}, "`Pathname` of a YAML file containing a kubernetes configmap") - _ = kubeCmd.RegisterFlagCompletionFunc(configmapFlagName, completion.AutocompleteDefault) - - buildFlagName := "build" - flags.BoolVar(&kubeOptions.BuildCLI, buildFlagName, false, "Build all images in a YAML (given Containerfiles exist)") - - contextDirFlagName := "context-dir" - flags.StringVar(&kubeOptions.ContextDir, contextDirFlagName, "", "Path to top level of context directory") - _ = kubeCmd.RegisterFlagCompletionFunc(contextDirFlagName, completion.AutocompleteDefault) - - // NOTE: The service-container flag is marked as hidden as it - // is purely designed for running play-kube in systemd units. - // It is not something users should need to know or care about. - // - // Having a flag rather than an env variable is cleaner. - serviceFlagName := "service-container" - flags.BoolVar(&kubeOptions.ServiceContainer, serviceFlagName, false, "Starts a service container before all pods") - _ = flags.MarkHidden("service-container") - - flags.StringVar(&kubeOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)") - - _ = flags.MarkHidden("signature-policy") - } -} - -func kube(cmd *cobra.Command, args []string) error { - // TLS verification in c/image is controlled via a `types.OptionalBool` - // which allows for distinguishing among set-true, set-false, unspecified - // which is important to implement a sane way of dealing with defaults of - // boolean CLI flags. - if cmd.Flags().Changed("tls-verify") { - kubeOptions.SkipTLSVerify = types.NewOptionalBool(!kubeOptions.TLSVerifyCLI) - } - if cmd.Flags().Changed("start") { - kubeOptions.Start = types.NewOptionalBool(kubeOptions.StartCLI) - } - if cmd.Flags().Changed("build") { - kubeOptions.Build = types.NewOptionalBool(kubeOptions.BuildCLI) - } - if kubeOptions.Authfile != "" { - if _, err := os.Stat(kubeOptions.Authfile); err != nil { - return err - } - } - if kubeOptions.ContextDir != "" && kubeOptions.Build != types.OptionalBoolTrue { - return errors.New("--build must be specified when using --context-dir option") - } - if kubeOptions.CredentialsCLI != "" { - creds, err := util.ParseRegistryCreds(kubeOptions.CredentialsCLI) - if err != nil { - return err - } - kubeOptions.Username = creds.Username - kubeOptions.Password = creds.Password - } - - for _, annotation := range annotations { - splitN := strings.SplitN(annotation, "=", 2) - if len(splitN) > 2 { - return fmt.Errorf("annotation %q must include an '=' sign", annotation) - } - if kubeOptions.Annotations == nil { - kubeOptions.Annotations = make(map[string]string) - } - annotation := splitN[1] - if len(annotation) > define.MaxKubeAnnotation { - return fmt.Errorf("annotation exceeds maximum size, %d, of kubernetes annotation: %s", define.MaxKubeAnnotation, annotation) - } - kubeOptions.Annotations[splitN[0]] = annotation - } - yamlfile := args[0] - if yamlfile == "-" { - yamlfile = "/dev/stdin" - } - - for _, mac := range macs { - m, err := net.ParseMAC(mac) - if err != nil { - return err - } - kubeOptions.StaticMACs = append(kubeOptions.StaticMACs, m) - } - if kubeOptions.Down { - return teardown(yamlfile) - } - if kubeOptions.Replace { - if err := teardown(yamlfile); err != nil && !errorhandling.Contains(err, define.ErrNoSuchPod) { - return err - } - } - return playkube(yamlfile) -} - -func teardown(yamlfile string) error { - var ( - podStopErrors utils.OutputErrors - podRmErrors utils.OutputErrors - ) - options := new(entities.PlayKubeDownOptions) - f, err := os.Open(yamlfile) - if err != nil { - return err - } - defer f.Close() - reports, err := registry.ContainerEngine().PlayKubeDown(registry.GetContext(), f, *options) - if err != nil { - return fmt.Errorf("%v: %w", yamlfile, err) - } - - // Output stopped pods - fmt.Println("Pods stopped:") - for _, stopped := range reports.StopReport { - if len(stopped.Errs) == 0 { - fmt.Println(stopped.Id) - } else { - podStopErrors = append(podStopErrors, stopped.Errs...) - } - } - // Dump any stop errors - lastStopError := podStopErrors.PrintErrors() - if lastStopError != nil { - fmt.Fprintf(os.Stderr, "Error: %s\n", lastStopError) - } - - // Output rm'd pods - fmt.Println("Pods removed:") - for _, removed := range reports.RmReport { - if removed.Err == nil { - fmt.Println(removed.Id) - } else { - podRmErrors = append(podRmErrors, removed.Err) - } - } - return podRmErrors.PrintErrors() -} - -func playkube(yamlfile string) error { - f, err := os.Open(yamlfile) - if err != nil { - return err - } - defer f.Close() - report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), f, kubeOptions.PlayKubeOptions) - if err != nil { - return fmt.Errorf("%s: %w", yamlfile, err) - } - // Print volumes report - for i, volume := range report.Volumes { - if i == 0 { - fmt.Println("Volumes:") - } - fmt.Println(volume.Name) - } - - // Print pods report - for _, pod := range report.Pods { - for _, l := range pod.Logs { - fmt.Fprint(os.Stderr, l) - } - } - - ctrsFailed := 0 - - for _, pod := range report.Pods { - fmt.Println("Pod:") - fmt.Println(pod.ID) - - switch len(pod.Containers) { - case 0: - continue - case 1: - fmt.Println("Container:") - default: - fmt.Println("Containers:") - } - for _, ctr := range pod.Containers { - fmt.Println(ctr) - } - ctrsFailed += len(pod.ContainerErrors) - // If We have errors, add a newline - if len(pod.ContainerErrors) > 0 { - fmt.Println() - } - for _, err := range pod.ContainerErrors { - fmt.Fprintln(os.Stderr, err) - } - // Empty line for space for next block - fmt.Println() - } - - if ctrsFailed > 0 { - return fmt.Errorf("failed to start %d containers", ctrsFailed) - } - - return nil -} diff --git a/cmd/podman/play/play.go b/cmd/podman/play/play.go deleted file mode 100644 index e277ec9bd..000000000 --- a/cmd/podman/play/play.go +++ /dev/null @@ -1,23 +0,0 @@ -package pods - -import ( - "github.com/containers/podman/v4/cmd/podman/registry" - "github.com/containers/podman/v4/cmd/podman/validate" - "github.com/spf13/cobra" -) - -var ( - // Command: podman _play_ - playCmd = &cobra.Command{ - Use: "play", - Short: "Play containers, pods or volumes from a structured file", - Long: "Play structured data (e.g., Kubernetes YAML) based on containers, pods or volumes.", - RunE: validate.SubCommandExists, - } -) - -func init() { - registry.Commands = append(registry.Commands, registry.CliCommand{ - Command: playCmd, - }) -} diff --git a/docs/kubernetes_support.md b/docs/kubernetes_support.md new file mode 100644 index 000000000..851e692cb --- /dev/null +++ b/docs/kubernetes_support.md @@ -0,0 +1,175 @@ +# Podman Kube Play Support + +This document outlines the kube yaml fields that are currently supported by the **podman kube play** command. + +Note: **N/A** means that the option cannot be supported in a single-node Podman environment. + +## Pod Fields + +| Field | Support | +|---------------------------------------------------|---------| +| containers | ✅ | +| initContainers | ✅ | +| imagePullSecrets | | +| enableServiceLinks | | +| os.name | | +| volumes | | +| nodeSelector | N/A | +| nodeName | N/A | +| affinity.nodeAffinity | N/A | +| affinity.podAffinity | N/A | +| affinity.podAntiAffinity | N/A | +| tolerations.key | N/A | +| tolerations.operator | N/A | +| tolerations.effect | N/A | +| tolerations.tolerationSeconds | N/A | +| schedulerName | N/A | +| runtimeClassName | | +| priorityClassName | | +| priority | | +| topologySpreadConstraints.maxSkew | N/A | +| topologySpreadConstraints.topologyKey | N/A | +| topologySpreadConstraints.whenUnsatisfiable | N/A | +| topologySpreadConstraints.labelSelector | N/A | +| topologySpreadConstraints.minDomains | N/A | +| restartPolicy | ✅ | +| terminationGracePeriod | | +| activeDeadlineSeconds | | +| readinessGates.conditionType | | +| hostname | ✅ | +| setHostnameAsFQDN | | +| subdomain | | +| hostAliases.hostnames | ✅ | +| hostAliases.ip | ✅ | +| dnsConfig.nameservers | ✅ | +| dnsConfig.options.name | ✅ | +| dnsConfig.options.value | ✅ | +| dnsConfig.searches | ✅ | +| dnsPolicy | | +| hostNetwork | ✅ | +| hostPID | | +| hostIPC | | +| shareProcessNamespace | ✅ | +| serviceAccountName | | +| automountServiceAccountToken | | +| securityContext.runAsUser | | +| securityContext.runAsNonRoot | | +| securityContext.runAsGroup | | +| securityContext.supplementalGroups | | +| securityContext.fsGroup | | +| securityContext.fsGroupChangePolicy | | +| securityContext.seccompProfile.type | | +| securityContext.seccompProfile.localhostProfile | | +| securityContext.seLinuxOptions.level | | +| securityContext.seLinuxOptions.role | | +| securityContext.seLinuxOptions.type | | +| securityContext.seLinuxOptions.user | | +| securityContext.sysctls.name | | +| securityContext.sysctls.value | | +| securityContext.windowsOptions.gmsaCredentialSpec | | +| securityContext.windowsOptions.hostProcess | | +| securityContext.windowsOptions.runAsUserName | | + +## Container Fields + +| Field | Support | +|---------------------------------------------------|---------| +| name | ✅ | +| image | ✅ | +| imagePullPolicy | ✅ | +| command | ✅ | +| args | ✅ | +| workingDir | ✅ | +| ports.containerPort | ✅ | +| ports.hostIP | ✅ | +| ports.hostPort | ✅ | +| ports.name | ✅ | +| ports.protocol | ✅ | +| env.name | ✅ | +| env.value | ✅ | +| env.valueFrom.configMapKeyRef.key | ✅ | +| env.valueFrom.configMapKeyRef.name | ✅ | +| env.valueFrom.configMapKeyRef.optional | ✅ | +| env.valueFrom.fieldRef | ✅ | +| env.valueFrom.resourceFieldRef | ✅ | +| env.valueFrom.secretKeyRef.key | ✅ | +| env.valueFrom.secretKeyRef.name | ✅ | +| env.valueFrom.secretKeyRef.optional | ✅ | +| envFrom.configMapRef.name | ✅ | +| envFrom.configMapRef.optional | ✅ | +| envFrom.prefix | | +| envFrom.secretRef.name | ✅ | +| envFrom.secretRef.optional | ✅ | +| volumeMounts.mountPath | ✅ | +| volumeMounts.name | ✅ | +| volumeMounts.mountPropagation | | +| volumeMounts.readOnly | ✅ | +| volumeMounts.subPath | | +| volumeMounts.subPathExpr | | +| volumeDevices.devicePath | | +| volumeDevices.name | | +| resources.limits | ✅ | +| resources.requests | ✅ | +| lifecycle.postStart | | +| lifecycle.preStop | | +| terminationMessagePath | | +| terminationMessagePolicy | | +| livenessProbe | ✅ | +| readinessProbe | | +| startupProbe | | +| securityContext.runAsUser | ✅ | +| securityContext.runAsNonRoot | | +| securityContext.runAsGroup | ✅ | +| securityContext.readOnlyRootFilesystem | ✅ | +| securityContext.procMount | | +| securityContext.privileged | ✅ | +| securityContext.allowPrivilegeEscalation | ✅ | +| securityContext.capabilities.add | ✅ | +| securityContext.capabilities.drop | ✅ | +| securityContext.seccompProfile.type | | +| securityContext.seccompProfile.localhostProfile | | +| securityContext.seLinuxOptions.level | ✅ | +| securityContext.seLinuxOptions.role | ✅ | +| securityContext.seLinuxOptions.type | ✅ | +| securityContext.seLinuxOptions.user | ✅ | +| securityContext.windowsOptions.gmsaCredentialSpec | | +| securityContext.windowsOptions.hostProcess | | +| securityContext.windowsOptions.runAsUserName | | +| stdin | | +| stdinOnce | | +| tty | | + +## PersistentVolumeClaim Fields + +| Field | Support | +|--------------------|---------| +| volumeName | | +| storageClassName | ✅ | +| volumeMode | | +| accessModes | ✅ | +| selector | | +| resources.limits | | +| resources.requests | ✅ | + +## ConfigMap Fields + +| Field | Support | +|------------|---------| +| binaryData | | +| data | ✅ | +| immutable | | + +## Deployment Fields + +| Field | Support | +|---------------------------------------|---------| +| replicas | ✅ | +| selector | ✅ | +| template | ✅ | +| minReadySeconds | | +| strategy.type | | +| strategy.rollingUpdate.maxSurge | | +| strategy.rollingUpdate.maxUnavailable | | +| revisionHistoryLimit | | +| progressDeadlineSeconds | | +| paused | | diff --git a/docs/play_kube_support.md b/docs/play_kube_support.md deleted file mode 100644 index 3cfd3fa50..000000000 --- a/docs/play_kube_support.md +++ /dev/null @@ -1,175 +0,0 @@ -# Podman Play Kube Support - -This document outlines the kube yaml fields that are currently supported by the **podman play kube** command. - -Note: **N/A** means that the option cannot be supported in a single-node Podman environment. - -## Pod Fields - -| Field | Support | -|---------------------------------------------------|---------| -| containers | ✅ | -| initContainers | ✅ | -| imagePullSecrets | | -| enableServiceLinks | | -| os.name | | -| volumes | | -| nodeSelector | N/A | -| nodeName | N/A | -| affinity.nodeAffinity | N/A | -| affinity.podAffinity | N/A | -| affinity.podAntiAffinity | N/A | -| tolerations.key | N/A | -| tolerations.operator | N/A | -| tolerations.effect | N/A | -| tolerations.tolerationSeconds | N/A | -| schedulerName | N/A | -| runtimeClassName | | -| priorityClassName | | -| priority | | -| topologySpreadConstraints.maxSkew | N/A | -| topologySpreadConstraints.topologyKey | N/A | -| topologySpreadConstraints.whenUnsatisfiable | N/A | -| topologySpreadConstraints.labelSelector | N/A | -| topologySpreadConstraints.minDomains | N/A | -| restartPolicy | ✅ | -| terminationGracePeriod | | -| activeDeadlineSeconds | | -| readinessGates.conditionType | | -| hostname | ✅ | -| setHostnameAsFQDN | | -| subdomain | | -| hostAliases.hostnames | ✅ | -| hostAliases.ip | ✅ | -| dnsConfig.nameservers | ✅ | -| dnsConfig.options.name | ✅ | -| dnsConfig.options.value | ✅ | -| dnsConfig.searches | ✅ | -| dnsPolicy | | -| hostNetwork | ✅ | -| hostPID | | -| hostIPC | | -| shareProcessNamespace | ✅ | -| serviceAccountName | | -| automountServiceAccountToken | | -| securityContext.runAsUser | | -| securityContext.runAsNonRoot | | -| securityContext.runAsGroup | | -| securityContext.supplementalGroups | | -| securityContext.fsGroup | | -| securityContext.fsGroupChangePolicy | | -| securityContext.seccompProfile.type | | -| securityContext.seccompProfile.localhostProfile | | -| securityContext.seLinuxOptions.level | | -| securityContext.seLinuxOptions.role | | -| securityContext.seLinuxOptions.type | | -| securityContext.seLinuxOptions.user | | -| securityContext.sysctls.name | | -| securityContext.sysctls.value | | -| securityContext.windowsOptions.gmsaCredentialSpec | | -| securityContext.windowsOptions.hostProcess | | -| securityContext.windowsOptions.runAsUserName | | - -## Container Fields - -| Field | Support | -|---------------------------------------------------|---------| -| name | ✅ | -| image | ✅ | -| imagePullPolicy | ✅ | -| command | ✅ | -| args | ✅ | -| workingDir | ✅ | -| ports.containerPort | ✅ | -| ports.hostIP | ✅ | -| ports.hostPort | ✅ | -| ports.name | ✅ | -| ports.protocol | ✅ | -| env.name | ✅ | -| env.value | ✅ | -| env.valueFrom.configMapKeyRef.key | ✅ | -| env.valueFrom.configMapKeyRef.name | ✅ | -| env.valueFrom.configMapKeyRef.optional | ✅ | -| env.valueFrom.fieldRef | ✅ | -| env.valueFrom.resourceFieldRef | ✅ | -| env.valueFrom.secretKeyRef.key | ✅ | -| env.valueFrom.secretKeyRef.name | ✅ | -| env.valueFrom.secretKeyRef.optional | ✅ | -| envFrom.configMapRef.name | ✅ | -| envFrom.configMapRef.optional | ✅ | -| envFrom.prefix | | -| envFrom.secretRef.name | ✅ | -| envFrom.secretRef.optional | ✅ | -| volumeMounts.mountPath | ✅ | -| volumeMounts.name | ✅ | -| volumeMounts.mountPropagation | | -| volumeMounts.readOnly | ✅ | -| volumeMounts.subPath | | -| volumeMounts.subPathExpr | | -| volumeDevices.devicePath | | -| volumeDevices.name | | -| resources.limits | ✅ | -| resources.requests | ✅ | -| lifecycle.postStart | | -| lifecycle.preStop | | -| terminationMessagePath | | -| terminationMessagePolicy | | -| livenessProbe | ✅ | -| readinessProbe | | -| startupProbe | | -| securityContext.runAsUser | ✅ | -| securityContext.runAsNonRoot | | -| securityContext.runAsGroup | ✅ | -| securityContext.readOnlyRootFilesystem | ✅ | -| securityContext.procMount | | -| securityContext.privileged | ✅ | -| securityContext.allowPrivilegeEscalation | ✅ | -| securityContext.capabilities.add | ✅ | -| securityContext.capabilities.drop | ✅ | -| securityContext.seccompProfile.type | | -| securityContext.seccompProfile.localhostProfile | | -| securityContext.seLinuxOptions.level | ✅ | -| securityContext.seLinuxOptions.role | ✅ | -| securityContext.seLinuxOptions.type | ✅ | -| securityContext.seLinuxOptions.user | ✅ | -| securityContext.windowsOptions.gmsaCredentialSpec | | -| securityContext.windowsOptions.hostProcess | | -| securityContext.windowsOptions.runAsUserName | | -| stdin | | -| stdinOnce | | -| tty | | - -## PersistentVolumeClaim Fields - -| Field | Support | -|--------------------|---------| -| volumeName | | -| storageClassName | ✅ | -| volumeMode | | -| accessModes | ✅ | -| selector | | -| resources.limits | | -| resources.requests | ✅ | - -## ConfigMap Fields - -| Field | Support | -|------------|---------| -| binaryData | | -| data | ✅ | -| immutable | | - -## Deployment Fields - -| Field | Support | -|---------------------------------------|---------| -| replicas | ✅ | -| selector | ✅ | -| template | ✅ | -| minReadySeconds | | -| strategy.type | | -| strategy.rollingUpdate.maxSurge | | -| strategy.rollingUpdate.maxUnavailable | | -| revisionHistoryLimit | | -| progressDeadlineSeconds | | -| paused | | diff --git a/docs/source/Commands.rst b/docs/source/Commands.rst index 2911efe18..6b26ed1d9 100644 --- a/docs/source/Commands.rst +++ b/docs/source/Commands.rst @@ -47,6 +47,8 @@ Commands :doc:`kill ` Kill one or more running containers with a specific signal +:doc:`kube ` Play a pod + :doc:`load ` Load an image from container archive :doc:`login ` Login to a container registry @@ -65,8 +67,6 @@ Commands :doc:`pause ` Pause all the processes in one or more containers -:doc:`play ` Play a pod - :doc:`pod ` Manage pods :doc:`port ` List port mappings or a specific mapping for the container diff --git a/docs/source/markdown/links/podman-play-kube.1 b/docs/source/markdown/links/podman-play-kube.1 new file mode 100644 index 000000000..ffa073b9a --- /dev/null +++ b/docs/source/markdown/links/podman-play-kube.1 @@ -0,0 +1 @@ +.so man1/podman-kube-play.1 diff --git a/docs/source/markdown/podman-generate-kube.1.md b/docs/source/markdown/podman-generate-kube.1.md index cbb875f60..9b8aa5b80 100644 --- a/docs/source/markdown/podman-generate-kube.1.md +++ b/docs/source/markdown/podman-generate-kube.1.md @@ -213,7 +213,7 @@ status: ``` ## SEE ALSO -**[podman(1)](podman.1.md)**, **[podman-container(1)](podman-container.1.md)**, **[podman-pod(1)](podman-pod.1.md)**, **[podman-play-kube(1)](podman-play-kube.1.md)** +**[podman(1)](podman.1.md)**, **[podman-container(1)](podman-container.1.md)**, **[podman-pod(1)](podman-pod.1.md)**, **[podman-kube-play(1)](podman-kube-play.1.md)** ## HISTORY December 2018, Originally compiled by Brent Baude (bbaude at redhat dot com) diff --git a/docs/source/markdown/podman-generate-systemd.1.md b/docs/source/markdown/podman-generate-systemd.1.md index 56ad4e446..3d63c83c0 100644 --- a/docs/source/markdown/podman-generate-systemd.1.md +++ b/docs/source/markdown/podman-generate-systemd.1.md @@ -55,7 +55,7 @@ Use the name of the container for the start, stop, and description in the unit f Using this flag will yield unit files that do not expect containers and pods to exist. Instead, new containers and pods are created based on their configuration files. The unit files are created best effort and may need to be further edited; please review the generated files carefully before using them in production. -Note that `--new` only works on containers and pods created directly via Podman (i.e., `podman [container] {create,run}` or `podman pod create`). It does not work on containers or pods created via the REST API or via `podman play kube`. +Note that `--new` only works on containers and pods created directly via Podman (i.e., `podman [container] {create,run}` or `podman pod create`). It does not work on containers or pods created via the REST API or via `podman kube play`. #### **--no-header** diff --git a/docs/source/markdown/podman-kube-play.1.md b/docs/source/markdown/podman-kube-play.1.md new file mode 100644 index 000000000..37d2069e0 --- /dev/null +++ b/docs/source/markdown/podman-kube-play.1.md @@ -0,0 +1,331 @@ +% podman-kube-play(1) + +## NAME +podman-kube-play - Create containers, pods or volumes based on Kubernetes YAML + +## SYNOPSIS +**podman kube play** [*options*] *file.yml|-* + +## DESCRIPTION +**podman kube play** will read in a structured file of Kubernetes YAML. It will then recreate the containers, pods or volumes described in the YAML. Containers within a pod are then started and the ID of the new Pod or the name of the new Volume is output. If the yaml file is specified as "-" then `podman kube play` will read the YAML file from stdin. +Using the `--down` command line option, it is also capable of tearing down the pods created by a previous run of `podman kube play`. +Using the `--replace` command line option, it will tear down the pods(if any) created by a previous run of `podman kube play` and recreate the pods with the Kubernetes YAML file. +Ideally the input file would be one created by Podman (see podman-generate-kube(1)). This would guarantee a smooth import and expected results. + +Currently, the supported Kubernetes kinds are: +- Pod +- Deployment +- PersistentVolumeClaim +- ConfigMap + +`Kubernetes Pods or Deployments` + +Only two volume types are supported by kube play, the *hostPath* and *persistentVolumeClaim* volume types. For the *hostPath* volume type, only the *default (empty)*, *DirectoryOrCreate*, *Directory*, *FileOrCreate*, *File*, *Socket*, *CharDevice* and *BlockDevice* subtypes are supported. Podman interprets the value of *hostPath* *path* as a file path when it contains at least one forward slash, otherwise Podman treats the value as the name of a named volume. When using a *persistentVolumeClaim*, the value for *claimName* is the name for the Podman named volume. + +Note: When playing a kube YAML with init containers, the init container will be created with init type value `always`. + +Note: *hostPath* volume types created by kube play will be given an SELinux shared label (z), bind mounts are not relabeled (use `chcon -t container_file_t -R `). + +Note: If the `:latest` tag is used, Podman will attempt to pull the image from a registry. If the image was built locally with Podman or Buildah, it will have `localhost` as the domain, in that case, Podman will use the image from the local store even if it has the `:latest` tag. + +Note: The command `podman play kube` is an alias of `podman kube play`, and will perform the same function. + +`Kubernetes PersistentVolumeClaims` + +A Kubernetes PersistentVolumeClaim represents a Podman named volume. Only the PersistentVolumeClaim name is required by Podman to create a volume. Kubernetes annotations can be used to make use of the available options for Podman volumes. + +- volume.podman.io/driver +- volume.podman.io/device +- volume.podman.io/type +- volume.podman.io/uid +- volume.podman.io/gid +- volume.podman.io/mount-options + +Kube play is capable of building images on the fly given the correct directory layout and Containerfiles. This +option is not available for remote clients, including Mac and Windows (excluding WSL2) machines, yet. Consider the following excerpt from a YAML file: +``` +apiVersion: v1 +kind: Pod +metadata: +... +spec: + containers: + - command: + - top + - name: container + value: podman + image: foobar +... +``` + +If there is a directory named `foobar` in the current working directory with a file named `Containerfile` or `Dockerfile`, +Podman kube play will build that image and name it `foobar`. An example directory structure for this example would look +like: +``` +|- mykubefiles + |- myplayfile.yaml + |- foobar + |- Containerfile +``` + +The build will consider `foobar` to be the context directory for the build. If there is an image in local storage +called `foobar`, the image will not be built unless the `--build` flag is used. Use `--build=false` to completely +disable builds. + +`Kubernetes ConfigMap` + +Kubernetes ConfigMap can be referred as a source of environment variables or volumes in Pods or Deployments. +ConfigMaps aren't a standalone object in Podman; instead, when a container uses a ConfigMap, Podman will create environment variables or volumes as needed. + +For example, the following YAML document defines a ConfigMap and then uses it in a Pod: + +``` +apiVersion: v1 +kind: ConfigMap +metadata: + name: foo +data: + FOO: bar +--- +apiVersion: v1 +kind: Pod +metadata: + name: foobar +spec: + containers: + - command: + - top + name: container-1 + image: foobar + envFrom: + - configMapRef: + name: foo + optional: false +``` + +and as a result environment variable `FOO` will be set to `bar` for container `container-1`. + +## OPTIONS + +#### **--annotation**=*key=value* + +Add an annotation to the container or pod. The format is key=value. +The **--annotation** option can be set multiple times. + +#### **--authfile**=*path* + +Path of the authentication file. Default is ${XDG\_RUNTIME\_DIR}/containers/auth.json, which is set using `podman login`. +If the authorization state is not found there, $HOME/.docker/config.json is checked, which is set using `docker login`. + +Note: You can also override the default path of the authentication file by setting the REGISTRY\_AUTH\_FILE +environment variable. `export REGISTRY_AUTH_FILE=path` + +#### **--build** + +Build images even if they are found in the local storage. Use `--build=false` to completely disable builds. (This option is not available with the remote Podman client) + +#### **--cert-dir**=*path* + +Use certificates at *path* (\*.crt, \*.cert, \*.key) to connect to the registry. (Default: /etc/containers/certs.d) +Please refer to containers-certs.d(5) for details. (This option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines) + +#### **--configmap**=*path* + +Use Kubernetes configmap YAML at path to provide a source for environment variable values within the containers of the pod. (This option is not available with the remote Podman client) + +Note: The *--configmap* option can be used multiple times or a comma-separated list of paths can be used to pass multiple Kubernetes configmap YAMLs. + +#### **--context-dir**=*path* + +Use *path* as the build context directory for each image. Requires --build option be true. (This option is not available with the remote Podman client) + +#### **--creds** + +The [username[:password]] to use to authenticate with the registry if required. +If one or both values are not supplied, a command line prompt will appear and the +value can be entered. The password is entered without echo. + +#### **--down** + +Tears down the pods that were created by a previous run of `kube play`. The pods are stopped and then +removed. Any volumes created are left intact. + +#### **--help**, **-h** + +Print usage statement + +#### **--ip**=*IP address* + +Assign a static ip address to the pod. This option can be specified several times when kube play creates more than one pod. +Note: When joining multiple networks you should use the **--network name:ip=\** syntax. + +#### **--log-driver**=driver + +Set logging driver for all created containers. + +#### **--log-opt**=*name*=*value* + +Set custom logging configuration. The following *name*s are supported: + +- **path**: specify a path to the log file +(e.g. **--log-opt path=/var/log/container/mycontainer.json**); + +- **max-size**: specify a max size of the log file +(e.g. **--log-opt max-size=10mb**); + +- **tag**: specify a custom log tag for the container +(e.g. **--log-opt tag="{{.ImageName}}"**. + +It supports the same keys as **podman inspect --format**. + +This option is currently supported only by the **journald** log driver. + +#### **--mac-address**=*MAC address* + +Assign a static mac address to the pod. This option can be specified several times when kube play creates more than one pod. +Note: When joining multiple networks you should use the **--network name:mac=\** syntax. + +#### **--network**=*mode*, **--net** + +Change the network mode of the pod. The host network mode should be configured in the YAML file. +Valid _mode_ values are: + +- **bridge[:OPTIONS,...]**: Create a network stack on the default bridge. This is the default for rootful containers. It is possible to specify these additional options: + - **alias=name**: Add network-scoped alias for the container. + - **ip=IPv4**: Specify a static ipv4 address for this container. + - **ip=IPv6**: Specify a static ipv6 address for this container. + - **mac=MAC**: Specify a static mac address for this container. + - **interface_name**: Specify a name for the created network interface inside the container. + + For example to set a static ipv4 address and a static mac address, use `--network bridge:ip=10.88.0.10,mac=44:33:22:11:00:99`. +- \[:OPTIONS,...]: Connect to a user-defined network; this is the network name or ID from a network created by **[podman network create](podman-network-create.1.md)**. Using the network name implies the bridge network mode. It is possible to specify the same options described under the bridge mode above. You can use the **--network** option multiple times to specify additional networks. +- **none**: Create a network namespace for the container but do not configure network interfaces for it, thus the container has no network connectivity. +- **container:**_id_: Reuse another container's network stack. +- **ns:**_path_: Path to a network namespace to join. +- **private**: Create a new namespace for the container. This will use the **bridge** mode for rootful containers and **slirp4netns** for rootless ones. +- **slirp4netns[:OPTIONS,...]**: use **slirp4netns**(1) to create a user network stack. This is the default for rootless containers. It is possible to specify these additional options, they can also be set with `network_cmd_options` in containers.conf: + - **allow_host_loopback=true|false**: Allow the slirp4netns to reach the host loopback IP (`10.0.2.2`). Default is false. + - **mtu=MTU**: Specify the MTU to use for this network. (Default is `65520`). + - **cidr=CIDR**: Specify ip range to use for this network. (Default is `10.0.2.0/24`). + - **enable_ipv6=true|false**: Enable IPv6. Default is true. (Required for `outbound_addr6`). + - **outbound_addr=INTERFACE**: Specify the outbound interface slirp should bind to (ipv4 traffic only). + - **outbound_addr=IPv4**: Specify the outbound ipv4 address slirp should bind to. + - **outbound_addr6=INTERFACE**: Specify the outbound interface slirp should bind to (ipv6 traffic only). + - **outbound_addr6=IPv6**: Specify the outbound ipv6 address slirp should bind to. + - **port_handler=rootlesskit**: Use rootlesskit for port forwarding. Default. + Note: Rootlesskit changes the source IP address of incoming packets to an IP address in the container network namespace, usually `10.0.2.100`. If your application requires the real source IP address, e.g. web server logs, use the slirp4netns port handler. The rootlesskit port handler is also used for rootless containers when connected to user-defined networks. + - **port_handler=slirp4netns**: Use the slirp4netns port forwarding, it is slower than rootlesskit but preserves the correct source IP address. This port handler cannot be used for user-defined networks. + +#### **--no-hosts** + +Do not create /etc/hosts for the pod. +By default, Podman will manage /etc/hosts, adding the container's own IP address and any hosts from **--add-host**. +**--no-hosts** disables this, and the image's **/etc/host** will be preserved unmodified. +This option conflicts with host added in the Kubernetes YAML. + +#### **--quiet**, **-q** + +Suppress output information when pulling images + +#### **--replace** + +Tears down the pods created by a previous run of `kube play` and recreates the pods. This option is used to keep the existing pods up to date based upon the Kubernetes YAML. + +#### **--seccomp-profile-root**=*path* + +Directory path for seccomp profiles (default: "/var/lib/kubelet/seccomp"). (This option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines) + +#### **--start** + +Start the pod after creating it, set to false to only create it. + +#### **--tls-verify** + +Require HTTPS and verify certificates when contacting registries (default: true). If explicitly set to true, +then TLS verification will be used. If set to false, then TLS verification will not be used. If not specified, +TLS verification will be used unless the target registry is listed as an insecure registry in registries.conf. + +#### **--userns**=*mode* + +Set the user namespace mode for the container. It defaults to the **PODMAN_USERNS** environment variable. An empty value ("") means user namespaces are disabled unless an explicit mapping is set with the **--uidmap** and **--gidmap** options. + +Rootless user --userns=Key mappings: + +Key | Host User | Container User +----------|---------------|--------------------- +"" |$UID |0 (Default User account mapped to root user in container.) +keep-id |$UID |$UID (Map user account to same UID within container.) +auto |$UID | nil (Host User UID is not mapped into container.) +nomap |$UID | nil (Host User UID is not mapped into container.) + +Valid _mode_ values are: + +**auto**[:_OPTIONS,..._]: automatically create a unique user namespace. + +The `--userns=auto` flag, requires that the user name `containers` and a range of subordinate user ids that the Podman container is allowed to use be specified in the /etc/subuid and /etc/subgid files. + +Example: `containers:2147483647:2147483648`. + +Podman allocates unique ranges of UIDs and GIDs from the `containers` subordinate user ids. The size of the ranges is based on the number of UIDs required in the image. The number of UIDs and GIDs can be overridden with the `size` option. The `auto` options currently does not work in rootless mode + + Valid `auto` options: + + - *gidmapping*=_CONTAINER_GID:HOST_GID:SIZE_: to force a GID mapping to be present in the user namespace. + - *size*=_SIZE_: to specify an explicit size for the automatic user namespace. e.g. `--userns=auto:size=8192`. If `size` is not specified, `auto` will estimate a size for the user namespace. + - *uidmapping*=_CONTAINER_UID:HOST_UID:SIZE_: to force a UID mapping to be present in the user namespace. + +**container:**_id_: join the user namespace of the specified container. + +**host**: create a new namespace for the container. + +**keep-id**: creates a user namespace where the current rootless user's UID:GID are mapped to the same values in the container. This option is not allowed for containers created by the root user. + +**nomap**: creates a user namespace where the current rootless user's UID:GID are not mapped into the container. This option is not allowed for containers created by the root user. + +**ns:**_namespace_: run the pod in the given existing user namespace. + +## EXAMPLES + +Recreate the pod and containers as described in a file called `demo.yml` +``` +$ podman kube play demo.yml +52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 +``` + +Recreate the pod and containers as described in a file `demo.yml` sent to stdin +``` +$ cat demo.yml | podman kube play - +52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 + +``` +Teardown the pod and containers as described in a file `demo.yml` +``` +$ podman kube play --down demo.yml +Pods stopped: +52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 +Pods removed: +52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 +``` + +Provide `configmap-foo.yml` and `configmap-bar.yml` as sources for environment variables within the containers. +``` +$ podman kube play demo.yml --configmap configmap-foo.yml,configmap-bar.yml +52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 + +$ podman kube play demo.yml --configmap configmap-foo.yml --configmap configmap-bar.yml +52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 +``` + +Create a pod connected to two networks (called net1 and net2) with a static ip +``` +$ podman kube play demo.yml --network net1:ip=10.89.1.5 --network net2:ip=10.89.10.10 +52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 +``` + +Please take into account that CNI networks must be created first using podman-network-create(1). + +## SEE ALSO +**[podman(1)](podman.1.md)**, **[podman-kube(1)](podman-kube.1.md)**, **[podman-network-create(1)](podman-network-create.1.md)**, **[podman-generate-kube(1)](podman-generate-kube.1.md)**, **[containers-certs.d(5)](https://github.com/containers/image/blob/main/docs/containers-certs.d.5.md)** + +## HISTORY +December 2018, Originally compiled by Brent Baude (bbaude at redhat dot com) diff --git a/docs/source/markdown/podman-kube.1.md b/docs/source/markdown/podman-kube.1.md new file mode 100644 index 000000000..f815ffae2 --- /dev/null +++ b/docs/source/markdown/podman-kube.1.md @@ -0,0 +1,20 @@ +% podman-kube(1) + +## NAME +podman\-kube - Play containers, pods or volumes based on a structured input file + +## SYNOPSIS +**podman kube** *subcommand* + +## DESCRIPTION +The kube command will recreate containers, pods or volumes based on the input from a structured (like YAML) +file input. Containers will be automatically started. + +## COMMANDS + +| Command | Man Page | Description | +| ------- | --------------------------------------------------- | ---------------------------------------------------------------------------- | +| play | [podman-kube-play(1)](podman-kube-play.1.md) | Create containers, pods or volumes based on Kubernetes YAML. | + +## SEE ALSO +**[podman(1)](podman.1.md)**, **[podman-pod(1)](podman-pod.1.md)**, **[podman-container(1)](podman-container.1.md)**, **[podman-generate(1)](podman-generate.1.md)**, **[podman-kube-play(1)](podman-kube-play.1.md)** diff --git a/docs/source/markdown/podman-play-kube.1.md b/docs/source/markdown/podman-play-kube.1.md deleted file mode 100644 index 92cb694b0..000000000 --- a/docs/source/markdown/podman-play-kube.1.md +++ /dev/null @@ -1,342 +0,0 @@ -% podman-play-kube(1) - -## NAME -podman-play-kube - Create containers, pods or volumes based on Kubernetes YAML - -## SYNOPSIS -**podman play kube** [*options*] *file.yml|-* - -## DESCRIPTION -**podman play kube** will read in a structured file of Kubernetes YAML. It will then recreate the containers, pods or volumes described in the YAML. Containers within a pod are then started and the ID of the new Pod or the name of the new Volume is output. If the yaml file is specified as "-" then `podman play kube` will read the YAML file from stdin. -Using the `--down` command line option, it is also capable of tearing down the pods created by a previous run of `podman play kube`. -Using the `--replace` command line option, it will tear down the pods(if any) created by a previous run of `podman play kube` and recreate the pods with the Kubernetes YAML file. -Ideally the input file would be one created by Podman (see podman-generate-kube(1)). This would guarantee a smooth import and expected results. - -Currently, the supported Kubernetes kinds are: -- Pod -- Deployment -- PersistentVolumeClaim -- ConfigMap - -`Kubernetes Pods or Deployments` - -Only two volume types are supported by play kube, the *hostPath* and *persistentVolumeClaim* volume types. For the *hostPath* volume type, only the *default (empty)*, *DirectoryOrCreate*, *Directory*, *FileOrCreate*, *File*, *Socket*, *CharDevice* and *BlockDevice* subtypes are supported. Podman interprets the value of *hostPath* *path* as a file path when it contains at least one forward slash, otherwise Podman treats the value as the name of a named volume. When using a *persistentVolumeClaim*, the value for *claimName* is the name for the Podman named volume. - -Note: When playing a kube YAML with init containers, the init container will be created with init type value `always`. - -Note: *hostPath* volume types created by play kube will be given an SELinux shared label (z), bind mounts are not relabeled (use `chcon -t container_file_t -R `). - -Note: If the `:latest` tag is used, Podman will attempt to pull the image from a registry. If the image was built locally with Podman or Buildah, it will have `localhost` as the domain, in that case, Podman will use the image from the local store even if it has the `:latest` tag. - -`Kubernetes PersistentVolumeClaims` - -A Kubernetes PersistentVolumeClaim represents a Podman named volume. Only the PersistentVolumeClaim name is required by Podman to create a volume. Kubernetes annotations can be used to make use of the available options for Podman volumes. - -- volume.podman.io/driver -- volume.podman.io/device -- volume.podman.io/type -- volume.podman.io/uid -- volume.podman.io/gid -- volume.podman.io/mount-options - -Play kube is capable of building images on the fly given the correct directory layout and Containerfiles. This -option is not available for remote clients, including Mac and Windows (excluding WSL2) machines, yet. Consider the following excerpt from a YAML file: -``` -apiVersion: v1 -kind: Pod -metadata: -... -spec: - containers: - - command: - - top - - name: container - value: podman - image: foobar -... -``` - -If there is a directory named `foobar` in the current working directory with a file named `Containerfile` or `Dockerfile`, -Podman play kube will build that image and name it `foobar`. An example directory structure for this example would look -like: -``` -|- mykubefiles - |- myplayfile.yaml - |- foobar - |- Containerfile -``` - -The build will consider `foobar` to be the context directory for the build. If there is an image in local storage -called `foobar`, the image will not be built unless the `--build` flag is used. Use `--build=false` to completely -disable builds. - -`Kubernetes ConfigMap` - -Kubernetes ConfigMap can be referred as a source of environment variables or volumes in Pods or Deployments. -ConfigMaps aren't a standalone object in Podman; instead, when a container uses a ConfigMap, Podman will create environment variables or volumes as needed. - -For example, the following YAML document defines a ConfigMap and then uses it in a Pod: - -``` -apiVersion: v1 -kind: ConfigMap -metadata: - name: foo -data: - FOO: bar ---- -apiVersion: v1 -kind: Pod -metadata: - name: foobar -spec: - containers: - - command: - - top - name: container-1 - image: foobar - envFrom: - - configMapRef: - name: foo - optional: false -``` - -and as a result environment variable `FOO` will be set to `bar` for container `container-1`. - -### Systemd Integration - -A Kubernetes YAML can be executed in systemd via the `podman-kube@.service` systemd template. The template's argument is the path to the YAML file. Given a `workload.yaml` file in the home directory, it can be executed as follows: - -``` -$ escaped=$(systemd-escape ~/sysadmin.yaml) -$ systemctl --user start podman-kube@$escaped.service -$ systemctl --user is-active podman-kube@$escaped.service -active -``` - -Note that the path to the YAML file must be escaped via `systemd-escape`. - -## OPTIONS - -#### **--annotation**=*key=value* - -Add an annotation to the container or pod. The format is key=value. -The **--annotation** option can be set multiple times. - -#### **--authfile**=*path* - -Path of the authentication file. Default is ${XDG\_RUNTIME\_DIR}/containers/auth.json, which is set using `podman login`. -If the authorization state is not found there, $HOME/.docker/config.json is checked, which is set using `docker login`. - -Note: You can also override the default path of the authentication file by setting the REGISTRY\_AUTH\_FILE -environment variable. `export REGISTRY_AUTH_FILE=path` - -#### **--build** - -Build images even if they are found in the local storage. Use `--build=false` to completely disable builds. (This option is not available with the remote Podman client) - -#### **--cert-dir**=*path* - -Use certificates at *path* (\*.crt, \*.cert, \*.key) to connect to the registry. (Default: /etc/containers/certs.d) -Please refer to containers-certs.d(5) for details. (This option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines) - -#### **--configmap**=*path* - -Use Kubernetes configmap YAML at path to provide a source for environment variable values within the containers of the pod. (This option is not available with the remote Podman client) - -Note: The *--configmap* option can be used multiple times or a comma-separated list of paths can be used to pass multiple Kubernetes configmap YAMLs. - -#### **--context-dir**=*path* - -Use *path* as the build context directory for each image. Requires --build option be true. (This option is not available with the remote Podman client) - -#### **--creds** - -The [username[:password]] to use to authenticate with the registry if required. -If one or both values are not supplied, a command line prompt will appear and the -value can be entered. The password is entered without echo. - -#### **--down** - -Tears down the pods that were created by a previous run of `play kube`. The pods are stopped and then -removed. Any volumes created are left intact. - -#### **--help**, **-h** - -Print usage statement - -#### **--ip**=*IP address* - -Assign a static ip address to the pod. This option can be specified several times when play kube creates more than one pod. -Note: When joining multiple networks you should use the **--network name:ip=\** syntax. - -#### **--log-driver**=driver - -Set logging driver for all created containers. - -#### **--log-opt**=*name*=*value* - -Set custom logging configuration. The following *name*s are supported: - -- **path**: specify a path to the log file -(e.g. **--log-opt path=/var/log/container/mycontainer.json**); - -- **max-size**: specify a max size of the log file -(e.g. **--log-opt max-size=10mb**); - -- **tag**: specify a custom log tag for the container -(e.g. **--log-opt tag="{{.ImageName}}"**. - -It supports the same keys as **podman inspect --format**. - -This option is currently supported only by the **journald** log driver. - -#### **--mac-address**=*MAC address* - -Assign a static mac address to the pod. This option can be specified several times when play kube creates more than one pod. -Note: When joining multiple networks you should use the **--network name:mac=\** syntax. - -#### **--network**=*mode*, **--net** - -Change the network mode of the pod. The host network mode should be configured in the YAML file. -Valid _mode_ values are: - -- **bridge[:OPTIONS,...]**: Create a network stack on the default bridge. This is the default for rootful containers. It is possible to specify these additional options: - - **alias=name**: Add network-scoped alias for the container. - - **ip=IPv4**: Specify a static ipv4 address for this container. - - **ip=IPv6**: Specify a static ipv6 address for this container. - - **mac=MAC**: Specify a static mac address for this container. - - **interface_name**: Specify a name for the created network interface inside the container. - - For example to set a static ipv4 address and a static mac address, use `--network bridge:ip=10.88.0.10,mac=44:33:22:11:00:99`. -- \[:OPTIONS,...]: Connect to a user-defined network; this is the network name or ID from a network created by **[podman network create](podman-network-create.1.md)**. Using the network name implies the bridge network mode. It is possible to specify the same options described under the bridge mode above. You can use the **--network** option multiple times to specify additional networks. -- **none**: Create a network namespace for the container but do not configure network interfaces for it, thus the container has no network connectivity. -- **container:**_id_: Reuse another container's network stack. -- **ns:**_path_: Path to a network namespace to join. -- **private**: Create a new namespace for the container. This will use the **bridge** mode for rootful containers and **slirp4netns** for rootless ones. -- **slirp4netns[:OPTIONS,...]**: use **slirp4netns**(1) to create a user network stack. This is the default for rootless containers. It is possible to specify these additional options, they can also be set with `network_cmd_options` in containers.conf: - - **allow_host_loopback=true|false**: Allow the slirp4netns to reach the host loopback IP (`10.0.2.2`). Default is false. - - **mtu=MTU**: Specify the MTU to use for this network. (Default is `65520`). - - **cidr=CIDR**: Specify ip range to use for this network. (Default is `10.0.2.0/24`). - - **enable_ipv6=true|false**: Enable IPv6. Default is true. (Required for `outbound_addr6`). - - **outbound_addr=INTERFACE**: Specify the outbound interface slirp should bind to (ipv4 traffic only). - - **outbound_addr=IPv4**: Specify the outbound ipv4 address slirp should bind to. - - **outbound_addr6=INTERFACE**: Specify the outbound interface slirp should bind to (ipv6 traffic only). - - **outbound_addr6=IPv6**: Specify the outbound ipv6 address slirp should bind to. - - **port_handler=rootlesskit**: Use rootlesskit for port forwarding. Default. - Note: Rootlesskit changes the source IP address of incoming packets to an IP address in the container network namespace, usually `10.0.2.100`. If your application requires the real source IP address, e.g. web server logs, use the slirp4netns port handler. The rootlesskit port handler is also used for rootless containers when connected to user-defined networks. - - **port_handler=slirp4netns**: Use the slirp4netns port forwarding, it is slower than rootlesskit but preserves the correct source IP address. This port handler cannot be used for user-defined networks. - -#### **--no-hosts** - -Do not create /etc/hosts for the pod. -By default, Podman will manage /etc/hosts, adding the container's own IP address and any hosts from **--add-host**. -**--no-hosts** disables this, and the image's **/etc/host** will be preserved unmodified. -This option conflicts with host added in the Kubernetes YAML. - -#### **--quiet**, **-q** - -Suppress output information when pulling images - -#### **--replace** - -Tears down the pods created by a previous run of `play kube` and recreates the pods. This option is used to keep the existing pods up to date based upon the Kubernetes YAML. - -#### **--seccomp-profile-root**=*path* - -Directory path for seccomp profiles (default: "/var/lib/kubelet/seccomp"). (This option is not available with the remote Podman client, including Mac and Windows (excluding WSL2) machines) - -#### **--start** - -Start the pod after creating it, set to false to only create it. - -#### **--tls-verify** - -Require HTTPS and verify certificates when contacting registries (default: true). If explicitly set to true, -then TLS verification will be used. If set to false, then TLS verification will not be used. If not specified, -TLS verification will be used unless the target registry is listed as an insecure registry in registries.conf. - -#### **--userns**=*mode* - -Set the user namespace mode for the container. It defaults to the **PODMAN_USERNS** environment variable. An empty value ("") means user namespaces are disabled unless an explicit mapping is set with the **--uidmap** and **--gidmap** options. - -Rootless user --userns=Key mappings: - -Key | Host User | Container User -----------|---------------|--------------------- -"" |$UID |0 (Default User account mapped to root user in container.) -keep-id |$UID |$UID (Map user account to same UID within container.) -auto |$UID | nil (Host User UID is not mapped into container.) -nomap |$UID | nil (Host User UID is not mapped into container.) - -Valid _mode_ values are: - -**auto**[:_OPTIONS,..._]: automatically create a unique user namespace. - -The `--userns=auto` flag, requires that the user name `containers` and a range of subordinate user ids that the Podman container is allowed to use be specified in the /etc/subuid and /etc/subgid files. - -Example: `containers:2147483647:2147483648`. - -Podman allocates unique ranges of UIDs and GIDs from the `containers` subordinate user ids. The size of the ranges is based on the number of UIDs required in the image. The number of UIDs and GIDs can be overridden with the `size` option. The `auto` options currently does not work in rootless mode - - Valid `auto` options: - - - *gidmapping*=_CONTAINER_GID:HOST_GID:SIZE_: to force a GID mapping to be present in the user namespace. - - *size*=_SIZE_: to specify an explicit size for the automatic user namespace. e.g. `--userns=auto:size=8192`. If `size` is not specified, `auto` will estimate a size for the user namespace. - - *uidmapping*=_CONTAINER_UID:HOST_UID:SIZE_: to force a UID mapping to be present in the user namespace. - -**container:**_id_: join the user namespace of the specified container. - -**host**: create a new namespace for the container. - -**keep-id**: creates a user namespace where the current rootless user's UID:GID are mapped to the same values in the container. This option is not allowed for containers created by the root user. - -**nomap**: creates a user namespace where the current rootless user's UID:GID are not mapped into the container. This option is not allowed for containers created by the root user. - -**ns:**_namespace_: run the pod in the given existing user namespace. - -## EXAMPLES - -Recreate the pod and containers as described in a file called `demo.yml` -``` -$ podman play kube demo.yml -52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 -``` - -Recreate the pod and containers as described in a file `demo.yml` sent to stdin -``` -$ cat demo.yml | podman play kube - -52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 - -``` -Teardown the pod and containers as described in a file `demo.yml` -``` -$ podman play kube --down demo.yml -Pods stopped: -52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 -Pods removed: -52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 -``` - -Provide `configmap-foo.yml` and `configmap-bar.yml` as sources for environment variables within the containers. -``` -$ podman play kube demo.yml --configmap configmap-foo.yml,configmap-bar.yml -52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 - -$ podman play kube demo.yml --configmap configmap-foo.yml --configmap configmap-bar.yml -52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 -``` - -Create a pod connected to two networks (called net1 and net2) with a static ip -``` -$ podman play kube demo.yml --network net1:ip=10.89.1.5 --network net2:ip=10.89.10.10 -52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6 -``` - -Please take into account that CNI networks must be created first using podman-network-create(1). - -## SEE ALSO -**[podman(1)](podman.1.md)**, **[podman-play(1)](podman-play.1.md)**, **[podman-network-create(1)](podman-network-create.1.md)**, **[podman-generate-kube(1)](podman-generate-kube.1.md)**, **[containers-certs.d(5)](https://github.com/containers/image/blob/main/docs/containers-certs.d.5.md)** - -## HISTORY -December 2018, Originally compiled by Brent Baude (bbaude at redhat dot com) diff --git a/docs/source/markdown/podman-play.1.md b/docs/source/markdown/podman-play.1.md deleted file mode 100644 index e5f0d315e..000000000 --- a/docs/source/markdown/podman-play.1.md +++ /dev/null @@ -1,20 +0,0 @@ -% podman-play(1) - -## NAME -podman\-play - Play containers, pods or volumes based on a structured input file - -## SYNOPSIS -**podman play** *subcommand* - -## DESCRIPTION -The play command will recreate containers, pods or volumes based on the input from a structured (like YAML) -file input. Containers will be automatically started. - -## COMMANDS - -| Command | Man Page | Description | -| ------- | --------------------------------------------------- | ---------------------------------------------------------------------------- | -| kube | [podman-play-kube(1)](podman-play-kube.1.md) | Create containers, pods or volumes based on Kubernetes YAML. | - -## SEE ALSO -**[podman(1)](podman.1.md)**, **[podman-pod(1)](podman-pod.1.md)**, **[podman-container(1)](podman-container.1.md)**, **[podman-generate(1)](podman-generate.1.md)**, **[podman-play-kube(1)](podman-play-kube.1.md)** diff --git a/docs/source/markdown/podman-pod-create.1.md b/docs/source/markdown/podman-pod-create.1.md index 53d1e3327..f7bdb623a 100644 --- a/docs/source/markdown/podman-pod-create.1.md +++ b/docs/source/markdown/podman-pod-create.1.md @@ -92,7 +92,7 @@ Set the exit policy of the pod when the last container exits. Supported policie | Exit Policy | Description | | ------------------ | --------------------------------------------------------------------------- | | *continue* | The pod continues running when the last container exits. Used by default. | -| *stop* | The pod is stopped when the last container exits. Used in `play kube`. | +| *stop* | The pod is stopped when the last container exits. Used in `kube play`. | #### **--gidmap**=*container_gid:host_gid:amount* @@ -603,7 +603,7 @@ $ podman pod create --network net1:ip=10.89.1.5 --network net2:ip=10.89.10.10 ``` ## SEE ALSO -**[podman(1)](podman.1.md)**, **[podman-pod(1)](podman-pod.1.md)**, **[podman-play-kube(1)](podman-play-kube.1.md)**, **containers.conf(1)** +**[podman(1)](podman.1.md)**, **[podman-pod(1)](podman-pod.1.md)**, **[podman-kube-play(1)](podman-kube-play.1.md)**, **containers.conf(1)** ## HISTORY diff --git a/docs/source/markdown/podman.1.md b/docs/source/markdown/podman.1.md index 3d1578ea1..4c019ae97 100644 --- a/docs/source/markdown/podman.1.md +++ b/docs/source/markdown/podman.1.md @@ -325,7 +325,7 @@ the exit codes follow the `chroot` standard, see below: | [podman-mount(1)](podman-mount.1.md) | Mount a working container's root filesystem. | | [podman-network(1)](podman-network.1.md) | Manage Podman networks. | | [podman-pause(1)](podman-pause.1.md) | Pause one or more containers. | -| [podman-play(1)](podman-play.1.md) | Play containers, pods or volumes based on a structured input file. | +| [podman-kube(1)](podman-kube.1.md) | Play containers, pods or volumes based on a structured input file. | | [podman-pod(1)](podman-pod.1.md) | Management tool for groups of containers, called pods. | | [podman-port(1)](podman-port.1.md) | List port mappings for a container. | | [podman-ps(1)](podman-ps.1.md) | Prints out information about containers. | diff --git a/hack/swagger-check b/hack/swagger-check index b4481f5bb..1e5b95c3a 100755 --- a/hack/swagger-check +++ b/hack/swagger-check @@ -320,8 +320,8 @@ sub operation_name { if ($action eq 'df') { $action = 'dataUsage'; } - elsif ($action eq "delete" && $endpoint eq "/libpod/play/kube") { - $action = "KubeDown" + elsif ($action eq "delete" && $endpoint eq "/libpod/kube/play") { + $action = "PlayDown" } # Grrrrrr, this one is annoying: some operations get an extra 'All' elsif ($action =~ /^(delete|get|stats)$/ && $endpoint !~ /\{/) { diff --git a/pkg/api/handlers/libpod/kube.go b/pkg/api/handlers/libpod/kube.go new file mode 100644 index 000000000..6cad58795 --- /dev/null +++ b/pkg/api/handlers/libpod/kube.go @@ -0,0 +1,123 @@ +package libpod + +import ( + "fmt" + "net" + "net/http" + + "github.com/containers/image/v5/types" + "github.com/containers/podman/v4/libpod" + "github.com/containers/podman/v4/pkg/api/handlers/utils" + api "github.com/containers/podman/v4/pkg/api/types" + "github.com/containers/podman/v4/pkg/auth" + "github.com/containers/podman/v4/pkg/domain/entities" + "github.com/containers/podman/v4/pkg/domain/infra/abi" + "github.com/gorilla/schema" +) + +func KubePlay(w http.ResponseWriter, r *http.Request) { + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) + decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) + query := struct { + Annotations map[string]string `schema:"annotations"` + Network []string `schema:"network"` + TLSVerify bool `schema:"tlsVerify"` + LogDriver string `schema:"logDriver"` + LogOptions []string `schema:"logOptions"` + Start bool `schema:"start"` + StaticIPs []string `schema:"staticIPs"` + StaticMACs []string `schema:"staticMACs"` + NoHosts bool `schema:"noHosts"` + }{ + TLSVerify: true, + Start: true, + } + + if err := decoder.Decode(&query, r.URL.Query()); err != nil { + utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err)) + return + } + + staticIPs := make([]net.IP, 0, len(query.StaticIPs)) + for _, ipString := range query.StaticIPs { + ip := net.ParseIP(ipString) + if ip == nil { + utils.Error(w, http.StatusBadRequest, fmt.Errorf("invalid IP address %s", ipString)) + return + } + staticIPs = append(staticIPs, ip) + } + + staticMACs := make([]net.HardwareAddr, 0, len(query.StaticMACs)) + for _, macString := range query.StaticMACs { + mac, err := net.ParseMAC(macString) + if err != nil { + utils.Error(w, http.StatusBadRequest, err) + return + } + staticMACs = append(staticMACs, mac) + } + + authConf, authfile, err := auth.GetCredentials(r) + if err != nil { + utils.Error(w, http.StatusBadRequest, err) + return + } + defer auth.RemoveAuthfile(authfile) + var username, password string + if authConf != nil { + username = authConf.Username + password = authConf.Password + } + + logDriver := query.LogDriver + if logDriver == "" { + config, err := runtime.GetConfig() + if err != nil { + utils.Error(w, http.StatusInternalServerError, err) + return + } + logDriver = config.Containers.LogDriver + } + + containerEngine := abi.ContainerEngine{Libpod: runtime} + options := entities.PlayKubeOptions{ + Annotations: query.Annotations, + Authfile: authfile, + Username: username, + Password: password, + Networks: query.Network, + NoHosts: query.NoHosts, + Quiet: true, + LogDriver: logDriver, + LogOptions: query.LogOptions, + StaticIPs: staticIPs, + StaticMACs: staticMACs, + } + if _, found := r.URL.Query()["tlsVerify"]; found { + options.SkipTLSVerify = types.NewOptionalBool(!query.TLSVerify) + } + if _, found := r.URL.Query()["start"]; found { + options.Start = types.NewOptionalBool(query.Start) + } + report, err := containerEngine.PlayKube(r.Context(), r.Body, options) + _ = r.Body.Close() + if err != nil { + utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error playing YAML file: %w", err)) + return + } + utils.WriteResponse(w, http.StatusOK, report) +} + +func KubePlayDown(w http.ResponseWriter, r *http.Request) { + runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) + containerEngine := abi.ContainerEngine{Libpod: runtime} + options := new(entities.PlayKubeDownOptions) + report, err := containerEngine.PlayKubeDown(r.Context(), r.Body, *options) + _ = r.Body.Close() + if err != nil { + utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error tearing down YAML file: %w", err)) + return + } + utils.WriteResponse(w, http.StatusOK, report) +} diff --git a/pkg/api/handlers/libpod/play.go b/pkg/api/handlers/libpod/play.go index f8ce52a72..74830badb 100644 --- a/pkg/api/handlers/libpod/play.go +++ b/pkg/api/handlers/libpod/play.go @@ -1,123 +1,13 @@ package libpod import ( - "fmt" - "net" "net/http" - - "github.com/containers/image/v5/types" - "github.com/containers/podman/v4/libpod" - "github.com/containers/podman/v4/pkg/api/handlers/utils" - api "github.com/containers/podman/v4/pkg/api/types" - "github.com/containers/podman/v4/pkg/auth" - "github.com/containers/podman/v4/pkg/domain/entities" - "github.com/containers/podman/v4/pkg/domain/infra/abi" - "github.com/gorilla/schema" ) func PlayKube(w http.ResponseWriter, r *http.Request) { - runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) - decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder) - query := struct { - Annotations map[string]string `schema:"annotations"` - Network []string `schema:"network"` - TLSVerify bool `schema:"tlsVerify"` - LogDriver string `schema:"logDriver"` - LogOptions []string `schema:"logOptions"` - Start bool `schema:"start"` - StaticIPs []string `schema:"staticIPs"` - StaticMACs []string `schema:"staticMACs"` - NoHosts bool `schema:"noHosts"` - }{ - TLSVerify: true, - Start: true, - } - - if err := decoder.Decode(&query, r.URL.Query()); err != nil { - utils.Error(w, http.StatusBadRequest, fmt.Errorf("failed to parse parameters for %s: %w", r.URL.String(), err)) - return - } - - staticIPs := make([]net.IP, 0, len(query.StaticIPs)) - for _, ipString := range query.StaticIPs { - ip := net.ParseIP(ipString) - if ip == nil { - utils.Error(w, http.StatusBadRequest, fmt.Errorf("invalid IP address %s", ipString)) - return - } - staticIPs = append(staticIPs, ip) - } - - staticMACs := make([]net.HardwareAddr, 0, len(query.StaticMACs)) - for _, macString := range query.StaticMACs { - mac, err := net.ParseMAC(macString) - if err != nil { - utils.Error(w, http.StatusBadRequest, err) - return - } - staticMACs = append(staticMACs, mac) - } - - authConf, authfile, err := auth.GetCredentials(r) - if err != nil { - utils.Error(w, http.StatusBadRequest, err) - return - } - defer auth.RemoveAuthfile(authfile) - var username, password string - if authConf != nil { - username = authConf.Username - password = authConf.Password - } - - logDriver := query.LogDriver - if logDriver == "" { - config, err := runtime.GetConfig() - if err != nil { - utils.Error(w, http.StatusInternalServerError, err) - return - } - logDriver = config.Containers.LogDriver - } - - containerEngine := abi.ContainerEngine{Libpod: runtime} - options := entities.PlayKubeOptions{ - Annotations: query.Annotations, - Authfile: authfile, - Username: username, - Password: password, - Networks: query.Network, - NoHosts: query.NoHosts, - Quiet: true, - LogDriver: logDriver, - LogOptions: query.LogOptions, - StaticIPs: staticIPs, - StaticMACs: staticMACs, - } - if _, found := r.URL.Query()["tlsVerify"]; found { - options.SkipTLSVerify = types.NewOptionalBool(!query.TLSVerify) - } - if _, found := r.URL.Query()["start"]; found { - options.Start = types.NewOptionalBool(query.Start) - } - report, err := containerEngine.PlayKube(r.Context(), r.Body, options) - _ = r.Body.Close() - if err != nil { - utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error playing YAML file: %w", err)) - return - } - utils.WriteResponse(w, http.StatusOK, report) + KubePlay(w, r) } func PlayKubeDown(w http.ResponseWriter, r *http.Request) { - runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime) - containerEngine := abi.ContainerEngine{Libpod: runtime} - options := new(entities.PlayKubeDownOptions) - report, err := containerEngine.PlayKubeDown(r.Context(), r.Body, *options) - _ = r.Body.Close() - if err != nil { - utils.Error(w, http.StatusInternalServerError, fmt.Errorf("error tearing down YAML file: %w", err)) - return - } - utils.WriteResponse(w, http.StatusOK, report) + KubePlayDown(w, r) } diff --git a/pkg/api/handlers/swagger/responses.go b/pkg/api/handlers/swagger/responses.go index 93a508b39..5731f8edd 100644 --- a/pkg/api/handlers/swagger/responses.go +++ b/pkg/api/handlers/swagger/responses.go @@ -71,7 +71,7 @@ type imagesRemoveResponseLibpod struct { // PlayKube response // swagger:response -type playKubeResponseLibpod struct { +type kubePlayResponseLibpod struct { // in:body Body entities.PlayKubeReport } diff --git a/pkg/api/server/register_kube.go b/pkg/api/server/register_kube.go new file mode 100644 index 000000000..6ae9e8123 --- /dev/null +++ b/pkg/api/server/register_kube.go @@ -0,0 +1,82 @@ +package server + +import ( + "net/http" + + "github.com/containers/podman/v4/pkg/api/handlers/libpod" + "github.com/gorilla/mux" +) + +func (s *APIServer) registerKubeHandlers(r *mux.Router) error { + // swagger:operation POST /libpod/kube/play libpod KubePlayLibpod + // --- + // tags: + // - containers + // - pods + // summary: Play a Kubernetes YAML file. + // description: Create and run pods based on a Kubernetes YAML file (pod or service kind). + // parameters: + // - in: query + // name: network + // type: array + // description: USe the network mode or specify an array of networks. + // items: + // type: string + // - in: query + // name: tlsVerify + // type: boolean + // default: true + // description: Require HTTPS and verify signatures when contacting registries. + // - in: query + // name: logDriver + // type: string + // description: Logging driver for the containers in the pod. + // - in: query + // name: start + // type: boolean + // default: true + // description: Start the pod after creating it. + // - in: query + // name: staticIPs + // type: array + // description: Static IPs used for the pods. + // items: + // type: string + // - in: query + // name: staticMACs + // type: array + // description: Static MACs used for the pods. + // items: + // type: string + // - in: body + // name: request + // description: Kubernetes YAML file. + // schema: + // type: string + // produces: + // - application/json + // responses: + // 200: + // $ref: "#/responses/kubePlayResponseLibpod" + // 500: + // $ref: "#/responses/internalError" + r.HandleFunc(VersionedPath("/libpod/kube/play"), s.APIHandler(libpod.KubePlay)).Methods(http.MethodPost) + r.HandleFunc(VersionedPath("/libpod/play/kube"), s.APIHandler(libpod.PlayKube)).Methods(http.MethodPost) + // swagger:operation DELETE /libpod/kube/play libpod KubePlayDownLibpod + // --- + // tags: + // - containers + // - pods + // summary: Remove pods from kube play + // description: Tears down pods defined in a YAML file + // produces: + // - application/json + // responses: + // 200: + // $ref: "#/responses/kubePlayResponseLibpod" + // 500: + // $ref: "#/responses/internalError" + r.HandleFunc(VersionedPath("/libpod/kube/play"), s.APIHandler(libpod.KubePlayDown)).Methods(http.MethodDelete) + r.HandleFunc(VersionedPath("/libpod/play/kube"), s.APIHandler(libpod.PlayKubeDown)).Methods(http.MethodDelete) + return nil +} diff --git a/pkg/api/server/register_play.go b/pkg/api/server/register_play.go deleted file mode 100644 index 35da80ccc..000000000 --- a/pkg/api/server/register_play.go +++ /dev/null @@ -1,80 +0,0 @@ -package server - -import ( - "net/http" - - "github.com/containers/podman/v4/pkg/api/handlers/libpod" - "github.com/gorilla/mux" -) - -func (s *APIServer) registerPlayHandlers(r *mux.Router) error { - // swagger:operation POST /libpod/play/kube libpod PlayKubeLibpod - // --- - // tags: - // - containers - // - pods - // summary: Play a Kubernetes YAML file. - // description: Create and run pods based on a Kubernetes YAML file (pod or service kind). - // parameters: - // - in: query - // name: network - // type: array - // description: USe the network mode or specify an array of networks. - // items: - // type: string - // - in: query - // name: tlsVerify - // type: boolean - // default: true - // description: Require HTTPS and verify signatures when contacting registries. - // - in: query - // name: logDriver - // type: string - // description: Logging driver for the containers in the pod. - // - in: query - // name: start - // type: boolean - // default: true - // description: Start the pod after creating it. - // - in: query - // name: staticIPs - // type: array - // description: Static IPs used for the pods. - // items: - // type: string - // - in: query - // name: staticMACs - // type: array - // description: Static MACs used for the pods. - // items: - // type: string - // - in: body - // name: request - // description: Kubernetes YAML file. - // schema: - // type: string - // produces: - // - application/json - // responses: - // 200: - // $ref: "#/responses/playKubeResponseLibpod" - // 500: - // $ref: "#/responses/internalError" - r.HandleFunc(VersionedPath("/libpod/play/kube"), s.APIHandler(libpod.PlayKube)).Methods(http.MethodPost) - // swagger:operation DELETE /libpod/play/kube libpod PlayKubeDownLibpod - // --- - // tags: - // - containers - // - pods - // summary: Remove pods from play kube - // description: Tears down pods defined in a YAML file - // produces: - // - application/json - // responses: - // 200: - // $ref: "#/responses/playKubeResponseLibpod" - // 500: - // $ref: "#/responses/internalError" - r.HandleFunc(VersionedPath("/libpod/play/kube"), s.APIHandler(libpod.PlayKubeDown)).Methods(http.MethodDelete) - return nil -} diff --git a/pkg/api/server/server.go b/pkg/api/server/server.go index 5482a8ec2..a6d8b5e4c 100644 --- a/pkg/api/server/server.go +++ b/pkg/api/server/server.go @@ -126,11 +126,11 @@ func newServer(runtime *libpod.Runtime, listener net.Listener, opts entities.Ser server.registerHealthCheckHandlers, server.registerImagesHandlers, server.registerInfoHandlers, + server.registerKubeHandlers, server.registerManifestHandlers, server.registerMonitorHandlers, server.registerNetworkHandlers, server.registerPingHandlers, - server.registerPlayHandlers, server.registerPluginsHandlers, server.registerPodsHandlers, server.registerSecretHandlers, diff --git a/pkg/bindings/kube/kube.go b/pkg/bindings/kube/kube.go new file mode 100644 index 000000000..b9cc0efa7 --- /dev/null +++ b/pkg/bindings/kube/kube.go @@ -0,0 +1,96 @@ +package kube + +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/domain/entities" + "github.com/sirupsen/logrus" +) + +func Play(ctx context.Context, path string, options *PlayOptions) (*entities.KubePlayReport, error) { + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer f.Close() + + return PlayWithBody(ctx, f, options) +} + +func PlayWithBody(ctx context.Context, body io.Reader, options *PlayOptions) (*entities.KubePlayReport, error) { + var report entities.KubePlayReport + if options == nil { + options = new(PlayOptions) + } + + 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, "/kube/play", 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 +} + +func Down(ctx context.Context, path string) (*entities.KubePlayReport, error) { + f, err := os.Open(path) + if err != nil { + return nil, err + } + defer func() { + if err := f.Close(); err != nil { + logrus.Warn(err) + } + }() + + return DownWithBody(ctx, f) +} + +func DownWithBody(ctx context.Context, body io.Reader) (*entities.KubePlayReport, error) { + var report entities.KubePlayReport + conn, err := bindings.GetClient(ctx) + if err != nil { + return nil, err + } + + response, err := conn.DoRequest(ctx, body, http.MethodDelete, "/kube/play", nil, nil) + if err != nil { + return nil, err + } + if err := response.Process(&report); err != nil { + return nil, err + } + return &report, nil +} diff --git a/pkg/bindings/kube/types.go b/pkg/bindings/kube/types.go new file mode 100644 index 000000000..783d1912a --- /dev/null +++ b/pkg/bindings/kube/types.go @@ -0,0 +1,48 @@ +package kube + +import ( + "net" +) + +//go:generate go run ../generator/generator.go PlayOptions +// PlayOptions are optional options for replaying kube YAML files +type PlayOptions 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/kube/types_play_options.go b/pkg/bindings/kube/types_play_options.go new file mode 100644 index 000000000..cdc2e9dd8 --- /dev/null +++ b/pkg/bindings/kube/types_play_options.go @@ -0,0 +1,289 @@ +// Code generated by go generate; DO NOT EDIT. +package kube + +import ( + "net" + "net/url" + + "github.com/containers/podman/v4/pkg/bindings/internal/util" +) + +// Changed returns true if named field has been set +func (o *PlayOptions) Changed(fieldName string) bool { + return util.Changed(o, fieldName) +} + +// ToParams formats struct fields to be passed to API service +func (o *PlayOptions) ToParams() (url.Values, error) { + return util.ToParams(o) +} + +// WithAnnotations set field Annotations to given value +func (o *PlayOptions) WithAnnotations(value map[string]string) *PlayOptions { + o.Annotations = value + return o +} + +// GetAnnotations returns value of field Annotations +func (o *PlayOptions) 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 *PlayOptions) WithAuthfile(value string) *PlayOptions { + o.Authfile = &value + return o +} + +// GetAuthfile returns value of field Authfile +func (o *PlayOptions) GetAuthfile() string { + if o.Authfile == nil { + var z string + return z + } + return *o.Authfile +} + +// WithCertDir set field CertDir to given value +func (o *PlayOptions) WithCertDir(value string) *PlayOptions { + o.CertDir = &value + return o +} + +// GetCertDir returns value of field CertDir +func (o *PlayOptions) GetCertDir() string { + if o.CertDir == nil { + var z string + return z + } + return *o.CertDir +} + +// WithUsername set field Username to given value +func (o *PlayOptions) WithUsername(value string) *PlayOptions { + o.Username = &value + return o +} + +// GetUsername returns value of field Username +func (o *PlayOptions) GetUsername() string { + if o.Username == nil { + var z string + return z + } + return *o.Username +} + +// WithPassword set field Password to given value +func (o *PlayOptions) WithPassword(value string) *PlayOptions { + o.Password = &value + return o +} + +// GetPassword returns value of field Password +func (o *PlayOptions) GetPassword() string { + if o.Password == nil { + var z string + return z + } + return *o.Password +} + +// WithNetwork set field Network to given value +func (o *PlayOptions) WithNetwork(value []string) *PlayOptions { + o.Network = &value + return o +} + +// GetNetwork returns value of field Network +func (o *PlayOptions) GetNetwork() []string { + if o.Network == nil { + var z []string + return z + } + return *o.Network +} + +// WithNoHosts set field NoHosts to given value +func (o *PlayOptions) WithNoHosts(value bool) *PlayOptions { + o.NoHosts = &value + return o +} + +// GetNoHosts returns value of field NoHosts +func (o *PlayOptions) GetNoHosts() bool { + if o.NoHosts == nil { + var z bool + return z + } + return *o.NoHosts +} + +// WithQuiet set field Quiet to given value +func (o *PlayOptions) WithQuiet(value bool) *PlayOptions { + o.Quiet = &value + return o +} + +// GetQuiet returns value of field Quiet +func (o *PlayOptions) GetQuiet() bool { + if o.Quiet == nil { + var z bool + return z + } + return *o.Quiet +} + +// WithSignaturePolicy set field SignaturePolicy to given value +func (o *PlayOptions) WithSignaturePolicy(value string) *PlayOptions { + o.SignaturePolicy = &value + return o +} + +// GetSignaturePolicy returns value of field SignaturePolicy +func (o *PlayOptions) GetSignaturePolicy() string { + if o.SignaturePolicy == nil { + var z string + return z + } + return *o.SignaturePolicy +} + +// WithSkipTLSVerify set field SkipTLSVerify to given value +func (o *PlayOptions) WithSkipTLSVerify(value bool) *PlayOptions { + o.SkipTLSVerify = &value + return o +} + +// GetSkipTLSVerify returns value of field SkipTLSVerify +func (o *PlayOptions) GetSkipTLSVerify() bool { + if o.SkipTLSVerify == nil { + var z bool + return z + } + return *o.SkipTLSVerify +} + +// WithSeccompProfileRoot set field SeccompProfileRoot to given value +func (o *PlayOptions) WithSeccompProfileRoot(value string) *PlayOptions { + o.SeccompProfileRoot = &value + return o +} + +// GetSeccompProfileRoot returns value of field SeccompProfileRoot +func (o *PlayOptions) GetSeccompProfileRoot() string { + if o.SeccompProfileRoot == nil { + var z string + return z + } + return *o.SeccompProfileRoot +} + +// WithStaticIPs set field StaticIPs to given value +func (o *PlayOptions) WithStaticIPs(value []net.IP) *PlayOptions { + o.StaticIPs = &value + return o +} + +// GetStaticIPs returns value of field StaticIPs +func (o *PlayOptions) 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 *PlayOptions) WithStaticMACs(value []net.HardwareAddr) *PlayOptions { + o.StaticMACs = &value + return o +} + +// GetStaticMACs returns value of field StaticMACs +func (o *PlayOptions) 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 *PlayOptions) WithConfigMaps(value []string) *PlayOptions { + o.ConfigMaps = &value + return o +} + +// GetConfigMaps returns value of field ConfigMaps +func (o *PlayOptions) GetConfigMaps() []string { + if o.ConfigMaps == nil { + var z []string + return z + } + return *o.ConfigMaps +} + +// WithLogDriver set field LogDriver to given value +func (o *PlayOptions) WithLogDriver(value string) *PlayOptions { + o.LogDriver = &value + return o +} + +// GetLogDriver returns value of field LogDriver +func (o *PlayOptions) GetLogDriver() string { + if o.LogDriver == nil { + var z string + return z + } + return *o.LogDriver +} + +// WithLogOptions set field LogOptions to given value +func (o *PlayOptions) WithLogOptions(value []string) *PlayOptions { + o.LogOptions = &value + return o +} + +// GetLogOptions returns value of field LogOptions +func (o *PlayOptions) GetLogOptions() []string { + if o.LogOptions == nil { + var z []string + return z + } + return *o.LogOptions +} + +// WithStart set field Start to given value +func (o *PlayOptions) WithStart(value bool) *PlayOptions { + o.Start = &value + return o +} + +// GetStart returns value of field Start +func (o *PlayOptions) GetStart() bool { + if o.Start == nil { + var z bool + return z + } + return *o.Start +} + +// WithUserns set field Userns to given value +func (o *PlayOptions) WithUserns(value string) *PlayOptions { + o.Userns = &value + return o +} + +// GetUserns returns value of field Userns +func (o *PlayOptions) GetUserns() string { + if o.Userns == nil { + var z string + return z + } + return *o.Userns +} 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 -} diff --git a/pkg/domain/entities/play.go b/pkg/domain/entities/play.go index f1ba21650..35a5d8a4a 100644 --- a/pkg/domain/entities/play.go +++ b/pkg/domain/entities/play.go @@ -90,6 +90,8 @@ type PlayKubeReport struct { PlayKubeTeardown } +type KubePlayReport = PlayKubeReport + // PlayKubeDownOptions are options for tearing down pods type PlayKubeDownOptions struct{} diff --git a/pkg/domain/infra/tunnel/play.go b/pkg/domain/infra/tunnel/play.go index d731a1d6c..ee9195681 100644 --- a/pkg/domain/infra/tunnel/play.go +++ b/pkg/domain/infra/tunnel/play.go @@ -5,12 +5,13 @@ import ( "io" "github.com/containers/image/v5/types" + "github.com/containers/podman/v4/pkg/bindings/kube" "github.com/containers/podman/v4/pkg/bindings/play" "github.com/containers/podman/v4/pkg/domain/entities" ) func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, opts entities.PlayKubeOptions) (*entities.PlayKubeReport, error) { - options := new(play.KubeOptions).WithAuthfile(opts.Authfile).WithUsername(opts.Username).WithPassword(opts.Password) + options := new(kube.PlayOptions).WithAuthfile(opts.Authfile).WithUsername(opts.Username).WithPassword(opts.Password) options.WithCertDir(opts.CertDir).WithQuiet(opts.Quiet).WithSignaturePolicy(opts.SignaturePolicy).WithConfigMaps(opts.ConfigMaps) options.WithLogDriver(opts.LogDriver).WithNetwork(opts.Networks).WithSeccompProfileRoot(opts.SeccompProfileRoot) options.WithStaticIPs(opts.StaticIPs).WithStaticMACs(opts.StaticMACs) @@ -31,5 +32,5 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, opts en } func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, _ entities.PlayKubeDownOptions) (*entities.PlayKubeReport, error) { - return play.KubeDownWithBody(ic.ClientCtx, body) + return play.DownWithBody(ic.ClientCtx, body) } diff --git a/test/apiv2/25-containersMore.at b/test/apiv2/25-containersMore.at index c9fda8c6f..9cdc2a33f 100644 --- a/test/apiv2/25-containersMore.at +++ b/test/apiv2/25-containersMore.at @@ -53,34 +53,6 @@ t POST libpod/containers/foo/unmount 204 t DELETE libpod/containers/foo?force=true 200 -podman run $IMAGE true - -t GET libpod/containers/json?last=1 200 \ - length=1 \ - .[0].Id~[0-9a-f]\\{64\\} \ - .[0].Image=$IMAGE \ - .[0].Command[0]="true" \ - .[0].State~\\\(exited\\\|stopped\\\) \ - .[0].ExitCode=0 \ - .[0].IsInfra=false - -cid=$(jq -r '.[0].Id' <<<"$output") - -t GET libpod/generate/kube?names=$cid 200 -like "$output" ".*apiVersion:.*" "Check generated kube yaml - apiVersion" -like "$output" ".*kind:\\sPod.*" "Check generated kube yaml - kind: Pod" -like "$output" ".*metadata:.*" "Check generated kube yaml - metadata" -like "$output" ".*spec:.*" "Check generated kube yaml - spec" - -t GET "libpod/generate/kube?service=true&names=$cid" 200 -like "$output" ".*apiVersion:.*" "Check generated kube yaml(service=true) - apiVersion" -like "$output" ".*kind:\\sPod.*" "Check generated kube yaml(service=true) - kind: Pod" -like "$output" ".*metadata:.*" "Check generated kube yaml(service=true) - metadata" -like "$output" ".*spec:.*" "Check generated kube yaml(service=true) - spec" -like "$output" ".*kind:\\sService.*" "Check generated kube yaml(service=true) - kind: Service" - -t DELETE libpod/containers/$cid 200 .[0].Id=$cid - # Create 3 stopped containers to test containers prune podman run $IMAGE true podman run $IMAGE true diff --git a/test/apiv2/80-kube.at b/test/apiv2/80-kube.at new file mode 100644 index 000000000..40b26d75e --- /dev/null +++ b/test/apiv2/80-kube.at @@ -0,0 +1,50 @@ +# -*- sh -*- +# +# test more container-related endpoints +# + +podman create $IMAGE true + +t GET libpod/containers/json?last=1 200 \ + length=1 \ + .[0].Id~[0-9a-f]\\{64\\} \ + .[0].Image=$IMAGE \ + .[0].Command[0]="true" \ + .[0].IsInfra=false + +cid=$(jq -r '.[0].Id' <<<"$output") + +# Make sure that generate-kube works + +t GET libpod/generate/kube?names=$cid 200 +like "$output" ".*apiVersion:.*" "Check generated kube yaml - apiVersion" +like "$output" ".*kind:\\sPod.*" "Check generated kube yaml - kind: Pod" +like "$output" ".*metadata:.*" "Check generated kube yaml - metadata" +like "$output" ".*spec:.*" "Check generated kube yaml - spec" + +t GET "libpod/generate/kube?service=true&names=$cid" 200 +like "$output" ".*apiVersion:.*" "Check generated kube yaml(service=true) - apiVersion" +like "$output" ".*kind:\\sPod.*" "Check generated kube yaml(service=true) - kind: Pod" +like "$output" ".*metadata:.*" "Check generated kube yaml(service=true) - metadata" +like "$output" ".*spec:.*" "Check generated kube yaml(service=true) - spec" +like "$output" ".*kind:\\sService.*" "Check generated kube yaml(service=true) - kind: Service" + +TMPD=$(mktemp -d podman-apiv2-test-kube.XXXXXX) +YAML="${TMPD}/kube.yaml" +echo "$output" > $YAML + +t DELETE libpod/containers/$cid 200 .[0].Id=$cid + +# Make sure that kube-play works + +t POST libpod/kube/play $YAML 200 +t DELETE libpod/kube/play $YAML 200 + +# Make sure that play-kube works + +t POST libpod/play/kube $YAML 200 +t DELETE libpod/play/kube $YAML 200 + +rm -rf $TMPD + +# vim: filetype=sh diff --git a/test/apiv2/test-apiv2 b/test/apiv2/test-apiv2 index 0fd282854..0c3c6e672 100755 --- a/test/apiv2/test-apiv2 +++ b/test/apiv2/test-apiv2 @@ -252,7 +252,7 @@ function t() { fi # POST and PUT requests may be followed by one or more key=value pairs. # Slurp the command line until we see a 3-digit status code. - if [[ $method = "POST" || $method == "PUT" ]]; then + if [[ $method = "POST" || $method == "PUT" || $method = "DELETE" ]]; then local -a post_args for arg; do case "$arg" in @@ -261,6 +261,8 @@ function t() { *.tar) curl_args+=(--data-binary @$arg); content_type="application/x-tar"; shift;; + *.yaml) curl_args+=(--data-binary @$arg); + shift;; application/*) content_type="$arg"; shift;; [1-9][0-9][0-9]) break;; diff --git a/test/system/700-play.bats b/test/system/700-play.bats index 6c2a8c8b1..53e9a5274 100644 --- a/test/system/700-play.bats +++ b/test/system/700-play.bats @@ -65,12 +65,12 @@ status: {} RELABEL="system_u:object_r:container_file_t:s0" -@test "podman play with stdin" { +@test "podman kube with stdin" { TESTDIR=$PODMAN_TMPDIR/testdir mkdir -p $TESTDIR echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml - run_podman play kube - < $PODMAN_TMPDIR/test.yaml + run_podman kube play - < $PODMAN_TMPDIR/test.yaml if [ -e /usr/sbin/selinuxenabled -a /usr/sbin/selinuxenabled ]; then run ls -Zd $TESTDIR is "$output" "${RELABEL} $TESTDIR" "selinux relabel should have happened" @@ -86,6 +86,20 @@ RELABEL="system_u:object_r:container_file_t:s0" run_podman pod rm -t 0 -f test_pod } +@test "podman kube" { + TESTDIR=$PODMAN_TMPDIR/testdir + mkdir -p $TESTDIR + echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml + run_podman kube play $PODMAN_TMPDIR/test.yaml + if [ -e /usr/sbin/selinuxenabled -a /usr/sbin/selinuxenabled ]; then + run ls -Zd $TESTDIR + is "$output" "${RELABEL} $TESTDIR" "selinux relabel should have happened" + fi + + run_podman stop -a -t 0 + run_podman pod rm -t 0 -f test_pod +} + @test "podman play" { TESTDIR=$PODMAN_TMPDIR/testdir mkdir -p $TESTDIR @@ -159,13 +173,13 @@ EOF run_podman 1 container exists $service_container } -@test "podman play --network" { +@test "podman kube --network" { TESTDIR=$PODMAN_TMPDIR/testdir mkdir -p $TESTDIR echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml - run_podman 125 play kube --network host $PODMAN_TMPDIR/test.yaml + run_podman 125 kube play --network host $PODMAN_TMPDIR/test.yaml is "$output" ".*invalid value passed to --network: bridge or host networking must be configured in YAML" "podman plan-network should fail with --network host" - run_podman play kube --network slirp4netns:port_handler=slirp4netns $PODMAN_TMPDIR/test.yaml + run_podman kube play --network slirp4netns:port_handler=slirp4netns $PODMAN_TMPDIR/test.yaml run_podman pod inspect --format {{.InfraContainerID}} "${lines[1]}" infraID="$output" run_podman container inspect --format "{{.HostConfig.NetworkMode}}" $infraID @@ -174,7 +188,7 @@ EOF run_podman stop -a -t 0 run_podman pod rm -t 0 -f test_pod - run_podman play kube --network none $PODMAN_TMPDIR/test.yaml + run_podman kube play --network none $PODMAN_TMPDIR/test.yaml run_podman pod inspect --format {{.InfraContainerID}} "${lines[1]}" infraID="$output" run_podman container inspect --format "{{.HostConfig.NetworkMode}}" $infraID @@ -280,12 +294,12 @@ _EOF run_podman rmi -f userimage:latest } -@test "podman play --annotation" { +@test "podman kube --annotation" { TESTDIR=$PODMAN_TMPDIR/testdir RANDOMSTRING=$(random_string 15) mkdir -p $TESTDIR echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml - run_podman play kube --annotation "name=$RANDOMSTRING" $PODMAN_TMPDIR/test.yaml + run_podman kube play --annotation "name=$RANDOMSTRING" $PODMAN_TMPDIR/test.yaml run_podman inspect --format "{{ .Config.Annotations }}" test_pod-test is "$output" ".*name:$RANDOMSTRING" "Annotation should be added to pod" @@ -338,7 +352,7 @@ status: {} assert "$output" =~ "invalid annotation \"test\"=\"$RANDOMSTRING\"" "Expected to fail with annotation length greater than 63" } -@test "podman play kube - default log driver" { +@test "podman kube play - default log driver" { TESTDIR=$PODMAN_TMPDIR/testdir mkdir -p $TESTDIR echo "$testYaml" | sed "s|TESTDIR|${TESTDIR}|g" > $PODMAN_TMPDIR/test.yaml @@ -347,7 +361,7 @@ status: {} default_driver=$output # Make sure that the default log driver is used - run_podman play kube $PODMAN_TMPDIR/test.yaml + run_podman kube play $PODMAN_TMPDIR/test.yaml run_podman inspect --format "{{.HostConfig.LogConfig.Type}}" test_pod-test is "$output" "$default_driver" "play kube uses default log driver" -- cgit v1.2.3-54-g00ecf