Skip to content

Commit

Permalink
Modified OS detection logic when updating http proxy settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
KashifSaadat committed Oct 10, 2017
1 parent 35cf4a3 commit 89da146
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 143 deletions.
2 changes: 2 additions & 0 deletions nodeup/pkg/model/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,11 @@ func (b *DockerBuilder) buildSysconfig(c *fi.ModelBuilderContext) error {
return fmt.Errorf("error building docker flags: %v", err)
}

// The system-wide environment file may include proxy settings if configured
lines := []string{
"DOCKER_OPTS=" + flagsString,
"DOCKER_NOFILE=1000000",
"source /etc/environment",
}
contents := strings.Join(lines, "\n")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
contents: |-
DOCKER_OPTS=
DOCKER_NOFILE=1000000
source /etc/environment
path: /etc/sysconfig/docker
type: file
---
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
@@ -1,6 +1,7 @@
contents: |-
DOCKER_OPTS=
DOCKER_NOFILE=1000000
source /etc/environment
path: /etc/sysconfig/docker
type: file
---
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
@@ -1,6 +1,7 @@
contents: |-
DOCKER_OPTS=
DOCKER_NOFILE=1000000
source /etc/environment
path: /etc/sysconfig/docker
type: file
---
Expand Down
55 changes: 21 additions & 34 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(" >> /etc/systemd/system.conf\n")
buffer.WriteString("echo \"export http_proxy=" + httpProxyURL + "\" >> /etc/environment\n")
buffer.WriteString("echo \"export https_proxy=" + httpProxyURL + "\" >> /etc/environment\n")
buffer.WriteString("echo \"export no_proxy=" + ps.ProxyExcludes + "\" >> /etc/environment\n")
buffer.WriteString("echo \"export NO_PROXY=" + ps.ProxyExcludes + "\" >> /etc/environment\n")

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

// Set env variables for package manager depending on OS Distribution
// 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")

// 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()
}
2 changes: 1 addition & 1 deletion pkg/model/bootstrapscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ 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 \"export http_proxy=http://example.com:80\" >> /etc/environment") {
t.Fatalf("script not setting http_proxy properly")
}

Expand Down
31 changes: 13 additions & 18 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
echo "export http_proxy=http://example.com:80" >> /etc/environment
echo "export https_proxy=http://example.com:80" >> /etc/environment
echo "export no_proxy=" >> /etc/environment
echo "export NO_PROXY=" >> /etc/environment
source /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
31 changes: 13 additions & 18 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
echo "export http_proxy=http://example.com:80" >> /etc/environment
echo "export https_proxy=http://example.com:80" >> /etc/environment
echo "export no_proxy=" >> /etc/environment
echo "export NO_PROXY=" >> /etc/environment
source /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
31 changes: 13 additions & 18 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
echo "export http_proxy=http://example.com:80" >> /etc/environment
echo "export https_proxy=http://example.com:80" >> /etc/environment
echo "export no_proxy=" >> /etc/environment
echo "export NO_PROXY=" >> /etc/environment
source /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
31 changes: 13 additions & 18 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
echo "export http_proxy=http://example.com:80" >> /etc/environment
echo "export https_proxy=http://example.com:80" >> /etc/environment
echo "export no_proxy=" >> /etc/environment
echo "export NO_PROXY=" >> /etc/environment
source /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
31 changes: 13 additions & 18 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
echo "export http_proxy=http://example.com:80" >> /etc/environment
echo "export https_proxy=http://example.com:80" >> /etc/environment
echo "export no_proxy=" >> /etc/environment
echo "export NO_PROXY=" >> /etc/environment
source /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
31 changes: 13 additions & 18 deletions pkg/model/tests/data/bootstrapscript_5.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
echo "export http_proxy=http://example.com:80" >> /etc/environment
echo "export https_proxy=http://example.com:80" >> /etc/environment
echo "export no_proxy=" >> /etc/environment
echo "export NO_PROXY=" >> /etc/environment
source /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

0 comments on commit 89da146

Please sign in to comment.