Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

feat: Allow changing emptyDir sizeLimit #311

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The following table lists the configurable parameters of the job-executor-servic
| `jobConfig.labels` | Additional labels that are added to all kubernetes jobs | `{}` |
| `jobConfig.networkPolicy.enabled` | Enable a network policy for jobs such that they can not access blocked networks defined in blockCIDRS | `false` |
| `jobConfig.networkPolicy.blockCIDRs` | A list of networks that should not be accessible from jobs | `false` |
| `jobConfig.emptyDirSizeLimit` | Size Limit of emptyDirs created for jobs | `"20Mi"` |
| `remoteControlPlane.autoDetect.enabled` | Enables auto detection of a Keptn installation | `false` |
| `remoteControlPlane.autoDetect.namespace` | Namespace which should be used by the auto-detection | `""` |
| `remoteControlPlane.api.protocol` | Used protocol (http, https | `"https"` |
Expand Down
1 change: 1 addition & 0 deletions chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: job-service-config
data:
job_namespace: "{{ .Release.Namespace }}"
job_emptydir_sizelimit: "{{ .Values.jobConfig.emptyDirSizeLimit | default "20Mi" }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means that it won't be possible not to specify a size and leave the management to the k8s host. I would suggest to leave the default in the values.yaml and remove it from here to allow users to specify "" as value already when installing.
Current solution would force users to manually modify the configmap to have no limit for emptyDir volumes...

init_container_image: "{{ .Values.jobexecutorserviceinitcontainer.image.repository }}:{{ .Values.jobexecutorserviceinitcontainer.image.tag | default .Chart.AppVersion }}"
default_resource_limits_cpu: "1"
default_resource_limits_memory: "512Mi"
Expand Down
5 changes: 5 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ spec:
configMapKeyRef:
name: job-service-config
key: job_namespace
- name: JOB_EMPTYDIR_SIZELIMIT
valueFrom:
configMapKeyRef:
name: job-service-config
key: job_emptydir_sizelimit
- name: INIT_CONTAINER_IMAGE
valueFrom:
configMapKeyRef:
Expand Down
1 change: 1 addition & 0 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobConfig:
# "172.16.0.0/12",
# "192.168.0.0/16"
]
emptyDirSizeLimit: "20Mi" # Size Limit for emptyDirs for each job (/keptn - containing resources)

imagePullSecrets: [ ] # Secrets to use for container registry credentials

