Skip to content

Commit

Permalink
cluster up: add proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
csrwng committed Jan 17, 2017
1 parent 0b38fe0 commit 0e3dcb9
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 7 deletions.
6 changes: 6 additions & 0 deletions contrib/completions/bash/oc
Original file line number Diff line number Diff line change
Expand Up @@ -5611,6 +5611,10 @@ _oc_cluster_up()
local_nonpersistent_flags+=("--host-data-dir=")
flags+=("--host-volumes-dir=")
local_nonpersistent_flags+=("--host-volumes-dir=")
flags+=("--http-proxy=")
local_nonpersistent_flags+=("--http-proxy=")
flags+=("--https-proxy=")
local_nonpersistent_flags+=("--https-proxy=")
flags+=("--image=")
local_nonpersistent_flags+=("--image=")
flags+=("--image-streams=")
Expand All @@ -5619,6 +5623,8 @@ _oc_cluster_up()
local_nonpersistent_flags+=("--logging")
flags+=("--metrics")
local_nonpersistent_flags+=("--metrics")
flags+=("--no-proxy=")
local_nonpersistent_flags+=("--no-proxy=")
flags+=("--public-hostname=")
local_nonpersistent_flags+=("--public-hostname=")
flags+=("--routing-suffix=")
Expand Down
6 changes: 6 additions & 0 deletions contrib/completions/bash/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -10409,6 +10409,10 @@ _openshift_cli_cluster_up()
local_nonpersistent_flags+=("--host-data-dir=")
flags+=("--host-volumes-dir=")
local_nonpersistent_flags+=("--host-volumes-dir=")
flags+=("--http-proxy=")
local_nonpersistent_flags+=("--http-proxy=")
flags+=("--https-proxy=")
local_nonpersistent_flags+=("--https-proxy=")
flags+=("--image=")
local_nonpersistent_flags+=("--image=")
flags+=("--image-streams=")
Expand All @@ -10417,6 +10421,8 @@ _openshift_cli_cluster_up()
local_nonpersistent_flags+=("--logging")
flags+=("--metrics")
local_nonpersistent_flags+=("--metrics")
flags+=("--no-proxy=")
local_nonpersistent_flags+=("--no-proxy=")
flags+=("--public-hostname=")
local_nonpersistent_flags+=("--public-hostname=")
flags+=("--routing-suffix=")
Expand Down
6 changes: 6 additions & 0 deletions contrib/completions/zsh/oc
Original file line number Diff line number Diff line change
Expand Up @@ -5759,6 +5759,10 @@ _oc_cluster_up()
local_nonpersistent_flags+=("--host-data-dir=")
flags+=("--host-volumes-dir=")
local_nonpersistent_flags+=("--host-volumes-dir=")
flags+=("--http-proxy=")
local_nonpersistent_flags+=("--http-proxy=")
flags+=("--https-proxy=")
local_nonpersistent_flags+=("--https-proxy=")
flags+=("--image=")
local_nonpersistent_flags+=("--image=")
flags+=("--image-streams=")
Expand All @@ -5767,6 +5771,8 @@ _oc_cluster_up()
local_nonpersistent_flags+=("--logging")
flags+=("--metrics")
local_nonpersistent_flags+=("--metrics")
flags+=("--no-proxy=")
local_nonpersistent_flags+=("--no-proxy=")
flags+=("--public-hostname=")
local_nonpersistent_flags+=("--public-hostname=")
flags+=("--routing-suffix=")
Expand Down
6 changes: 6 additions & 0 deletions contrib/completions/zsh/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -10557,6 +10557,10 @@ _openshift_cli_cluster_up()
local_nonpersistent_flags+=("--host-data-dir=")
flags+=("--host-volumes-dir=")
local_nonpersistent_flags+=("--host-volumes-dir=")
flags+=("--http-proxy=")
local_nonpersistent_flags+=("--http-proxy=")
flags+=("--https-proxy=")
local_nonpersistent_flags+=("--https-proxy=")
flags+=("--image=")
local_nonpersistent_flags+=("--image=")
flags+=("--image-streams=")
Expand All @@ -10565,6 +10569,8 @@ _openshift_cli_cluster_up()
local_nonpersistent_flags+=("--logging")
flags+=("--metrics")
local_nonpersistent_flags+=("--metrics")
flags+=("--no-proxy=")
local_nonpersistent_flags+=("--no-proxy=")
flags+=("--public-hostname=")
local_nonpersistent_flags+=("--public-hostname=")
flags+=("--routing-suffix=")
Expand Down
12 changes: 12 additions & 0 deletions docs/man/man1/oc-cluster-up.1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ A public hostname can also be specified for the server with the \-\-public\-host
\fB\-\-host\-volumes\-dir\fP="/var/lib/origin/openshift.local.volumes"
Directory on Docker host for OpenShift volumes

.PP
\fB\-\-http\-proxy\fP=""
HTTP proxy to use for master and builds

.PP
\fB\-\-https\-proxy\fP=""
HTTPS proxy to use for master and builds

