Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified OS detection logic when updating http proxy settings. #3587

Merged
merged 1 commit into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions nodeup/pkg/bootstrap/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ package bootstrap
import (
"bytes"
"fmt"
"os"
"strings"
"time"

"github.com/golang/glog"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kops/nodeup/pkg/distros"
Expand All @@ -27,9 +31,6 @@ import (
"k8s.io/kops/upup/pkg/fi/nodeup/local"
"k8s.io/kops/upup/pkg/fi/nodeup/nodetasks"
"k8s.io/kops/util/pkg/vfs"
"os"
"strings"
"time"
)

type Installation struct {
Expand Down Expand Up @@ -138,6 +139,7 @@ func (i *Installation) buildSystemdJob() *nodetasks.Service {
manifest.Set("Service", "Environment", buffer.String())
}

manifest.Set("Service", "EnvironmentFile", "/etc/environment")
manifest.Set("Service", "ExecStart", command)
manifest.Set("Service", "Type", "oneshot")

Expand Down
2 changes: 2 additions & 0 deletions nodeup/pkg/model/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ func (b *DockerBuilder) buildSystemdService(dockerVersionMajor int64, dockerVers

manifest.Set("Service", "Type", "notify")
manifest.Set("Service", "EnvironmentFile", "/etc/sysconfig/docker")
manifest.Set("Service", "EnvironmentFile", "/etc/environment")

if usesDockerSocket {
manifest.Set("Service", "ExecStart", dockerdCommand+" -H fd:// \"$DOCKER_OPTS\"")
Expand Down Expand Up @@ -632,6 +633,7 @@ func (b *DockerBuilder) buildContainerOSConfigurationDropIn(c *fi.ModelBuilderCo
lines := []string{
"[Service]",
"EnvironmentFile=/etc/sysconfig/docker",
"EnvironmentFile=/etc/environment",
}
contents := strings.Join(lines, "\n")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ definition: |
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/docker
EnvironmentFile=/etc/environment
ExecStart=/usr/bin/dockerd -H fd:// "$DOCKER_OPTS"
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
Expand Down
1 change: 1 addition & 0 deletions nodeup/pkg/model/tests/dockerbuilder/logflags/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ definition: |
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/docker
EnvironmentFile=/etc/environment
ExecStart=/usr/bin/dockerd -H fd:// "$DOCKER_OPTS"
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
Expand Down
1 change: 1 addition & 0 deletions nodeup/pkg/model/tests/dockerbuilder/simple/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ definition: |
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/docker
EnvironmentFile=/etc/environment
ExecStart=/usr/bin/dockerd -H fd:// "$DOCKER_OPTS"
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
Expand Down
57 changes: 22 additions & 35 deletions pkg/model/bootstrapscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,47 +282,34 @@ func (b *BootstrapScript) createProxyEnv(ps *kops.EgressProxySpec) string {
httpProxyURL += ps.HTTPProxy.Host
}

// Set base env variables
buffer.WriteString("export http_proxy=" + httpProxyURL + "\n")
buffer.WriteString("export https_proxy=${http_proxy}\n")
buffer.WriteString("export no_proxy=" + ps.ProxyExcludes + "\n")
buffer.WriteString("export NO_PROXY=${no_proxy}\n")

// TODO move the rest of this configuration work to nodeup

// Set env variables for docker
buffer.WriteString("echo \"export http_proxy=${http_proxy}\" >> /etc/default/docker\n")
buffer.WriteString("echo \"export https_proxy=${http_proxy}\" >> /etc/default/docker\n")
buffer.WriteString("echo \"export no_proxy=${no_proxy}\" >> /etc/default/docker\n")
buffer.WriteString("echo \"export NO_PROXY=${no_proxy}\" >> /etc/default/docker\n")

// Set env variables for base environment
buffer.WriteString("echo \"export http_proxy=${http_proxy}\" >> /etc/environment\n")
buffer.WriteString("echo \"export https_proxy=${http_proxy}\" >> /etc/environment\n")
buffer.WriteString("echo \"export no_proxy=${no_proxy}\" >> /etc/environment\n")
buffer.WriteString("echo \"export NO_PROXY=${no_proxy}\" >> /etc/environment\n")

// Set env variables to systemd
buffer.WriteString("echo DefaultEnvironment=\\\"http_proxy=${http_proxy}\\\" \\\"https_proxy=${http_proxy}\\\"")
buffer.WriteString("echo DefaultEnvironment=\\\"http_proxy=${http_proxy}\\\" \\\"https_proxy=${http_proxy}\\\"")
buffer.WriteString(" \\\"NO_PROXY=${no_proxy}\\\" \\\"no_proxy=${no_proxy}\\\"")
buffer.WriteString(`echo "http_proxy=` + httpProxyURL + `" >> /etc/environment` + "\n")
buffer.WriteString(`echo "https_proxy=` + httpProxyURL + `" >> /etc/environment` + "\n")
buffer.WriteString(`echo "no_proxy=` + ps.ProxyExcludes + `" >> /etc/environment` + "\n")
buffer.WriteString(`echo "NO_PROXY=` + ps.ProxyExcludes + `" >> /etc/environment` + "\n")

// Load the proxy environment variables
buffer.WriteString("while read in; do export $in; done < /etc/environment\n")

// Set env variables for package manager depending on OS Distribution (N/A for CoreOS)
// Note: Nodeup will source the `/etc/environment` file within docker config in the correct location
buffer.WriteString("case `cat /proc/version` in\n")
buffer.WriteString("*[Dd]ebian*)\n")
buffer.WriteString(` echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;` + "\n")
buffer.WriteString("*[Uu]buntu*)\n")
buffer.WriteString(` echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;` + "\n")
buffer.WriteString("*[Rr]ed[Hh]at*)\n")
buffer.WriteString(` echo "http_proxy=${http_proxy}" >> /etc/yum.conf ;;` + "\n")
buffer.WriteString("esac\n")

// Set env variables for systemd
buffer.WriteString(`echo "DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\"`)
buffer.WriteString(` \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\""`)
buffer.WriteString(" >> /etc/systemd/system.conf\n")

// source in the environment this step ensures that environment file is correct
buffer.WriteString("source /etc/environment\n")

// Restart stuff
buffer.WriteString("systemctl daemon-reload\n")
buffer.WriteString("systemctl daemon-reexec\n")

// TODO do we need no_proxy in these as well??
// TODO handle CoreOS
// Depending on OS set package manager proxy settings
buffer.WriteString("if [ -f /etc/lsb-release ] || [ -f /etc/debian_version ]; then\n")
buffer.WriteString(" echo \"Acquire::http::Proxy \\\"${http_proxy}\\\";\" > /etc/apt/apt.conf.d/30proxy\n")
buffer.WriteString("elif [ -f /etc/redhat-release ]; then\n")
buffer.WriteString(" echo \"http_proxy=${http_proxy}\" >> /etc/yum.conf\n")
buffer.WriteString("fi\n")
}
return buffer.String()
}
4 changes: 2 additions & 2 deletions pkg/model/bootstrapscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func Test_ProxyFunc(t *testing.T) {
t.Fatalf("script cannot be empty")
}

if !strings.HasPrefix(script, "export http_proxy=http://example.com:80") {
if !strings.HasPrefix(script, "echo \"http_proxy=http://example.com:80\" >> /etc/environment") {
t.Fatalf("script not setting http_proxy properly")
}

ps.ProxyExcludes = "www.google.com,www.kubernetes.io"

script = b.createProxyEnv(ps)
if !strings.Contains(script, "export no_proxy="+ps.ProxyExcludes) {
if !strings.Contains(script, "no_proxy="+ps.ProxyExcludes) {
t.Fatalf("script not setting no_proxy properly")
}
}
Expand Down
33 changes: 14 additions & 19 deletions pkg/model/tests/data/bootstrapscript_0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,22 @@ NODEUP_HASH=NUSHash



export http_proxy=http://example.com:80
export https_proxy=${http_proxy}
export no_proxy=
export NO_PROXY=${no_proxy}
echo "export http_proxy=${http_proxy}" >> /etc/default/docker
echo "export https_proxy=${http_proxy}" >> /etc/default/docker
echo "export no_proxy=${no_proxy}" >> /etc/default/docker
echo "export NO_PROXY=${no_proxy}" >> /etc/default/docker
echo "export http_proxy=${http_proxy}" >> /etc/environment
echo "export https_proxy=${http_proxy}" >> /etc/environment
echo "export no_proxy=${no_proxy}" >> /etc/environment
echo "export NO_PROXY=${no_proxy}" >> /etc/environment
echo DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\"echo DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\" \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\" >> /etc/systemd/system.conf
source /etc/environment
echo "http_proxy=http://example.com:80" >> /etc/environment
echo "https_proxy=http://example.com:80" >> /etc/environment
echo "no_proxy=" >> /etc/environment
echo "NO_PROXY=" >> /etc/environment
while read in; do export $in; done < /etc/environment
case `cat /proc/version` in
*[Dd]ebian*)
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;
*[Uu]buntu*)
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;
*[Rr]ed[Hh]at*)
echo "http_proxy=${http_proxy}" >> /etc/yum.conf ;;
esac
echo "DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\" \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\"" >> /etc/systemd/system.conf
systemctl daemon-reload
systemctl daemon-reexec
if [ -f /etc/lsb-release ] || [ -f /etc/debian_version ]; then
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy
elif [ -f /etc/redhat-release ]; then
echo "http_proxy=${http_proxy}" >> /etc/yum.conf
fi


function ensure-install-dir() {
Expand Down
33 changes: 14 additions & 19 deletions pkg/model/tests/data/bootstrapscript_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,22 @@ NODEUP_HASH=NUSHash



export http_proxy=http://example.com:80
export https_proxy=${http_proxy}
export no_proxy=
export NO_PROXY=${no_proxy}
echo "export http_proxy=${http_proxy}" >> /etc/default/docker
echo "export https_proxy=${http_proxy}" >> /etc/default/docker
echo "export no_proxy=${no_proxy}" >> /etc/default/docker
echo "export NO_PROXY=${no_proxy}" >> /etc/default/docker
echo "export http_proxy=${http_proxy}" >> /etc/environment
echo "export https_proxy=${http_proxy}" >> /etc/environment
echo "export no_proxy=${no_proxy}" >> /etc/environment
echo "export NO_PROXY=${no_proxy}" >> /etc/environment
echo DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\"echo DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\" \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\" >> /etc/systemd/system.conf
source /etc/environment
echo "http_proxy=http://example.com:80" >> /etc/environment
echo "https_proxy=http://example.com:80" >> /etc/environment
echo "no_proxy=" >> /etc/environment
echo "NO_PROXY=" >> /etc/environment
while read in; do export $in; done < /etc/environment
case `cat /proc/version` in
*[Dd]ebian*)
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;
*[Uu]buntu*)
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;
*[Rr]ed[Hh]at*)
echo "http_proxy=${http_proxy}" >> /etc/yum.conf ;;
esac
echo "DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\" \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\"" >> /etc/systemd/system.conf
systemctl daemon-reload
systemctl daemon-reexec
if [ -f /etc/lsb-release ] || [ -f /etc/debian_version ]; then
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy
elif [ -f /etc/redhat-release ]; then
echo "http_proxy=${http_proxy}" >> /etc/yum.conf
fi


