Skip to content

Commit f2c28ef

Browse files
feat(slugbuilder-cache): allow turning caching off completely
When the slugbuilder doesn't receive a CACHE_PATH, it'll skip caching. Adding DEIS_DISABLE_CACHE config variable will disable the cache and will not define CACHE_PATH on the slugbuilder pod, preventing it from reading/writing cache.
1 parent 408529f commit f2c28ef

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

pkg/gitreceive/k8s_util.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ func slugbuilderPod(
108108
pod.Spec.Containers[0].Name = slugBuilderName
109109
pod.Spec.Containers[0].Image = image
110110

111+
if _, ok := env["DEIS_DISABLE_CACHE"]; !ok {
112+
addEnvToPod(pod, cachePath, cacheKey)
113+
}
114+
111115
addEnvToPod(pod, tarPath, tarKey)
112116
addEnvToPod(pod, putPath, putKey)
113-
addEnvToPod(pod, cachePath, cacheKey)
114117
addEnvToPod(pod, sourceVersion, gitShortHash)
115118
addEnvToPod(pod, builderStorage, storageType)
116119

pkg/gitreceive/k8s_util_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ func TestBuildPod(t *testing.T) {
5656
env := make(map[string]interface{})
5757
env["KEY"] = "VALUE"
5858

59+
cacheDisabledEnv := make(map[string]interface{})
60+
cacheDisabledEnv["DEIS_DISABLE_CACHE"] = "1"
61+
5962
var pod *api.Pod
6063

6164
slugBuilds := []slugBuildCase{
6265
{true, "test", "default", emptyEnv, "tar", "put-url", "cache-url", "deadbeef", "", "", api.PullAlways, ""},
6366
{true, "test", "default", env, "tar", "put-url", "cache-url", "deadbeef", "", "", api.PullAlways, ""},
67+
{true, "test", "default", cacheDisabledEnv, "tar", "put-url", "cache-url", "deadbeef", "", "", api.PullAlways, ""},
6468
{true, "test", "default", emptyEnv, "tar", "put-url", "cache-url", "deadbeef", "buildpack", "", api.PullAlways, ""},
6569
{true, "test", "default", env, "tar", "put-url", "cache-url", "deadbeef", "buildpack", "", api.PullAlways, ""},
6670
{true, "test", "default", env, "tar", "put-url", "cache-url", "deadbeef", "buildpack", "customimage", api.PullAlways, ""},
@@ -95,7 +99,14 @@ func TestBuildPod(t *testing.T) {
9599
checkForEnv(t, pod, "SOURCE_VERSION", build.gitShortHash)
96100
checkForEnv(t, pod, "TAR_PATH", build.tarKey)
97101
checkForEnv(t, pod, "PUT_PATH", build.putKey)
98-
checkForEnv(t, pod, "CACHE_PATH", build.cacheKey)
102+
103+
if _, ok := build.env["DEIS_DISABLE_CACHE"]; !ok {
104+
checkForEnv(t, pod, "CACHE_PATH", build.cacheKey)
105+
} else {
106+
if cachePath, err := envValueFromKey(pod, "CACHE_PATH"); err == nil {
107+
t.Errorf("expected CACHE_PATH not to be defined but it was defined with %v", cachePath)
108+
}
109+
}
99110

100111
if build.buildPack != "" {
101112
checkForEnv(t, pod, "BUILDPACK_URL", build.buildPack)

0 commit comments

Comments
 (0)