.PP
\fB\-\-image\fP="openshift/origin"
Specify the images to use for OpenShift
Expand All @@ -73,6 +81,10 @@ A public hostname can also be specified for the server with the \-\-public\-host
\fB\-\-metrics\fP=false
If true, install metrics (experimental)

.PP
\fB\-\-no\-proxy\fP=[]
List of hosts or subnets for which a proxy should not be used

.PP
\fB\-\-public\-hostname\fP=""
Public hostname for OpenShift cluster
Expand Down
12 changes: 12 additions & 0 deletions docs/man/man1/openshift-cli-cluster-up.1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ A public hostname can also be specified for the server with the \-\-public\-host
\fB\-\-host\-volumes\-dir\fP="/var/lib/origin/openshift.local.volumes"
Directory on Docker host for OpenShift volumes

.PP
\fB\-\-http\-proxy\fP=""
HTTP proxy to use for master and builds

.PP
\fB\-\-https\-proxy\fP=""
HTTPS proxy to use for master and builds

.PP
\fB\-\-image\fP="openshift/origin"
Specify the images to use for OpenShift
Expand All @@ -73,6 +81,10 @@ A public hostname can also be specified for the server with the \-\-public\-host
\fB\-\-metrics\fP=false
If true, install metrics (experimental)

.PP
\fB\-\-no\-proxy\fP=[]
List of hosts or subnets for which a proxy should not be used

