Skip to content

Commit

Permalink
Merge pull request #2260 from cedrickring/init-container-resources
Browse files Browse the repository at this point in the history
Add resources to Kaniko init container
  • Loading branch information
priyawadhwa authored Jun 13, 2019
2 parents ff1ca99 + 3ed51c7 commit 05d3b2e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pkg/skaffold/build/cluster/sources/localdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ import (
"os/exec"
"path/filepath"

"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/sources"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
)

const (
Expand Down Expand Up @@ -83,6 +82,7 @@ func (g *LocalDir) Pod(args []string) *v1.Pod {
Image: g.artifact.BuildContext.LocalDir.InitImage,
Command: []string{"sh", "-c", "while [ ! -f /tmp/complete ]; do sleep 1; done"},
VolumeMounts: []v1.VolumeMount{vm},
Resources: resourceRequirements(g.clusterDetails.Resources),
}

p := podTemplate(g.clusterDetails, g.artifact, args)
Expand Down
21 changes: 18 additions & 3 deletions pkg/skaffold/build/cluster/sources/localdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,27 @@ limitations under the License.
package sources

import (
"reflect"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/testutil"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestPod(t *testing.T) {
reqs := &latest.ResourceRequirements{
Requests: &latest.ResourceRequirement{
CPU: "0.1",
Memory: "1Gi",
},
Limits: &latest.ResourceRequirement{
CPU: "0.5",
Memory: "5Gi",
},
}

localDir := &LocalDir{
artifact: &latest.KanikoArtifact{
Image: "image",
Expand All @@ -39,6 +50,7 @@ func TestPod(t *testing.T) {
clusterDetails: &latest.ClusterDetails{
Namespace: "ns",
PullSecretName: "secret",
Resources: reqs,
},
}

Expand All @@ -59,6 +71,7 @@ func TestPod(t *testing.T) {
Name: constants.DefaultKanikoEmptyDirName,
MountPath: constants.DefaultKanikoEmptyDirMountPath,
}},
Resources: resourceRequirements(reqs),
}},
Containers: []v1.Container{{
Name: constants.DefaultKanikoContainerName,
Expand All @@ -79,7 +92,7 @@ func TestPod(t *testing.T) {
MountPath: constants.DefaultKanikoEmptyDirMountPath,
},
},
Resources: v1.ResourceRequirements{},
Resources: resourceRequirements(reqs),
}},
RestartPolicy: v1.RestartPolicyNever,
Volumes: []v1.Volume{
Expand All @@ -101,5 +114,7 @@ func TestPod(t *testing.T) {
},
}

testutil.CheckDeepEqual(t, expectedPod, pod)
if !reflect.DeepEqual(expectedPod, pod) {
t.Errorf("Expected manifest differs from actual manifest. Got: \n%v, \nExpected: \n%v", expectedPod, pod)
}
}

0 comments on commit 05d3b2e

Please sign in to comment.