Skip to content

Commit

Permalink
Set different readiness/startup probe endpoint for automatic chia-hea…
Browse files Browse the repository at this point in the history
…lthcheck probes (#221)
  • Loading branch information
Starttoaster authored Dec 6, 2024
1 parent 705ec87 commit 1d8deb8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 24 deletions.
6 changes: 3 additions & 3 deletions internal/controller/chianode/assemblers.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,15 @@ func assembleChiaContainer(ctx context.Context, node k8schianetv1.ChiaNode, full
input.LivenessProbe = node.Spec.ChiaConfig.LivenessProbe
} else if node.Spec.ChiaHealthcheckConfig.Enabled {
input.LivenessProbe = kube.AssembleChiaHealthcheckProbe(kube.AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaNodeKind,
Path: "/full_node",
})
}

if node.Spec.ChiaConfig.ReadinessProbe != nil {
input.ReadinessProbe = node.Spec.ChiaConfig.ReadinessProbe
} else if node.Spec.ChiaHealthcheckConfig.Enabled {
input.ReadinessProbe = kube.AssembleChiaHealthcheckProbe(kube.AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaNodeKind,
Path: "/full_node/readiness",
})
}

Expand All @@ -416,7 +416,7 @@ func assembleChiaContainer(ctx context.Context, node k8schianetv1.ChiaNode, full
failThresh := int32(30)
periodSec := int32(10)
input.StartupProbe = kube.AssembleChiaHealthcheckProbe(kube.AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaNodeKind,
Path: "/full_node/readiness",
FailureThreshold: &failThresh,
PeriodSeconds: &periodSec,
})
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/chiaseeder/assemblers.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,15 @@ func assembleChiaContainer(seeder k8schianetv1.ChiaSeeder, fullNodePort int32, n
input.LivenessProbe = seeder.Spec.ChiaConfig.LivenessProbe
} else if seeder.Spec.ChiaHealthcheckConfig.Enabled && seeder.Spec.ChiaHealthcheckConfig.DNSHostname != nil {
input.ReadinessProbe = kube.AssembleChiaHealthcheckProbe(kube.AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaSeederKind,
Path: "/seeder",
})
}

if seeder.Spec.ChiaConfig.ReadinessProbe != nil {
input.ReadinessProbe = seeder.Spec.ChiaConfig.ReadinessProbe
} else if seeder.Spec.ChiaHealthcheckConfig.Enabled && seeder.Spec.ChiaHealthcheckConfig.DNSHostname != nil {
input.ReadinessProbe = kube.AssembleChiaHealthcheckProbe(kube.AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaSeederKind,
Path: "/seeder/readiness",
})
}

Expand All @@ -435,7 +435,7 @@ func assembleChiaContainer(seeder k8schianetv1.ChiaSeeder, fullNodePort int32, n
failThresh := int32(30)
periodSec := int32(10)
input.StartupProbe = kube.AssembleChiaHealthcheckProbe(kube.AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaSeederKind,
Path: "/seeder/readiness",
FailureThreshold: &failThresh,
PeriodSeconds: &periodSec,
})
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/chiatimelord/assemblers.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,15 @@ func assembleChiaContainer(ctx context.Context, tl k8schianetv1.ChiaTimelord, ne
input.LivenessProbe = tl.Spec.ChiaConfig.LivenessProbe
} else if tl.Spec.ChiaHealthcheckConfig.Enabled {
input.LivenessProbe = kube.AssembleChiaHealthcheckProbe(kube.AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaTimelordKind,
Path: "/timelord",
})
}

if tl.Spec.ChiaConfig.ReadinessProbe != nil {
input.ReadinessProbe = tl.Spec.ChiaConfig.ReadinessProbe
} else if tl.Spec.ChiaHealthcheckConfig.Enabled {
input.ReadinessProbe = kube.AssembleChiaHealthcheckProbe(kube.AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaTimelordKind,
Path: "/timelord/readiness",
})
}

Expand All @@ -421,7 +421,7 @@ func assembleChiaContainer(ctx context.Context, tl k8schianetv1.ChiaTimelord, ne
failThresh := int32(30)
periodSec := int32(10)
input.StartupProbe = kube.AssembleChiaHealthcheckProbe(kube.AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaTimelordKind,
Path: "/timelord/readiness",
FailureThreshold: &failThresh,
PeriodSeconds: &periodSec,
})
Expand Down
14 changes: 2 additions & 12 deletions internal/controller/common/kube/assemblers.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func AssembleChiaHealthcheckContainer(input AssembleChiaHealthcheckContainerInpu

// AssembleChiaHealthcheckProbeInputs contains configuration inputs to the AssembleChiaHealthcheckProbe function
type AssembleChiaHealthcheckProbeInputs struct {
Kind consts.ChiaKind
Path string
FailureThreshold *int32
PeriodSeconds *int32
}
Expand All @@ -256,7 +256,7 @@ func AssembleChiaHealthcheckProbe(input AssembleChiaHealthcheckProbeInputs) *cor
probe := corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/",
Path: input.Path,
Port: intstr.FromInt32(consts.ChiaHealthcheckPort),
},
},
Expand All @@ -270,15 +270,5 @@ func AssembleChiaHealthcheckProbe(input AssembleChiaHealthcheckProbeInputs) *cor
probe.PeriodSeconds = *input.PeriodSeconds
}

switch input.Kind {
case consts.ChiaNodeKind:
probe.ProbeHandler.HTTPGet.Path = "/full_node"
case consts.ChiaSeederKind:
probe.ProbeHandler.HTTPGet.Path = "/seeder"
case consts.ChiaTimelordKind:
probe.ProbeHandler.HTTPGet.Path = "/timelord"
default:
return nil
}
return &probe
}
6 changes: 3 additions & 3 deletions internal/controller/common/kube/assemblers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func TestAssembleChiaHealthcheckProbe_Minimal(t *testing.T) {
},
}
actual := AssembleChiaHealthcheckProbe(AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaSeederKind,
Path: "/seeder",
})
require.Equal(t, expected, *actual)
}
Expand All @@ -508,15 +508,15 @@ func TestAssembleChiaHealthcheckProbe_Full(t *testing.T) {
expected := corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/seeder",
Path: "/seeder/readiness",
Port: intstr.FromInt32(consts.ChiaHealthcheckPort),
},
},
FailureThreshold: failThresh,
PeriodSeconds: periodSec,
}
actual := AssembleChiaHealthcheckProbe(AssembleChiaHealthcheckProbeInputs{
Kind: consts.ChiaSeederKind,
Path: "/seeder/readiness",
FailureThreshold: &failThresh,
PeriodSeconds: &periodSec,
})
Expand Down

0 comments on commit 1d8deb8

Please sign in to comment.