Skip to content

Commit

Permalink
🍱 [patch] Add dynamic env vars for staging ctrl (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pohfy123 authored Apr 17, 2020
1 parent 15f71c3 commit e69dc5e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 36 deletions.
6 changes: 0 additions & 6 deletions cmd/samsahai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ func startCtrlCmd() *cobra.Command {
httpServerPort),
SamsahaiExternalURL: viper.GetString(s2h.VKS2HExternalURL),
SamsahaiImage: viper.GetString(s2h.VKS2HImage),
SamsahaiHTTPProxy: viper.GetString(s2h.VKS2HHTTPProxy),
SamsahaiHTTPSProxy: viper.GetString(s2h.VKS2HHTTPSProxy),
SamsahaiNoProxy: viper.GetString(s2h.VKS2HNoProxy),
ClusterDomain: viper.GetString(s2h.VKClusterDomain),
ActivePromotion: s2h.ActivePromotionConfig{
Concurrences: viper.GetInt(s2h.VKActivePromotionConcurrences),
Expand Down Expand Up @@ -236,9 +233,6 @@ func startCtrlCmd() *cobra.Command {
cmd.Flags().String(s2h.VKS2HServiceScheme, "http", "Scheme to use for connecting to Samsahai.")
cmd.Flags().String(s2h.VKS2HServiceName, "samsahai", "Service name for connecting to Samsahai.")
cmd.Flags().String(s2h.VKS2HExternalURL, "http://localhost:8080", "External url for Samsahai.")
cmd.Flags().String(s2h.VKS2HHTTPProxy, "", "http proxy for Samsahai.")
cmd.Flags().String(s2h.VKS2HHTTPSProxy, "", "https proxy for Samsahai.")
cmd.Flags().String(s2h.VKS2HNoProxy, "", "no proxy for Samsahai.")
cmd.Flags().String(s2h.VKTeamcityURL, "", "Teamcity Base URL.")
cmd.Flags().String(s2h.VKTeamcityUsername, "", "Teamcity Username.")
cmd.Flags().String(s2h.VKTeamcityPassword, "", "Teamcity Password.")
Expand Down
8 changes: 7 additions & 1 deletion config/chart/samsahai/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extraEnvs: {}
configs:
S2H_CONFIG_PATH: "samsahai.yaml"
S2H_SERVICE_NAME: '{{ include "samsahai.fullname" . }}'
NO_PROXY: '.{{ .Release.Namespace }}'

fileConfigs:
s2hImage: '{{ .Values.image.repository }}:{{ .Values.image.tag }}'
Expand Down Expand Up @@ -56,6 +55,13 @@ fileConfigs:
# if you do not set this flag, the default value is true
promoteOnTeamCreation: true

# environment variables for staging controller
stagingEnvs:
NO_PROXY: '.{{ .Release.Namespace }}'

# how many days of queue histories will be kept?
QUEUE_MAX_HISTORY_DAYS: "7"

# the value in this field should be base64 encoder
credentials: null
# # this is the token for GRPC communication between samsahai and staging controller
Expand Down
3 changes: 0 additions & 3 deletions internal/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const (
VKS2HServiceName = "s2h-service-name"
VKS2HServiceScheme = "s2h-service-scheme"
VKS2HImage = "s2h-image"
VKS2HHTTPProxy = "http-proxy"
VKS2HHTTPSProxy = "https-proxy"
VKS2HNoProxy = "no-proxy"
VKS2HExternalURL = "s2h-external-url"
VKTeamcityURL = "teamcity-url"
VKTeamcityUsername = "teamcity-username"
Expand Down
12 changes: 3 additions & 9 deletions internal/samsahai.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ type SamsahaiConfig struct {
// SamsahaiExternalURL defines a Samsahai external url
SamsahaiExternalURL string `json:"s2hExternalURL" yaml:"s2hExternalURL"`

// SamsahaiHTTPProxy defines a Samsahai http proxy
SamsahaiHTTPProxy string `json:"s2hHTTPProxy" yaml:"s2hHTTPProxy"`

// SamsahaiHTTPSProxy defines a Samsahai https proxy
SamsahaiHTTPSProxy string `json:"s2hHTTPSProxy" yaml:"s2hHTTPSProxy"`

// SamsahaiNoProxy defines a Samsahai no proxy
SamsahaiNoProxy string `json:"s2hNoProxy" yaml:"s2hNoProxy"`

// TeamcityURL defines a Teamcity url
TeamcityURL string `json:"teamcityURL" yaml:"teamcityURL"`

Expand All @@ -69,6 +60,9 @@ type SamsahaiConfig struct {
s2hv1beta1.CommandAndArgs
} `json:"postNamespaceCreation,omitempty" yaml:"postNamespaceCreation,omitempty"`

// StagingEnvs defines environment variables of staging controller
StagingEnvs map[string]string `json:"stagingEnvs,omitempty" yaml:"stagingEnvs,omitempty"`

SamsahaiURL string `json:"-" yaml:"-"`
SamsahaiCredential SamsahaiCredential `json:"-" yaml:"-"`
}
Expand Down
20 changes: 3 additions & 17 deletions internal/samsahai/k8sobject/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,10 @@ func GetDeployment(scheme *runtime.Scheme, teamComp *s2hv1beta1.Team, namespaceN
},
}

if configs.SamsahaiHTTPProxy != "" {
for key, value := range configs.StagingEnvs {
envVars = append(envVars, corev1.EnvVar{
Name: "HTTP_PROXY",
Value: configs.SamsahaiHTTPProxy,
})
}

if configs.SamsahaiHTTPSProxy != "" {
envVars = append(envVars, corev1.EnvVar{
Name: "HTTPS_PROXY",
Value: configs.SamsahaiHTTPSProxy,
})
}

if configs.SamsahaiNoProxy != "" {
envVars = append(envVars, corev1.EnvVar{
Name: "NO_PROXY",
Value: configs.SamsahaiNoProxy,
Name: key,
Value: value,
})
}

Expand Down

0 comments on commit e69dc5e

Please sign in to comment.