function ensure-install-dir() {
Expand Down
33 changes: 14 additions & 19 deletions pkg/model/tests/data/bootstrapscript_2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,22 @@ NODEUP_HASH=NUSHash



export http_proxy=http://example.com:80
export https_proxy=${http_proxy}
export no_proxy=
export NO_PROXY=${no_proxy}
echo "export http_proxy=${http_proxy}" >> /etc/default/docker
echo "export https_proxy=${http_proxy}" >> /etc/default/docker
echo "export no_proxy=${no_proxy}" >> /etc/default/docker
echo "export NO_PROXY=${no_proxy}" >> /etc/default/docker
echo "export http_proxy=${http_proxy}" >> /etc/environment
echo "export https_proxy=${http_proxy}" >> /etc/environment
echo "export no_proxy=${no_proxy}" >> /etc/environment
echo "export NO_PROXY=${no_proxy}" >> /etc/environment
echo DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\"echo DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\" \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\" >> /etc/systemd/system.conf
source /etc/environment
echo "http_proxy=http://example.com:80" >> /etc/environment
echo "https_proxy=http://example.com:80" >> /etc/environment
echo "no_proxy=" >> /etc/environment
echo "NO_PROXY=" >> /etc/environment
while read in; do export $in; done < /etc/environment
case `cat /proc/version` in
*[Dd]ebian*)
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;
*[Uu]buntu*)
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;
*[Rr]ed[Hh]at*)
echo "http_proxy=${http_proxy}" >> /etc/yum.conf ;;
esac
echo "DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\" \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\"" >> /etc/systemd/system.conf
systemctl daemon-reload
systemctl daemon-reexec
if [ -f /etc/lsb-release ] || [ -f /etc/debian_version ]; then
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy
elif [ -f /etc/redhat-release ]; then
echo "http_proxy=${http_proxy}" >> /etc/yum.conf
fi