Expand Down
3 changes: 3 additions & 0 deletions cmd/job-executor-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type envConfig struct {
ConfigurationServiceURL string `envconfig:"CONFIGURATION_SERVICE" default:""`
// The k8s namespace the job will run in
JobNamespace string `envconfig:"JOB_NAMESPACE" required:"true"`
// Kubernetes Empty Dir Size Limit for every job (default: "20Mi")
JobEmtpyDirVolumeSizeLimit string `envconfig:"JOB_EMPTYDIR_SIZELIMIT" default:"20Mi"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another default value layer (so we have 3: values.yaml, default helm function in the configmap template and finally here in EnvConfig), it would get confusing as which value would be used.
For example: what is the value of the emptyDir size if I explicitly specify --set jobConfig.emptyDirSizeLimit="" during helm install ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
JobEmtpyDirVolumeSizeLimit string `envconfig:"JOB_EMPTYDIR_SIZELIMIT" default:"20Mi"`
JobEmptyDirVolumeSizeLimit string `envconfig:"JOB_EMPTYDIR_SIZELIMIT" default:"20Mi"`

// The token of the keptn API
KeptnAPIToken string `envconfig:"KEPTN_API_TOKEN"`
// The init container image to use
Expand Down Expand Up @@ -130,6 +132,7 @@ func processKeptnCloudEvent(ctx context.Context, event cloudevents.Event, allowL
DefaultPodSecurityContext: DefaultPodSecurityContext,
AllowPrivilegedJobs: env.AllowPrivilegedJobs,
JobLabels: JobLabels,
JobEmtpyDirVolumeSizeLimit: env.JobEmtpyDirVolumeSizeLimit,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
JobEmtpyDirVolumeSizeLimit: env.JobEmtpyDirVolumeSizeLimit,
JobEmptyDirVolumeSizeLimit: env.JobEmtpyDirVolumeSizeLimit,

TaskDeadlineSeconds: TaskDeadlineSecondsPtr,
JesDeploymentName: env.FullDeploymentName,
},
Expand Down
5 changes: 5 additions & 0 deletions docs/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ args:
- /keptn/locust/basic.py
```

#### Increase Volume Size for files

By default, `/keptn` reserves `"20Mi"` (20 Mebibyte) as part of an `emptyDir`. This value can be modified at your own
risk by setting the Helm Value `jobConfig.emptyDirSizeLimit`, e.g., `--set jobConfig.emptyDirSizeLimit=50Mi`.

### Silent mode

Actions can be run in silent mode, meaning no `.started/.finished` events will be sent by the job-executor-service. This
Expand Down
5 changes: 4 additions & 1 deletion pkg/k8sutils/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type JobSettings struct {
AllowPrivilegedJobs bool
TaskDeadlineSeconds *int64
JobLabels map[string]string
JobEmtpyDirVolumeSizeLimit string
JesDeploymentName string
}

Expand Down Expand Up @@ -116,8 +117,10 @@ func (k8s *K8sImpl) CreateK8sJob(
// TODO configure from outside:
jobVolumeMountPath := "/keptn"

// TODO configure from outside:
quantity := resource.MustParse("20Mi")
if jobSettings.JobEmtpyDirVolumeSizeLimit != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with all the default values we have I am not sure that we can ever have an empty JobEmptyDirVolumeSizeLimit

Suggested change
if jobSettings.JobEmtpyDirVolumeSizeLimit != "" {
if jobSettings.JobEmptyDirVolumeSizeLimit != "" {

quantity = resource.MustParse(jobSettings.JobEmtpyDirVolumeSizeLimit)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
quantity = resource.MustParse(jobSettings.JobEmtpyDirVolumeSizeLimit)
quantity = resource.MustParse(jobSettings.JobEmptyDirVolumeSizeLimit)

}

jobResourceRequirements := jobSettings.DefaultResourceRequirements
if task.Resources != nil {
Expand Down
62 changes: 62 additions & 0 deletions pkg/k8sutils/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,68 @@ func TestSetEmptyNamespace(t *testing.T) {
assert.Equal(t, job.Namespace, namespace, "Could not find container in namespace %s", namespace)
}

func TestSetEmptyDirSizeLimit(t *testing.T) {
jobName := "test-job-3"

eventData := keptnv2.EventData{
Project: "sockshop",
Stage: "dev",
Service: "carts",
}

customEmptyDirSizeLimit := "52Mi"

var eventAsInterface interface{}
json.Unmarshal([]byte(testTriggeredEvent), &eventAsInterface)

k8sClientSet := k8sfake.NewSimpleClientset()

k8s := K8sImpl{
clientset: k8sClientSet,
}

err := k8s.CreateK8sJob(
jobName,
JobDetails{
Action: &config.Action{
Name: jobName,
},
Task: &config.Task{
Name: jobName,
Image: "alpine",
Cmd: []string{"ls"},
},
ActionIndex: 0,
TaskIndex: 0,
JobConfigHash: "",
},
&eventData, JobSettings{
JobNamespace: testNamespace,
DefaultResourceRequirements: &corev1.ResourceRequirements{
Limits: make(corev1.ResourceList),
Requests: make(corev1.ResourceList),
},
DefaultPodSecurityContext: new(corev1.PodSecurityContext),
DefaultSecurityContext: new(corev1.SecurityContext),
JobEmtpyDirVolumeSizeLimit: customEmptyDirSizeLimit,
}, eventAsInterface, testNamespace,
)

require.NoError(t, err)

job, err := k8sClientSet.BatchV1().Jobs(testNamespace).Get(context.TODO(), jobName, metav1.GetOptions{})
require.NoError(t, err)

var volume *corev1.Volume

require.NotNil(t, job.Spec.Template.Spec.Volumes)
volume = &job.Spec.Template.Spec.Volumes[0]

require.NotNil(t, volume.EmptyDir)

assert.Equal(t, volume.EmptyDir.SizeLimit.String(), customEmptyDirSizeLimit)
}

func TestImagePullPolicy(t *testing.T) {

tests := []struct {
Expand Down