Skip to content

Commit

Permalink
Add a test to Kaniko builder
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot committed Jun 28, 2019
1 parent 54eacb6 commit 1dadfbe
Showing 1 changed file with 118 additions and 69 deletions.
187 changes: 118 additions & 69 deletions pkg/skaffold/build/cluster/sources/sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,29 @@ package sources
import (
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/testutil"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/testutil"
)

func TestPodTemplate(t *testing.T) {
tests := []struct {
description string
initial *latest.ClusterDetails
artifact *latest.KanikoArtifact
image string
args []string
expected *v1.Pod
}{
{
description: "basic pod",
initial: &latest.ClusterDetails{},
artifact: &latest.KanikoArtifact{
Image: "kaniko-latest",
},
expected: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "kaniko-",
Expand All @@ -48,75 +51,74 @@ func TestPodTemplate(t *testing.T) {
RestartPolicy: "Never",
Containers: []v1.Container{
{
Name: "kaniko",
Env: []v1.EnvVar{
{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
},
},
VolumeMounts: []v1.VolumeMount{
{
Name: "kaniko-secret", MountPath: "/secret",
},
},
Name: "kaniko",
Image: "kaniko-latest",
Env: []v1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
}},
VolumeMounts: []v1.VolumeMount{{
Name: "kaniko-secret",
MountPath: "/secret",
}},
ImagePullPolicy: v1.PullPolicy("IfNotPresent"),
},
},
Volumes: []v1.Volume{
{
Name: "kaniko-secret",
VolumeSource: v1.VolumeSource{
Secret: &v1.SecretVolumeSource{
SecretName: "",
},
Volumes: []v1.Volume{{
Name: "kaniko-secret",
VolumeSource: v1.VolumeSource{
Secret: &v1.SecretVolumeSource{
SecretName: "",
},
},
}},
},
},
},
},
{
description: "with docker config",
initial: &latest.ClusterDetails{
PullSecretName: "pull-secret",
DockerConfig: &latest.DockerConfig{
SecretName: "docker-cfg",
Path: "/kaniko/.docker",
},
},
artifact: &latest.KanikoArtifact{
Image: "kaniko-latest",
},
expected: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "kaniko-",
Labels: map[string]string{"skaffold-kaniko": "skaffold-kaniko"},
},
Spec: v1.PodSpec{
RestartPolicy: "Never",
Containers: []v1.Container{
{
Name: "kaniko",
Env: []v1.EnvVar{
{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
},
Containers: []v1.Container{{
Name: "kaniko",
Image: "kaniko-latest",
Env: []v1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
}},
VolumeMounts: []v1.VolumeMount{
{
Name: "kaniko-secret",
MountPath: "/secret",
},
VolumeMounts: []v1.VolumeMount{
{
Name: "kaniko-secret", MountPath: "/secret",
},
{
Name: "docker-cfg", MountPath: "/kaniko/.docker",
},
{
Name: "docker-cfg",
MountPath: "/kaniko/.docker",
},
ImagePullPolicy: v1.PullPolicy("IfNotPresent"),
},
},
ImagePullPolicy: v1.PullPolicy("IfNotPresent"),
}},
Volumes: []v1.Volume{
{
Name: "kaniko-secret",
VolumeSource: v1.VolumeSource{
Secret: &v1.SecretVolumeSource{
SecretName: "",
SecretName: "pull-secret",
},
},
},
Expand Down Expand Up @@ -146,45 +148,92 @@ func TestPodTemplate(t *testing.T) {
},
},
},
artifact: &latest.KanikoArtifact{
Image: "kaniko-latest",
},
expected: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "kaniko-",
Labels: map[string]string{"skaffold-kaniko": "skaffold-kaniko"},
},
Spec: v1.PodSpec{
RestartPolicy: "Never",
Containers: []v1.Container{
{
Name: "kaniko",
Env: []v1.EnvVar{
{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
},
Containers: []v1.Container{{
Name: "kaniko",
Image: "kaniko-latest",
Env: []v1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
}},
VolumeMounts: []v1.VolumeMount{{
Name: "kaniko-secret",
MountPath: "/secret",
}},
ImagePullPolicy: v1.PullPolicy("IfNotPresent"),
Resources: createResourceRequirements(
resource.MustParse("1.0"),
resource.MustParse("2000"),
resource.MustParse("0.5"),
resource.MustParse("1000")),
}},
Volumes: []v1.Volume{{
Name: "kaniko-secret",
VolumeSource: v1.VolumeSource{
Secret: &v1.SecretVolumeSource{
SecretName: "",
},
VolumeMounts: []v1.VolumeMount{
{
Name: "kaniko-secret", MountPath: "/secret",
},
},
}},
},
},
},
{
description: "with cache",
initial: &latest.ClusterDetails{},
artifact: &latest.KanikoArtifact{
Image: "kaniko-latest",
Cache: &latest.KanikoCache{
HostPath: "/cache-path",
},
},
expected: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "kaniko-",
Labels: map[string]string{"skaffold-kaniko": "skaffold-kaniko"},
},
Spec: v1.PodSpec{
RestartPolicy: "Never",
Containers: []v1.Container{{
Name: "kaniko",
Image: "kaniko-latest",
Env: []v1.EnvVar{{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/secret/kaniko-secret",
}},
VolumeMounts: []v1.VolumeMount{{
Name: "kaniko-secret",
MountPath: "/secret",
}, {
Name: "kaniko-cache",
MountPath: "/cache",
}},
ImagePullPolicy: v1.PullPolicy("IfNotPresent"),
}},
Volumes: []v1.Volume{{
Name: "kaniko-secret",
VolumeSource: v1.VolumeSource{
Secret: &v1.SecretVolumeSource{
SecretName: "",
},
ImagePullPolicy: v1.PullPolicy("IfNotPresent"),
Resources: createResourceRequirements(
resource.MustParse("1.0"),
resource.MustParse("2000"),
resource.MustParse("0.5"),
resource.MustParse("1000")),
},
},
Volumes: []v1.Volume{
{
Name: "kaniko-secret",
VolumeSource: v1.VolumeSource{
Secret: &v1.SecretVolumeSource{
SecretName: "",
},
}, {
Name: "kaniko-cache",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/cache-path",
},
},
},
}},
},
},
},
Expand All @@ -196,7 +245,7 @@ func TestPodTemplate(t *testing.T) {

for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
actual := podTemplate(test.initial, &latest.KanikoArtifact{Image: test.image, Cache: &latest.KanikoCache{}}, test.args)
actual := podTemplate(test.initial, test.artifact, test.args)

t.CheckDeepEqual(test.expected, actual, opt)
})
Expand Down

0 comments on commit 1dadfbe

Please sign in to comment.