mirror of https://github.com/kubernetes/kops.git
exec target command, but still pipe it to tee
Equivalent of https://github.com/kubernetes/kubernetes/pull/57756
This commit is contained in:
parent
6bcc86bc0f
commit
7ca593b994
|
@ -21,14 +21,14 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/kops/pkg/apis/kops"
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
|
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// s is a helper that builds a *string from a string value
|
// s is a helper that builds a *string from a string value
|
||||||
|
@ -187,3 +187,19 @@ func addHostPathMapping(pod *v1.Pod, container *v1.Container, name, path string)
|
||||||
func convEtcdSettingsToMs(dur *metav1.Duration) string {
|
func convEtcdSettingsToMs(dur *metav1.Duration) string {
|
||||||
return strconv.FormatInt(dur.Nanoseconds()/1000000, 10)
|
return strconv.FormatInt(dur.Nanoseconds()/1000000, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// execWithTee returns the command to run the command while piping output to both the log file and stdout/stderr
|
||||||
|
func execWithTee(cmd string, args []string, logfile string) []string {
|
||||||
|
// exec so we don't have a shell that doesn't pass signals to the real process
|
||||||
|
execCmd := "exec " + cmd + " " + strings.Join(args, " ")
|
||||||
|
|
||||||
|
// NOTE: tee & mkfifo is in /usr/bin in the kube-proxy image, but /bin in other images
|
||||||
|
|
||||||
|
// Bash supports something like this, but dash and other limited shells don't
|
||||||
|
//shCmd := "exec &> >(/usr/bin/tee -a " + logfile + "); " + execCmd
|
||||||
|
// Instead we create the pipe manually and wire up the tee:
|
||||||
|
shCmd := "mkfifo /tmp/pipe; (tee -a " + logfile + " < /tmp/pipe & ) ; " + execCmd + " > /tmp/pipe 2>&1"
|
||||||
|
|
||||||
|
// Execute shell command
|
||||||
|
return []string{"/bin/sh", "-c", shCmd}
|
||||||
|
}
|
||||||
|
|
|
@ -247,10 +247,10 @@ func (b *KubeAPIServerBuilder) buildPod() (*v1.Pod, error) {
|
||||||
container := &v1.Container{
|
container := &v1.Container{
|
||||||
Name: "kube-apiserver",
|
Name: "kube-apiserver",
|
||||||
Image: b.Cluster.Spec.KubeAPIServer.Image,
|
Image: b.Cluster.Spec.KubeAPIServer.Image,
|
||||||
Command: []string{
|
Command: execWithTee(
|
||||||
"/bin/sh", "-c",
|
"/usr/local/bin/kube-apiserver",
|
||||||
"/usr/local/bin/kube-apiserver " + strings.Join(sortedStrings(flags), " ") + " 2>&1 | /bin/tee -a /var/log/kube-apiserver.log",
|
sortedStrings(flags),
|
||||||
},
|
"/var/log/kube-apiserver.log"),
|
||||||
Env: getProxyEnvVars(b.Cluster.Spec.EgressProxy),
|
Env: getProxyEnvVars(b.Cluster.Spec.EgressProxy),
|
||||||
LivenessProbe: &v1.Probe{
|
LivenessProbe: &v1.Probe{
|
||||||
Handler: v1.Handler{
|
Handler: v1.Handler{
|
||||||
|
|
|
@ -167,10 +167,10 @@ func (b *KubeControllerManagerBuilder) buildPod() (*v1.Pod, error) {
|
||||||
container := &v1.Container{
|
container := &v1.Container{
|
||||||
Name: "kube-controller-manager",
|
Name: "kube-controller-manager",
|
||||||
Image: b.Cluster.Spec.KubeControllerManager.Image,
|
Image: b.Cluster.Spec.KubeControllerManager.Image,
|
||||||
Command: []string{
|
Command: execWithTee(
|
||||||
"/bin/sh", "-c",
|
"/usr/local/bin/kube-controller-manager",
|
||||||
"/usr/local/bin/kube-controller-manager " + strings.Join(sortedStrings(flags), " ") + " 2>&1 | /bin/tee -a /var/log/kube-controller-manager.log",
|
sortedStrings(flags),
|
||||||
},
|
"/var/log/kube-controller-manager.log"),
|
||||||
Env: getProxyEnvVars(b.Cluster.Spec.EgressProxy),
|
Env: getProxyEnvVars(b.Cluster.Spec.EgressProxy),
|
||||||
LivenessProbe: &v1.Probe{
|
LivenessProbe: &v1.Probe{
|
||||||
Handler: v1.Handler{
|
Handler: v1.Handler{
|
||||||
|
|
|
@ -18,7 +18,6 @@ package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"k8s.io/kops/pkg/dns"
|
"k8s.io/kops/pkg/dns"
|
||||||
"k8s.io/kops/pkg/flagbuilder"
|
"k8s.io/kops/pkg/flagbuilder"
|
||||||
|
@ -144,10 +143,10 @@ func (b *KubeProxyBuilder) buildPod() (*v1.Pod, error) {
|
||||||
container := &v1.Container{
|
container := &v1.Container{
|
||||||
Name: "kube-proxy",
|
Name: "kube-proxy",
|
||||||
Image: image,
|
Image: image,
|
||||||
Command: []string{
|
Command: execWithTee(
|
||||||
"/bin/sh", "-c",
|
"/usr/local/bin/kube-proxy",
|
||||||
"/usr/local/bin/kube-proxy " + strings.Join(sortedStrings(flags), " ") + " 2>&1 | /usr/bin/tee -a /var/log/kube-proxy.log",
|
sortedStrings(flags),
|
||||||
},
|
"/var/log/kube-proxy.log"),
|
||||||
Resources: v1.ResourceRequirements{
|
Resources: v1.ResourceRequirements{
|
||||||
Requests: v1.ResourceList{
|
Requests: v1.ResourceList{
|
||||||
"cpu": cpuRequest,
|
"cpu": cpuRequest,
|
||||||
|
|
|
@ -18,7 +18,6 @@ package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"k8s.io/kops/pkg/flagbuilder"
|
"k8s.io/kops/pkg/flagbuilder"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
@ -125,10 +124,10 @@ func (b *KubeSchedulerBuilder) buildPod() (*v1.Pod, error) {
|
||||||
container := &v1.Container{
|
container := &v1.Container{
|
||||||
Name: "kube-scheduler",
|
Name: "kube-scheduler",
|
||||||
Image: c.Image,
|
Image: c.Image,
|
||||||
Command: []string{
|
Command: execWithTee(
|
||||||
"/bin/sh", "-c",
|
"/usr/local/bin/kube-scheduler",
|
||||||
"/usr/local/bin/kube-scheduler " + strings.Join(sortedStrings(flags), " ") + " 2>&1 | /bin/tee -a /var/log/kube-scheduler.log",
|
sortedStrings(flags),
|
||||||
},
|
"/var/log/kube-scheduler.log"),
|
||||||
Env: getProxyEnvVars(b.Cluster.Spec.EgressProxy),
|
Env: getProxyEnvVars(b.Cluster.Spec.EgressProxy),
|
||||||
LivenessProbe: &v1.Probe{
|
LivenessProbe: &v1.Probe{
|
||||||
Handler: v1.Handler{
|
Handler: v1.Handler{
|
||||||
|
|
|
@ -45,7 +45,10 @@ func BuildEtcdManifest(c *EtcdCluster) *v1.Pod {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Command: []string{
|
Command: []string{
|
||||||
"/bin/sh", "-c", "/usr/local/bin/etcd 2>&1 | /bin/tee -a /var/log/etcd.log",
|
"/bin/sh", "-c",
|
||||||
|
"/bin/mkfifo /tmp/pipe; " +
|
||||||
|
"(/bin/tee -a /var/log/etcd.log < /tmp/pipe & ); " +
|
||||||
|
"exec /usr/local/bin/etcd > /tmp/pipe 2>&1",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// build the environment variables for etcd service
|
// build the environment variables for etcd service
|
||||||
|
|
|
@ -37,7 +37,8 @@ spec:
|
||||||
- command:
|
- command:
|
||||||
- /bin/sh
|
- /bin/sh
|
||||||
- -c
|
- -c
|
||||||
- /usr/local/bin/etcd 2>&1 | /bin/tee -a /var/log/etcd.log
|
- /bin/mkfifo /tmp/pipe; (/bin/tee -a /var/log/etcd.log < /tmp/pipe & ); exec
|
||||||
|
/usr/local/bin/etcd > /tmp/pipe 2>&1
|
||||||
env:
|
env:
|
||||||
- name: ETCD_NAME
|
- name: ETCD_NAME
|
||||||
value: node0
|
value: node0
|
||||||
|
|
|
@ -35,7 +35,8 @@ spec:
|
||||||
- command:
|
- command:
|
||||||
- /bin/sh
|
- /bin/sh
|
||||||
- -c
|
- -c
|
||||||
- /usr/local/bin/etcd 2>&1 | /bin/tee -a /var/log/etcd.log
|
- /bin/mkfifo /tmp/pipe; (/bin/tee -a /var/log/etcd.log < /tmp/pipe & ); exec
|
||||||
|
/usr/local/bin/etcd > /tmp/pipe 2>&1
|
||||||
env:
|
env:
|
||||||
- name: ETCD_NAME
|
- name: ETCD_NAME
|
||||||
value: node0
|
value: node0
|
||||||
|
|
|
@ -41,7 +41,8 @@ spec:
|
||||||
- command:
|
- command:
|
||||||
- /bin/sh
|
- /bin/sh
|
||||||
- -c
|
- -c
|
||||||
- /usr/local/bin/etcd 2>&1 | /bin/tee -a /var/log/etcd.log
|
- /bin/mkfifo /tmp/pipe; (/bin/tee -a /var/log/etcd.log < /tmp/pipe & ); exec
|
||||||
|
/usr/local/bin/etcd > /tmp/pipe 2>&1
|
||||||
env:
|
env:
|
||||||
- name: ETCD_NAME
|
- name: ETCD_NAME
|
||||||
value: node0
|
value: node0
|
||||||
|
|
Loading…
Reference in New Issue