function ensure-install-dir() {
Expand Down
33 changes: 14 additions & 19 deletions pkg/model/tests/data/bootstrapscript_3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,22 @@ NODEUP_HASH=NUSHash



export http_proxy=http://example.com:80
export https_proxy=${http_proxy}
export no_proxy=
export NO_PROXY=${no_proxy}
echo "export http_proxy=${http_proxy}" >> /etc/default/docker
echo "export https_proxy=${http_proxy}" >> /etc/default/docker
echo "export no_proxy=${no_proxy}" >> /etc/default/docker
echo "export NO_PROXY=${no_proxy}" >> /etc/default/docker
echo "export http_proxy=${http_proxy}" >> /etc/environment
echo "export https_proxy=${http_proxy}" >> /etc/environment
echo "export no_proxy=${no_proxy}" >> /etc/environment
echo "export NO_PROXY=${no_proxy}" >> /etc/environment
echo DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\"echo DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\" \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\" >> /etc/systemd/system.conf
source /etc/environment
echo "http_proxy=http://example.com:80" >> /etc/environment
echo "https_proxy=http://example.com:80" >> /etc/environment
echo "no_proxy=" >> /etc/environment
echo "NO_PROXY=" >> /etc/environment
while read in; do export $in; done < /etc/environment
case `cat /proc/version` in
*[Dd]ebian*)
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;
*[Uu]buntu*)
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;
*[Rr]ed[Hh]at*)
echo "http_proxy=${http_proxy}" >> /etc/yum.conf ;;
esac
echo "DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\" \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\"" >> /etc/systemd/system.conf
systemctl daemon-reload
systemctl daemon-reexec
if [ -f /etc/lsb-release ] || [ -f /etc/debian_version ]; then
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy
elif [ -f /etc/redhat-release ]; then
echo "http_proxy=${http_proxy}" >> /etc/yum.conf
fi


