diff --git a/pkg/patch/custompatch/custompatch.go b/pkg/patch/custompatch/custompatch.go index b6f8f2f..9e43089 100644 --- a/pkg/patch/custompatch/custompatch.go +++ b/pkg/patch/custompatch/custompatch.go @@ -54,7 +54,7 @@ func (p *Patch) Create(_ context.Context, containerInfo *types.ContainerInfo) ([ } // check well known operations and ignore them. -func (p *Patch) ignorePatch(patch types.PatchOperation, containerInfo *types.ContainerInfo) bool { +func (p *Patch) ignorePatch(patch types.PatchOperation, containerInfo *types.ContainerInfo) bool { //nolint:cyclop if patch.Op != "remove" { return false } @@ -70,6 +70,14 @@ 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": + if containerInfo.PodContainer.Container.ReadinessProbe == nil { + return true + } + case containerInfo.PodContainer.ContainerPath() + "/livenessprobe": + if containerInfo.PodContainer.Container.LivenessProbe == nil { + return true + } } return false diff --git a/pkg/patch/custompatch/custompatch_test.go b/pkg/patch/custompatch/custompatch_test.go index c95a1a8..bba827b 100644 --- a/pkg/patch/custompatch/custompatch_test.go +++ b/pkg/patch/custompatch/custompatch_test.go @@ -32,6 +32,7 @@ func TestCustompatch(t *testing.T) { //nolint:funlen Ignore bool CustomPatches types.PatchOperation Expected types.PatchOperation + Container *corev1.Container } tests := []testCase{ @@ -43,7 +44,7 @@ func TestCustompatch(t *testing.T) { //nolint:funlen }, Expected: types.PatchOperation{ Op: "test", - Path: "/spec/containers/123/annotations", + Path: "/spec/containers/1/annotations", Value: nil, }, }, @@ -87,6 +88,54 @@ func TestCustompatch(t *testing.T) { //nolint:funlen Path: "{{ .FFFFAAAKKEEE }}", }, }, + { + Container: &corev1.Container{ + Name: "test", + ReadinessProbe: &corev1.Probe{}, + }, + CustomPatches: types.PatchOperation{ + Op: "remove", + Path: "/spec/containers/1/readinessProbe", + }, + Expected: types.PatchOperation{ + Op: "remove", + Path: "/spec/containers/1/readinessProbe", + }, + }, + { + Ignore: true, + Container: &corev1.Container{ + Name: "test", + }, + CustomPatches: types.PatchOperation{ + Op: "remove", + Path: "/spec/containers/1/readinessProbe", + }, + }, + { + Container: &corev1.Container{ + Name: "test", + LivenessProbe: &corev1.Probe{}, + }, + CustomPatches: types.PatchOperation{ + Op: "remove", + Path: "/spec/containers/1/livenessProbe", + }, + Expected: types.PatchOperation{ + Op: "remove", + Path: "/spec/containers/1/livenessProbe", + }, + }, + { + Ignore: true, + Container: &corev1.Container{ + Name: "test", + }, + CustomPatches: types.PatchOperation{ + Op: "remove", + Path: "/spec/containers/1/livenessProbe", + }, + }, } for _, test := range tests { @@ -98,8 +147,9 @@ func TestCustompatch(t *testing.T) { //nolint:funlen containerInfo := &types.ContainerInfo{ ContainerName: "test", PodContainer: &types.PodContainer{ - Order: 123, - Type: "container", + Order: 1, + Type: "container", + Container: test.Container, Pod: &corev1.Pod{ Spec: corev1.PodSpec{ Affinity: nil,