Skip to content

Commit

Permalink
remove rediness and liveness probe from pods (#19)
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 ec411ac commit e9244f5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
10 changes: 9 additions & 1 deletion pkg/patch/custompatch/custompatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
56 changes: 53 additions & 3 deletions pkg/patch/custompatch/custompatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestCustompatch(t *testing.T) { //nolint:funlen
Ignore bool
CustomPatches types.PatchOperation
Expected types.PatchOperation
Container *corev1.Container
}

tests := []testCase{
Expand All @@ -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,
},
},
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit e9244f5

Please sign in to comment.