Skip to content

Commit

Permalink
fix ignore patch template (#21)
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Paskal <paskal.maksim@gmail.com>
  • Loading branch information
maksim-paskal committed Jan 2, 2024
1 parent 4271844 commit 99dfb2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/patch/custompatch/custompatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ func (p *Patch) Create(_ context.Context, containerInfo *types.ContainerInfo) ([

for _, selectedRule := range containerInfo.SelectedRules {
for _, customPatch := range selectedRule.CustomPatches {
if p.ignorePatch(customPatch, containerInfo) {
continue
}

newPatch := customPatch

var err error
Expand All @@ -46,6 +42,10 @@ func (p *Patch) Create(_ context.Context, containerInfo *types.ContainerInfo) ([
return nil, errors.Wrap(err, "error parsing template Path")
}

if p.ignorePatch(newPatch, containerInfo) {
continue
}

patch = append(patch, newPatch)
}
}
Expand All @@ -70,11 +70,11 @@ func (p *Patch) ignorePatch(patch types.PatchOperation, containerInfo *types.Con
if pod.Spec.NodeSelector == nil || len(pod.Spec.NodeSelector) == 0 {
return true
}
case containerInfo.PodContainer.ContainerPath() + "/readinessprobe":
case strings.ToLower(containerInfo.PodContainer.ContainerPath() + "/readinessProbe"):
if containerInfo.PodContainer.Container.ReadinessProbe == nil {
return true
}
case containerInfo.PodContainer.ContainerPath() + "/livenessprobe":
case strings.ToLower(containerInfo.PodContainer.ContainerPath() + "/livenessProbe"):
if containerInfo.PodContainer.Container.LivenessProbe == nil {
return true
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/patch/custompatch/custompatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ func TestCustompatch(t *testing.T) { //nolint:funlen
Path: "/spec/containers/1/livenessProbe",
},
},
{
Ignore: true,
Container: &corev1.Container{
Name: "test",
},
CustomPatches: types.PatchOperation{
Op: "remove",
Path: "{{ .PodContainer.ContainerPath }}/readinessProbe",
},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 99dfb2c

Please sign in to comment.