mirror of
https://github.com/containers/podman.git
synced 2025-06-23 18:59:30 +08:00
Add --log-driver to play kube
addresses #6604 Signed-off-by: Andy Librian <andylibrian@gmail.com>
This commit is contained in:
cmd/podman/play
pkg
api
bindings/play
domain
test/e2e
@ -52,6 +52,7 @@ func init() {
|
|||||||
flags.SetNormalizeFunc(utils.AliasFlags)
|
flags.SetNormalizeFunc(utils.AliasFlags)
|
||||||
flags.StringVar(&kubeOptions.CredentialsCLI, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
|
flags.StringVar(&kubeOptions.CredentialsCLI, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
|
||||||
flags.StringVar(&kubeOptions.Network, "network", "", "Connect pod to CNI network(s)")
|
flags.StringVar(&kubeOptions.Network, "network", "", "Connect pod to CNI network(s)")
|
||||||
|
flags.StringVar(&kubeOptions.LogDriver, "log-driver", "", "Logging driver for the container")
|
||||||
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.StringVar(&kubeOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
|
flags.StringVar(&kubeOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
|
||||||
|
@ -22,6 +22,7 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
|
|||||||
query := struct {
|
query := struct {
|
||||||
Network string `schema:"reference"`
|
Network string `schema:"reference"`
|
||||||
TLSVerify bool `schema:"tlsVerify"`
|
TLSVerify bool `schema:"tlsVerify"`
|
||||||
|
LogDriver string `schema:"logDriver"`
|
||||||
}{
|
}{
|
||||||
TLSVerify: true,
|
TLSVerify: true,
|
||||||
}
|
}
|
||||||
@ -67,6 +68,7 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
|
|||||||
Password: password,
|
Password: password,
|
||||||
Network: query.Network,
|
Network: query.Network,
|
||||||
Quiet: true,
|
Quiet: true,
|
||||||
|
LogDriver: query.LogDriver,
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
@ -25,6 +25,10 @@ func (s *APIServer) registerPlayHandlers(r *mux.Router) error {
|
|||||||
// type: boolean
|
// type: boolean
|
||||||
// default: true
|
// default: true
|
||||||
// description: Require HTTPS and verify signatures when contacting registries.
|
// 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: body
|
// - in: body
|
||||||
// name: request
|
// name: request
|
||||||
// description: Kubernetes YAML file.
|
// description: Kubernetes YAML file.
|
||||||
|
@ -28,6 +28,7 @@ func Kube(ctx context.Context, path string, options entities.PlayKubeOptions) (*
|
|||||||
|
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Set("network", options.Network)
|
params.Set("network", options.Network)
|
||||||
|
params.Set("logDriver", options.LogDriver)
|
||||||
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))
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ type PlayKubeOptions struct {
|
|||||||
SeccompProfileRoot string
|
SeccompProfileRoot string
|
||||||
// ConfigMaps - slice of pathnames to kubernetes configmap YAMLs.
|
// ConfigMaps - slice of pathnames to kubernetes configmap YAMLs.
|
||||||
ConfigMaps []string
|
ConfigMaps []string
|
||||||
|
// LogDriver for the container. For example: journald
|
||||||
|
LogDriver string
|
||||||
}
|
}
|
||||||
|
|
||||||
// PlayKubePod represents a single pod and associated containers created by play kube
|
// PlayKubePod represents a single pod and associated containers created by play kube
|
||||||
|
@ -351,7 +351,8 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
conf, err := kubeContainerToCreateConfig(ctx, container, newImage, namespaces, volumes, pod.ID(), podName, podInfraID, configMaps, seccompPaths)
|
|
||||||
|
conf, err := kubeContainerToCreateConfig(ctx, container, newImage, namespaces, volumes, pod.ID(), podName, podInfraID, configMaps, seccompPaths, options.LogDriver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -464,7 +465,7 @@ func setupSecurityContext(securityConfig *createconfig.SecurityConfig, userConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// kubeContainerToCreateConfig takes a v1.Container and returns a createconfig describing a container
|
// kubeContainerToCreateConfig takes a v1.Container and returns a createconfig describing a container
|
||||||
func kubeContainerToCreateConfig(ctx context.Context, containerYAML v1.Container, newImage *image.Image, namespaces map[string]string, volumes map[string]string, podID, podName, infraID string, configMaps []v1.ConfigMap, seccompPaths *kubeSeccompPaths) (*createconfig.CreateConfig, error) {
|
func kubeContainerToCreateConfig(ctx context.Context, containerYAML v1.Container, newImage *image.Image, namespaces map[string]string, volumes map[string]string, podID, podName, infraID string, configMaps []v1.ConfigMap, seccompPaths *kubeSeccompPaths, logDriver string) (*createconfig.CreateConfig, error) {
|
||||||
var (
|
var (
|
||||||
containerConfig createconfig.CreateConfig
|
containerConfig createconfig.CreateConfig
|
||||||
pidConfig createconfig.PidConfig
|
pidConfig createconfig.PidConfig
|
||||||
@ -593,6 +594,10 @@ func kubeContainerToCreateConfig(ctx context.Context, containerYAML v1.Container
|
|||||||
containerConfig.User = userConfig
|
containerConfig.User = userConfig
|
||||||
containerConfig.Security = securityConfig
|
containerConfig.Security = securityConfig
|
||||||
|
|
||||||
|
if logDriver != "" {
|
||||||
|
containerConfig.LogDriver = logDriver
|
||||||
|
}
|
||||||
|
|
||||||
annotations := make(map[string]string)
|
annotations := make(map[string]string)
|
||||||
if infraID != "" {
|
if infraID != "" {
|
||||||
annotations[ann.SandboxID] = infraID
|
annotations[ann.SandboxID] = infraID
|
||||||
|
@ -1466,4 +1466,20 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`})
|
|||||||
Expect(kube.ExitCode()).To(Equal(125))
|
Expect(kube.ExitCode()).To(Equal(125))
|
||||||
Expect(kube.ErrorToString()).To(ContainSubstring(invalidImageName))
|
Expect(kube.ErrorToString()).To(ContainSubstring(invalidImageName))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman play kube applies log driver to containers", func() {
|
||||||
|
Skip("need to verify images have correct packages for journald")
|
||||||
|
pod := getPod()
|
||||||
|
err := generateKubeYaml("pod", pod, kubeYaml)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
kube := podmanTest.Podman([]string{"play", "kube", "--log-driver", "journald", kubeYaml})
|
||||||
|
kube.WaitWithDefaultTimeout()
|
||||||
|
Expect(kube.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod), "--format", "'{{ .HostConfig.LogConfig.Type }}'"})
|
||||||
|
inspect.WaitWithDefaultTimeout()
|
||||||
|
Expect(inspect.ExitCode()).To(Equal(0))
|
||||||
|
Expect(inspect.OutputToString()).To(ContainSubstring("journald"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user