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

Commit

Permalink
Support volume patch path for different resource kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Jan 6, 2020
1 parent 186b1f3 commit 9b26ec4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion policies/pod/empty_dir_size_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (p PolicyEmptyDirSizeLimit) Validate(ctx context.Context, config policies.C
if volume.EmptyDir.SizeLimit == nil || volume.EmptyDir.SizeLimit.IsZero() {
patches = append(patches, policies.PatchOperation{
Op: "replace",
Path: fmt.Sprintf("/spec/volumes/%d/emptyDir/sizeLimit", i),
Path: fmt.Sprintf(volumePatchPath(podResource.ResourceKind)+"/%d/emptyDir/sizeLimit", i),
Value: cfg.DefaultSizeLimit.String(),
})
continue
Expand All @@ -66,3 +66,16 @@ func (p PolicyEmptyDirSizeLimit) Validate(ctx context.Context, config policies.C
}
return resourceViolations, patches
}

const templateVolumePath = "/spec/template/spec/volumes"

func volumePatchPath(podKind string) string {
nonTemplateKinds := map[string]string{
"Pod": "/spec/volumes",
"CronJob": "/spec/jobTemplate/spec/template/spec/volumes",
}
if pathPath, ok := nonTemplateKinds[podKind]; ok{
return pathPath
}
return templateVolumePath
}

0 comments on commit 9b26ec4

Please sign in to comment.