function ensure-install-dir() {
Expand Down
33 changes: 14 additions & 19 deletions pkg/model/tests/data/bootstrapscript_4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,22 @@ NODEUP_HASH=NUSHash



export http_proxy=http://example.com:80
export https_proxy=${http_proxy}
export no_proxy=
export NO_PROXY=${no_proxy}
echo "export http_proxy=${http_proxy}" >> /etc/default/docker
echo "export https_proxy=${http_proxy}" >> /etc/default/docker
echo "export no_proxy=${no_proxy}" >> /etc/default/docker
echo "export NO_PROXY=${no_proxy}" >> /etc/default/docker
echo "export http_proxy=${http_proxy}" >> /etc/environment
echo "export https_proxy=${http_proxy}" >> /etc/environment
echo "export no_proxy=${no_proxy}" >> /etc/environment
echo "export NO_PROXY=${no_proxy}" >> /etc/environment
echo DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\"echo DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\" \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\" >> /etc/systemd/system.conf
source /etc/environment
echo "http_proxy=http://example.com:80" >> /etc/environment
echo "https_proxy=http://example.com:80" >> /etc/environment
echo "no_proxy=" >> /etc/environment
echo "NO_PROXY=" >> /etc/environment
while read in; do export $in; done < /etc/environment
case `cat /proc/version` in
*[Dd]ebian*)
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;
*[Uu]buntu*)
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy ;;
*[Rr]ed[Hh]at*)
echo "http_proxy=${http_proxy}" >> /etc/yum.conf ;;
esac
echo "DefaultEnvironment=\"http_proxy=${http_proxy}\" \"https_proxy=${http_proxy}\" \"NO_PROXY=${no_proxy}\" \"no_proxy=${no_proxy}\"" >> /etc/systemd/system.conf
systemctl daemon-reload
systemctl daemon-reexec
if [ -f /etc/lsb-release ] || [ -f /etc/debian_version ]; then
echo "Acquire::http::Proxy \"${http_proxy}\";" > /etc/apt/apt.conf.d/30proxy
elif [ -f /etc/redhat-release ]; then
echo "http_proxy=${http_proxy}" >> /etc/yum.conf
fi


function ensure-install-dir() {
Expand Down
Loading