Add --log-driver to play kube

addresses #6604

Signed-off-by: Andy Librian <andylibrian@gmail.com>
This commit is contained in:
Andy Librian
2020-11-07 12:44:30 +07:00
parent e2b82e6245
commit f3355d9697
7 changed files with 38 additions and 7 deletions

View File

@ -22,6 +22,7 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
query := struct {
Network string `schema:"reference"`
TLSVerify bool `schema:"tlsVerify"`
LogDriver string `schema:"logDriver"`
}{
TLSVerify: true,
}
@ -62,11 +63,12 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
containerEngine := abi.ContainerEngine{Libpod: runtime}
options := entities.PlayKubeOptions{
Authfile: authfile,
Username: username,
Password: password,
Network: query.Network,
Quiet: true,
Authfile: authfile,
Username: username,
Password: password,
Network: query.Network,
Quiet: true,
LogDriver: query.LogDriver,
}
if _, found := r.URL.Query()["tlsVerify"]; found {
options.SkipTLSVerify = types.NewOptionalBool(!query.TLSVerify)

View File

@ -25,6 +25,10 @@ func (s *APIServer) registerPlayHandlers(r *mux.Router) error {
// 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: body
// name: request
// description: Kubernetes YAML file.

View File

@ -28,6 +28,7 @@ func Kube(ctx context.Context, path string, options entities.PlayKubeOptions) (*
params := url.Values{}
params.Set("network", options.Network)
params.Set("logDriver", options.LogDriver)
if options.SkipTLSVerify != types.OptionalBoolUndefined {
params.Set("tlsVerify", strconv.FormatBool(options.SkipTLSVerify == types.OptionalBoolTrue))
}

View File

@ -26,6 +26,8 @@ type PlayKubeOptions struct {
SeccompProfileRoot string
// ConfigMaps - slice of pathnames to kubernetes configmap YAMLs.
ConfigMaps []string
// LogDriver for the container. For example: journald
LogDriver string
}
// PlayKubePod represents a single pod and associated containers created by play kube

View File

@ -351,7 +351,8 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
if err != nil {
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 {
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
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 (
containerConfig createconfig.CreateConfig
pidConfig createconfig.PidConfig
@ -593,6 +594,10 @@ func kubeContainerToCreateConfig(ctx context.Context, containerYAML v1.Container
containerConfig.User = userConfig
containerConfig.Security = securityConfig
if logDriver != "" {
containerConfig.LogDriver = logDriver
}
annotations := make(map[string]string)
if infraID != "" {
annotations[ann.SandboxID] = infraID