Skip to content

Commit

Permalink
Use proxy info from environment in kotsadm API
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Jul 29, 2020
1 parent f819e85 commit 7f9fdd8
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 107 deletions.
217 changes: 110 additions & 107 deletions pkg/kotsadm/api_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,115 @@ func apiDeployment(deployOptions types.DeployOptions) *appsv1.Deployment {
}
}

env := []corev1.EnvVar{
{
Name: "SHARED_PASSWORD_BCRYPT",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-password",
},
Key: "passwordBcrypt",
},
},
},
{
Name: "AUTO_CREATE_CLUSTER_TOKEN",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: types.ClusterTokenSecret,
},
Key: types.ClusterTokenSecret,
},
},
},
{
Name: "SHIP_API_ENDPOINT",
Value: fmt.Sprintf("http://kotsadm.%s.svc.cluster.local:3000", deployOptions.Namespace),
},
{
Name: "SHIP_API_ADVERTISE_ENDPOINT",
Value: "http://localhost:8800",
},
{
Name: "S3_ENDPOINT",
Value: "http://kotsadm-minio:9000",
},
{
Name: "S3_BUCKET_NAME",
Value: "kotsadm",
},
{
Name: "API_ENCRYPTION_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-encryption",
},
Key: "encryptionKey",
},
},
},
{
Name: "S3_ACCESS_KEY_ID",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-minio",
},
Key: "accesskey",
},
},
},
{
Name: "S3_SECRET_ACCESS_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-minio",
},
Key: "secretkey",
},
},
},
{
Name: "S3_BUCKET_ENDPOINT",
Value: "true",
},
{
Name: "SESSION_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-session",
},
Key: "key",
},
},
},
{
Name: "POSTGRES_URI",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-postgres",
},
Key: "uri",
},
},
},
{
Name: "POD_NAMESPACE",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.namespace",
},
},
},
}
env = append(env, getProxyEnv()...)

deployment := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Expand Down Expand Up @@ -276,113 +385,7 @@ func apiDeployment(deployOptions types.DeployOptions) *appsv1.Deployment {
},
},
},
Env: []corev1.EnvVar{
{
Name: "SHARED_PASSWORD_BCRYPT",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-password",
},
Key: "passwordBcrypt",
},
},
},
{
Name: "AUTO_CREATE_CLUSTER_TOKEN",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: types.ClusterTokenSecret,
},
Key: types.ClusterTokenSecret,
},
},
},
{
Name: "SHIP_API_ENDPOINT",
Value: fmt.Sprintf("http://kotsadm.%s.svc.cluster.local:3000", deployOptions.Namespace),
},
{
Name: "SHIP_API_ADVERTISE_ENDPOINT",
Value: "http://localhost:8800",
},
{
Name: "S3_ENDPOINT",
Value: "http://kotsadm-minio:9000",
},
{
Name: "S3_BUCKET_NAME",
Value: "kotsadm",
},
{
Name: "API_ENCRYPTION_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-encryption",
},
Key: "encryptionKey",
},
},
},
{
Name: "S3_ACCESS_KEY_ID",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-minio",
},
Key: "accesskey",
},
},
},
{
Name: "S3_SECRET_ACCESS_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-minio",
},
Key: "secretkey",
},
},
},
{
Name: "S3_BUCKET_ENDPOINT",
Value: "true",
},
{
Name: "SESSION_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-session",
},
Key: "key",
},
},
},
{
Name: "POSTGRES_URI",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-postgres",
},
Key: "uri",
},
},
},
{
Name: "POD_NAMESPACE",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.namespace",
},
},
},
},
Env: env,
},
},
},
Expand Down
1 change: 1 addition & 0 deletions pkg/kotsadm/kotsadm_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ func kotsadmDeployment(deployOptions types.DeployOptions) *appsv1.Deployment {
Value: "http://localhost:8800",
},
}
env = append(env, getProxyEnv()...)

if deployOptions.KotsadmOptions.OverrideRegistry != "" {
env = append(env, corev1.EnvVar{
Expand Down
39 changes: 39 additions & 0 deletions pkg/kotsadm/proxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package kotsadm

import (
"os"

corev1 "k8s.io/api/core/v1"
)

func getProxyEnv() []corev1.EnvVar {
keys := []string{
"HTTP_PROXY",
"http_proxy",
"HTTPS_PROXY",
"https_proxy",
"NO_PROXY",
"no_proxy",
}

result := []corev1.EnvVar{}
for _, key := range keys {
val := os.Getenv(key)
if val == "" {
continue
}

if key == "NO_PROXY" || key == "no_proxy" {
if val != "" {
val = val + ","
}
val = val + "kotsadm-postgres,kotsadm-minio,kotsadm-api-node"
}

result = append(result, corev1.EnvVar{
Name: key,
Value: val,
})
}
return result
}

0 comments on commit 7f9fdd8

Please sign in to comment.