From e69dc5e9a8f1a40ec06f10cfb18a306d75390dd3 Mon Sep 17 00:00:00 2001 From: Kornchanok Jiravesayakul Date: Fri, 17 Apr 2020 17:11:00 +0700 Subject: [PATCH] :bento: [patch] Add dynamic env vars for staging ctrl (#25) --- cmd/samsahai/main.go | 6 ------ config/chart/samsahai/values.yaml | 8 +++++++- internal/const.go | 3 --- internal/samsahai.go | 12 +++--------- internal/samsahai/k8sobject/object.go | 20 +++----------------- 5 files changed, 13 insertions(+), 36 deletions(-) diff --git a/cmd/samsahai/main.go b/cmd/samsahai/main.go index 2e104439..280cba91 100644 --- a/cmd/samsahai/main.go +++ b/cmd/samsahai/main.go @@ -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), @@ -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.") diff --git a/config/chart/samsahai/values.yaml b/config/chart/samsahai/values.yaml index 838105c8..5ca085f9 100644 --- a/config/chart/samsahai/values.yaml +++ b/config/chart/samsahai/values.yaml @@ -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 }}' @@ -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 diff --git a/internal/const.go b/internal/const.go index c289c79e..bfd7d7da 100644 --- a/internal/const.go +++ b/internal/const.go @@ -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" diff --git a/internal/samsahai.go b/internal/samsahai.go index eb7279a1..5fa790fb 100644 --- a/internal/samsahai.go +++ b/internal/samsahai.go @@ -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"` @@ -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:"-"` } diff --git a/internal/samsahai/k8sobject/object.go b/internal/samsahai/k8sobject/object.go index 5b110802..cf324328 100644 --- a/internal/samsahai/k8sobject/object.go +++ b/internal/samsahai/k8sobject/object.go @@ -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, }) }