mirror of
https://github.com/containers/podman.git
synced 2025-06-21 09:28:09 +08:00
Merge pull request #8363 from AlbanBedel/play-kube-create-only
Add an option to control if play kube should start the pod
This commit is contained in:
@ -22,6 +22,7 @@ type playKubeOptionsWrapper struct {
|
|||||||
|
|
||||||
TLSVerifyCLI bool
|
TLSVerifyCLI bool
|
||||||
CredentialsCLI string
|
CredentialsCLI string
|
||||||
|
StartCLI bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -68,6 +69,7 @@ func init() {
|
|||||||
|
|
||||||
flags.BoolVarP(&kubeOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images")
|
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.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"
|
authfileFlagName := "authfile"
|
||||||
flags.StringVar(&kubeOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
|
flags.StringVar(&kubeOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
|
||||||
@ -100,6 +102,9 @@ func kube(cmd *cobra.Command, args []string) error {
|
|||||||
if cmd.Flags().Changed("tls-verify") {
|
if cmd.Flags().Changed("tls-verify") {
|
||||||
kubeOptions.SkipTLSVerify = types.NewOptionalBool(!kubeOptions.TLSVerifyCLI)
|
kubeOptions.SkipTLSVerify = types.NewOptionalBool(!kubeOptions.TLSVerifyCLI)
|
||||||
}
|
}
|
||||||
|
if cmd.Flags().Changed("start") {
|
||||||
|
kubeOptions.Start = types.NewOptionalBool(kubeOptions.StartCLI)
|
||||||
|
}
|
||||||
if kubeOptions.Authfile != "" {
|
if kubeOptions.Authfile != "" {
|
||||||
if _, err := os.Stat(kubeOptions.Authfile); err != nil {
|
if _, err := os.Stat(kubeOptions.Authfile); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -58,6 +58,10 @@ Suppress output information when pulling images
|
|||||||
|
|
||||||
Directory path for seccomp profiles (default: "/var/lib/kubelet/seccomp"). (Not available for remote commands)
|
Directory path for seccomp profiles (default: "/var/lib/kubelet/seccomp"). (Not available for remote commands)
|
||||||
|
|
||||||
|
#### **--start**=*true|false*
|
||||||
|
|
||||||
|
Start the pod after creating it, set to false to only create it.
|
||||||
|
|
||||||
#### **--tls-verify**=*true|false*
|
#### **--tls-verify**=*true|false*
|
||||||
|
|
||||||
Require HTTPS and verify certificates when contacting registries (default: true). If explicitly set to true,
|
Require HTTPS and verify certificates when contacting registries (default: true). If explicitly set to true,
|
||||||
|
@ -23,8 +23,10 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
|
|||||||
Network string `schema:"reference"`
|
Network string `schema:"reference"`
|
||||||
TLSVerify bool `schema:"tlsVerify"`
|
TLSVerify bool `schema:"tlsVerify"`
|
||||||
LogDriver string `schema:"logDriver"`
|
LogDriver string `schema:"logDriver"`
|
||||||
|
Start bool `schema:"start"`
|
||||||
}{
|
}{
|
||||||
TLSVerify: true,
|
TLSVerify: true,
|
||||||
|
Start: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||||
@ -73,6 +75,9 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
|
|||||||
if _, found := r.URL.Query()["tlsVerify"]; found {
|
if _, found := r.URL.Query()["tlsVerify"]; found {
|
||||||
options.SkipTLSVerify = types.NewOptionalBool(!query.TLSVerify)
|
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(), tmpfile.Name(), options)
|
report, err := containerEngine.PlayKube(r.Context(), tmpfile.Name(), options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -29,6 +29,11 @@ func (s *APIServer) registerPlayHandlers(r *mux.Router) error {
|
|||||||
// name: logDriver
|
// name: logDriver
|
||||||
// type: string
|
// type: string
|
||||||
// description: Logging driver for the containers in the pod.
|
// 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: body
|
// - in: body
|
||||||
// name: request
|
// name: request
|
||||||
// description: Kubernetes YAML file.
|
// description: Kubernetes YAML file.
|
||||||
|
@ -32,6 +32,9 @@ func Kube(ctx context.Context, path string, options entities.PlayKubeOptions) (*
|
|||||||
if options.SkipTLSVerify != types.OptionalBoolUndefined {
|
if options.SkipTLSVerify != types.OptionalBoolUndefined {
|
||||||
params.Set("tlsVerify", strconv.FormatBool(options.SkipTLSVerify != types.OptionalBoolTrue))
|
params.Set("tlsVerify", strconv.FormatBool(options.SkipTLSVerify != types.OptionalBoolTrue))
|
||||||
}
|
}
|
||||||
|
if options.Start != types.OptionalBoolUndefined {
|
||||||
|
params.Set("start", strconv.FormatBool(options.Start == types.OptionalBoolTrue))
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: have a global system context we can pass around (1st argument)
|
// TODO: have a global system context we can pass around (1st argument)
|
||||||
header, err := auth.Header(nil, auth.XRegistryAuthHeader, options.Authfile, options.Username, options.Password)
|
header, err := auth.Header(nil, auth.XRegistryAuthHeader, options.Authfile, options.Username, options.Password)
|
||||||
|
@ -28,6 +28,8 @@ type PlayKubeOptions struct {
|
|||||||
ConfigMaps []string
|
ConfigMaps []string
|
||||||
// LogDriver for the container. For example: journald
|
// LogDriver for the container. For example: journald
|
||||||
LogDriver string
|
LogDriver string
|
||||||
|
// Start - don't start the pod if false
|
||||||
|
Start types.OptionalBool
|
||||||
}
|
}
|
||||||
|
|
||||||
// PlayKubePod represents a single pod and associated containers created by play kube
|
// PlayKubePod represents a single pod and associated containers created by play kube
|
||||||
|
@ -297,20 +297,22 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
|
|||||||
containers = append(containers, ctr)
|
containers = append(containers, ctr)
|
||||||
}
|
}
|
||||||
|
|
||||||
//start the containers
|
if options.Start != types.OptionalBoolFalse {
|
||||||
podStartErrors, err := pod.Start(ctx)
|
//start the containers
|
||||||
if err != nil {
|
podStartErrors, err := pod.Start(ctx)
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Previous versions of playkube started containers individually and then
|
// Previous versions of playkube started containers individually and then
|
||||||
// looked for errors. Because we now use the uber-Pod start call, we should
|
// looked for errors. Because we now use the uber-Pod start call, we should
|
||||||
// iterate the map of possible errors and return one if there is a problem. This
|
// iterate the map of possible errors and return one if there is a problem. This
|
||||||
// keeps the behavior the same
|
// keeps the behavior the same
|
||||||
|
|
||||||
for _, e := range podStartErrors {
|
for _, e := range podStartErrors {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1482,4 +1482,19 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`})
|
|||||||
Expect(inspect.ExitCode()).To(Equal(0))
|
Expect(inspect.ExitCode()).To(Equal(0))
|
||||||
Expect(inspect.OutputToString()).To(ContainSubstring("journald"))
|
Expect(inspect.OutputToString()).To(ContainSubstring("journald"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman play kube test only creating the containers", func() {
|
||||||
|
pod := getPod()
|
||||||
|
err := generateKubeYaml("pod", pod, kubeYaml)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
kube := podmanTest.Podman([]string{"play", "kube", "--start=false", kubeYaml})
|
||||||
|
kube.WaitWithDefaultTimeout()
|
||||||
|
Expect(kube.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "{{ .State.Running }}"})
|
||||||
|
inspect.WaitWithDefaultTimeout()
|
||||||
|
Expect(inspect.ExitCode()).To(Equal(0))
|
||||||
|
Expect(inspect.OutputToString()).To(Equal("false"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user