.PP
\fB\-\-public\-hostname\fP=""
Public hostname for OpenShift cluster
Expand Down
68 changes: 61 additions & 7 deletions pkg/bootstrap/docker/openshift/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import (

docker "github.com/fsouza/go-dockerclient"
"github.com/golang/glog"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/util/homedir"

"github.com/openshift/origin/pkg/bootstrap/docker/dockerhelper"
"github.com/openshift/origin/pkg/bootstrap/docker/errors"
dockerexec "github.com/openshift/origin/pkg/bootstrap/docker/exec"
"github.com/openshift/origin/pkg/bootstrap/docker/host"
"github.com/openshift/origin/pkg/bootstrap/docker/run"
defaultsapi "github.com/openshift/origin/pkg/build/admission/defaults/api"
cliconfig "github.com/openshift/origin/pkg/cmd/cli/config"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
_ "github.com/openshift/origin/pkg/cmd/server/api/install"
Expand Down Expand Up @@ -83,6 +85,9 @@ type StartOptions struct {
MetricsHost string
LoggingHost string
PortForwarding bool
HTTPProxy string
HTTPSProxy string
NoProxy []string
}

// NewHelper creates a new OpenShift helper
Expand Down Expand Up @@ -222,6 +227,18 @@ func (h *Helper) Start(opt *StartOptions, out io.Writer) (string, error) {

binds := openShiftContainerBinds
env := []string{}
if len(opt.HTTPProxy) > 0 {
env = append(env, fmt.Sprintf("HTTP_PROXY=%s", opt.HTTPProxy))
env = append(env, fmt.Sprintf("http_proxy=%s", opt.HTTPProxy))
}
if len(opt.HTTPSProxy) > 0 {
env = append(env, fmt.Sprintf("HTTPS_PROXY=%s", opt.HTTPSProxy))
env = append(env, fmt.Sprintf("http_proxy=%s", opt.HTTPSProxy))
}
if len(opt.NoProxy) > 0 {
env = append(env, fmt.Sprintf("NO_PROXY=%s", strings.Join(opt.NoProxy, ",")))
env = append(env, fmt.Sprintf("no_proxy=%s", strings.Join(opt.NoProxy, ",")))
}
if opt.UseSharedVolume {
binds = append(binds, fmt.Sprintf("%[1]s:%[1]s:shared", opt.HostVolumesDir))
env = append(env, "OPENSHIFT_CONTAINERIZED=false")
Expand Down Expand Up @@ -304,7 +321,7 @@ func (h *Helper) Start(opt *StartOptions, out io.Writer) (string, error) {
if err != nil {
return "", errors.NewError("could not copy OpenShift configuration").WithCause(err)
}
err = h.updateConfig(configDir, opt.RouterIP, opt.MetricsHost, opt.LoggingHost)
err = h.updateConfig(configDir, opt)
if err != nil {
cleanupConfig()
return "", errors.NewError("could not update OpenShift configuration").WithCause(err)
Expand Down Expand Up @@ -489,7 +506,7 @@ func GetConfigFromContainer(client *docker.Client) (*configapi.MasterConfig, err
return config, nil
}

func (h *Helper) updateConfig(configDir, routerIP, metricsHost, loggingHost string) error {
func (h *Helper) updateConfig(configDir string, opt *StartOptions) error {
cfg, configPath, err := h.GetConfigFromLocalDir(configDir)
if err != nil {
return err
Expand All @@ -498,15 +515,52 @@ func (h *Helper) updateConfig(configDir, routerIP, metricsHost, loggingHost stri
if len(h.routingSuffix) > 0 {
cfg.RoutingConfig.Subdomain = h.routingSuffix
} else {
cfg.RoutingConfig.Subdomain = fmt.Sprintf("%s.xip.io", routerIP)
cfg.RoutingConfig.Subdomain = fmt.Sprintf("%s.xip.io", opt.RouterIP)
}

if len(metricsHost) > 0 && cfg.AssetConfig != nil {
cfg.AssetConfig.MetricsPublicURL = fmt.Sprintf("https://%s/hawkular/metrics", metricsHost)
if len(opt.MetricsHost) > 0 && cfg.AssetConfig != nil {
cfg.AssetConfig.MetricsPublicURL = fmt.Sprintf("https://%s/hawkular/metrics", opt.MetricsHost)
}

if len(loggingHost) > 0 && cfg.AssetConfig != nil {
cfg.AssetConfig.LoggingPublicURL = fmt.Sprintf("https://%s", loggingHost)
if len(opt.LoggingHost) > 0 && cfg.AssetConfig != nil {
cfg.AssetConfig.LoggingPublicURL = fmt.Sprintf("https://%s", opt.LoggingHost)
}

if len(opt.HTTPProxy) > 0 || len(opt.HTTPSProxy) > 0 || len(opt.NoProxy) > 0 {
if cfg.AdmissionConfig.PluginConfig == nil {
cfg.AdmissionConfig.PluginConfig = map[string]configapi.AdmissionPluginConfig{}
}

var buildDefaults *defaultsapi.BuildDefaultsConfig
buildDefaultsConfig, ok := cfg.AdmissionConfig.PluginConfig[defaultsapi.BuildDefaultsPlugin]
if !ok {
buildDefaultsConfig = configapi.AdmissionPluginConfig{}
}
if buildDefaultsConfig.Configuration != nil {
buildDefaults = buildDefaultsConfig.Configuration.(*defaultsapi.BuildDefaultsConfig)
}
if buildDefaults == nil {
buildDefaults = &defaultsapi.BuildDefaultsConfig{}
buildDefaultsConfig.Configuration = buildDefaults
}
buildDefaults.GitHTTPProxy = opt.HTTPProxy
buildDefaults.GitHTTPSProxy = opt.HTTPSProxy
buildDefaults.GitNoProxy = strings.Join(opt.NoProxy, ",")
varsToSet := map[string]string{
"HTTP_PROXY": opt.HTTPProxy,
"http_proxy": opt.HTTPProxy,
"HTTPS_PROXY": opt.HTTPSProxy,
"https_proxy": opt.HTTPSProxy,
"NO_PROXY": strings.Join(opt.NoProxy, ","),
"no_proxy": strings.Join(opt.NoProxy, ","),
}
for k, v := range varsToSet {
buildDefaults.Env = append(buildDefaults.Env, kapi.EnvVar{
Name: k,
Value: v,
})
}
cfg.AdmissionConfig.PluginConfig[defaultsapi.BuildDefaultsPlugin] = buildDefaultsConfig
}

cfgBytes, err := configapilatest.WriteYAML(cfg)
Expand Down
10 changes: 10 additions & 0 deletions pkg/bootstrap/docker/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func NewCmdUp(name, fullName string, f *osclientcmd.Factory, out, errout io.Writ
cmd.Flags().StringArrayVarP(&config.Environment, "env", "e", config.Environment, "Specify a key-value pair for an environment variable to set on OpenShift container")
cmd.Flags().BoolVar(&config.ShouldInstallMetrics, "metrics", false, "If true, install metrics (experimental)")
cmd.Flags().BoolVar(&config.ShouldInstallLogging, "logging", false, "If true, install logging (experimental)")
cmd.Flags().StringVar(&config.HTTPProxy, "http-proxy", "", "HTTP proxy to use for master and builds")
cmd.Flags().StringVar(&config.HTTPSProxy, "https-proxy", "", "HTTPS proxy to use for master and builds")
cmd.Flags().StringArrayVar(&config.NoProxy, "no-proxy", config.NoProxy, "List of hosts or subnets for which a proxy should not be used")
return cmd
}

Expand Down Expand Up @@ -190,6 +193,10 @@ type ClientStartConfig struct {
RoutingSuffix string
DNSPort int

HTTPProxy string
HTTPSProxy string
NoProxy []string

LocalConfigDir string
HostVolumesDir string
HostConfigDir string
Expand Down Expand Up @@ -672,6 +679,9 @@ func (c *ClientStartConfig) StartOpenShift(out io.Writer) error {
LogLevel: c.ServerLogLevel,
DNSPort: c.DNSPort,
PortForwarding: c.PortForwarding,
HTTPProxy: c.HTTPProxy,
HTTPSProxy: c.HTTPSProxy,
NoProxy: c.NoProxy,
}
if c.ShouldInstallMetrics {
opt.MetricsHost = openshift.MetricsHost(c.RoutingSuffix, c.ServerIP)
Expand Down

0 comments on commit 0e3dcb9

Please sign in to comment.