Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kaniko proxy #2283

Merged
merged 19 commits into from
Jul 10, 2019
12 changes: 12 additions & 0 deletions docs/content/en/schemas/v1beta13.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,16 @@
},
"ClusterDetails": {
"properties": {
"HTTPS_PROXY": {
"type": "string",
"description": "for kaniko pod.",
"x-intellij-html-description": "for kaniko pod."
},
"HTTP_PROXY": {
"type": "string",
"description": "for kaniko pod.",
"x-intellij-html-description": "for kaniko pod."
},
"dockerConfig": {
"$ref": "#/definitions/DockerConfig",
"description": "describes how to mount the local Docker configuration into a pod.",
Expand Down Expand Up @@ -512,6 +522,8 @@
}
},
"preferredOrder": [
"HTTP_PROXY",
"HTTPS_PROXY",
"pullSecret",
"pullSecretName",
"namespace",
Expand Down
4 changes: 2 additions & 2 deletions hack/generate-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fi

set -e

docker run $CONTAINER_NAME cat /proto/skaffold.pb.go > proto/skaffold.pb.go
docker run $CONTAINER_NAME cat /proto/skaffold.pb.gw.go > proto/skaffold.pb.gw.go
docker run $CONTAINER_NAME cat pkg/skaffold/server/proto/skaffold.pb.go > proto/skaffold.pb.go
docker run $CONTAINER_NAME cat pkg/skaffold/server/proto/skaffold.pb.gw.go > proto/skaffold.pb.gw.go

printf "\nFinished generating proto files, please commit the results.\n"
9 changes: 5 additions & 4 deletions pkg/skaffold/build/cluster/sources/localdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import (
)

func TestPod(t *testing.T) {
env := []v1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
}}
reqs := &latest.ResourceRequirements{
Requests: &latest.ResourceRequirement{
CPU: "0.1",
Expand Down Expand Up @@ -78,10 +82,7 @@ func TestPod(t *testing.T) {
Image: "image",
Args: []string{"arg1", "arg2"},
ImagePullPolicy: v1.PullIfNotPresent,
Env: []v1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
}},
Env: env,
VolumeMounts: []v1.VolumeMount{
{
Name: constants.DefaultKanikoSecretName,
Expand Down
32 changes: 27 additions & 5 deletions pkg/skaffold/build/cluster/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func Retrieve(clusterDetails *latest.ClusterDetails, artifact *latest.KanikoArti
}

func podTemplate(clusterDetails *latest.ClusterDetails, artifact *latest.KanikoArtifact, args []string) *v1.Pod {
env := []v1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
}}

env = setProxy(clusterDetails, env)

pod := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "kaniko-",
Expand All @@ -65,10 +72,7 @@ func podTemplate(clusterDetails *latest.ClusterDetails, artifact *latest.KanikoA
Image: artifact.Image,
Args: args,
ImagePullPolicy: v1.PullIfNotPresent,
Env: []v1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
}},
Env: env,
VolumeMounts: []v1.VolumeMount{
{
Name: constants.DefaultKanikoSecretName,
Expand Down Expand Up @@ -135,6 +139,25 @@ func podTemplate(clusterDetails *latest.ClusterDetails, artifact *latest.KanikoA
return pod
}

func setProxy(clusterDetails *latest.ClusterDetails, env []v1.EnvVar) []v1.EnvVar {
if clusterDetails.HTTPProxy != "" {
proxy := v1.EnvVar{
Name: "HTTP_PROXY",
Value: clusterDetails.HTTPProxy,
}
env = append(env, proxy)
}

if clusterDetails.HTTPSProxy != "" {
proxy := v1.EnvVar{
Name: "HTTPS_PROXY",
Value: clusterDetails.HTTPSProxy,
}
env = append(env, proxy)
}
return env
}

func resourceRequirements(rr *latest.ResourceRequirements) v1.ResourceRequirements {
req := v1.ResourceRequirements{}

Expand Down Expand Up @@ -162,5 +185,4 @@ func resourceRequirements(rr *latest.ResourceRequirements) v1.ResourceRequiremen
}

return req

}
39 changes: 39 additions & 0 deletions pkg/skaffold/build/cluster/sources/sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,45 @@ func TestPodTemplate(t *testing.T) {
}
}

func TestSetProxy(t *testing.T) {
tests := []struct {
description string
clusterDetails *latest.ClusterDetails
env []v1.EnvVar
expectedArgs []v1.EnvVar
}{
{
description: "no http and https proxy",
clusterDetails: &latest.ClusterDetails{},
env: []v1.EnvVar{},
expectedArgs: []v1.EnvVar{},
}, {
description: "set http proxy",

clusterDetails: &latest.ClusterDetails{HTTPProxy: "proxy.com"},
env: []v1.EnvVar{},
expectedArgs: []v1.EnvVar{{Name: "HTTP_PROXY", Value: "proxy.com"}},
}, {
description: "set https proxy",
clusterDetails: &latest.ClusterDetails{HTTPSProxy: "proxy.com"},
env: []v1.EnvVar{},
expectedArgs: []v1.EnvVar{{Name: "HTTPS_PROXY", Value: "proxy.com"}},
}, {
description: "set http and https proxy",
clusterDetails: &latest.ClusterDetails{HTTPProxy: "proxy.com", HTTPSProxy: "proxy.com"},
env: []v1.EnvVar{},
expectedArgs: []v1.EnvVar{{Name: "HTTP_PROXY", Value: "proxy.com"}, {Name: "HTTPS_PROXY", Value: "proxy.com"}},
},
}

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
actual := setProxy(test.clusterDetails, test.env)
testutil.CheckErrorAndDeepEqual(t, false, nil, test.expectedArgs, actual)
})
}
}

func createResourceRequirements(cpuLimit resource.Quantity, memoryLimit resource.Quantity, cpuRequest resource.Quantity, memoryRequest resource.Quantity) v1.ResourceRequirements {
return v1.ResourceRequirements{
Limits: v1.ResourceList{
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ type KanikoCache struct {

// ClusterDetails *beta* describes how to do an on-cluster build.
type ClusterDetails struct {
// HTTPProxy for kaniko pod.
HTTPProxy string `yaml:"HTTP_PROXY,omitempty"`

// HTTPSProxy for kaniko pod.
HTTPSProxy string `yaml:"HTTPS_PROXY,omitempty"`

// PullSecret is the path to the Google Cloud service account secret key file.
PullSecret string `yaml:"pullSecret,omitempty"`

Expand Down
19 changes: 19 additions & 0 deletions proto/skaffold.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.