Skip to content

Commit

Permalink
simplify structures
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Dec 10, 2024
1 parent 4ced5b6 commit 8dc3a7f
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 172 deletions.
14 changes: 7 additions & 7 deletions pkg/apis/deployment/kubedeployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ func TestComponentWithCustomHealthChecks(t *testing.T) {
createProbe := func(handler v1.RadixProbeHandler, seconds int32) *v1.RadixProbe {
return &v1.RadixProbe{
RadixProbeHandler: handler,
InitialDelaySeconds: pointers.Ptr(seconds),
TimeoutSeconds: pointers.Ptr(seconds + 1),
PeriodSeconds: pointers.Ptr(seconds + 2),
SuccessThreshold: pointers.Ptr(seconds + 3),
FailureThreshold: pointers.Ptr(seconds + 4),
InitialDelaySeconds: seconds,
TimeoutSeconds: seconds + 1,
PeriodSeconds: seconds + 2,
SuccessThreshold: seconds + 3,
FailureThreshold: seconds + 4,
// TerminationGracePeriodSeconds: pointers.Ptr(int64(seconds + 5)),
}
}

readynessProbe := createProbe(v1.RadixProbeHandler{HTTPGet: &v1.RadixProbeHTTPGetAction{
Port: pointers.Ptr[int32](5000),
Port: 5000,
}}, 10)

livenessProbe := createProbe(v1.RadixProbeHandler{TCPSocket: &v1.RadixProbeTCPSocketAction{
Port: pointers.Ptr[int32](5000),
Port: 5000,
}}, 20)
startuProbe := createProbe(v1.RadixProbeHandler{Exec: &v1.RadixProbeExecAction{
Command: []string{"echo", "hello"},
Expand Down
14 changes: 7 additions & 7 deletions pkg/apis/deployment/radixcomponent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,18 +1052,18 @@ func Test_GetRadixComponents_CustomHealthChecks(t *testing.T) {
createProbe := func(handler radixv1.RadixProbeHandler, seconds int32) *radixv1.RadixProbe {
return &radixv1.RadixProbe{
RadixProbeHandler: handler,
InitialDelaySeconds: &seconds,
TimeoutSeconds: pointers.Ptr(seconds + 1),
PeriodSeconds: pointers.Ptr(seconds + 2),
SuccessThreshold: pointers.Ptr(seconds + 3),
FailureThreshold: pointers.Ptr(seconds + 4),
InitialDelaySeconds: seconds,
TimeoutSeconds: seconds + 1,
PeriodSeconds: seconds + 2,
SuccessThreshold: seconds + 3,
FailureThreshold: seconds + 4,
// TerminationGracePeriodSeconds: pointers.Ptr(int64(seconds + 5)),
}
}

httpProbe := radixv1.RadixProbeHandler{HTTPGet: &radixv1.RadixProbeHTTPGetAction{Port: pointers.Ptr[int32](5000), Path: pointers.Ptr("/healthz"), Scheme: pointers.Ptr(corev1.URISchemeHTTP)}}
httpProbe := radixv1.RadixProbeHandler{HTTPGet: &radixv1.RadixProbeHTTPGetAction{Port: 5000, Path: "/healthz", Scheme: corev1.URISchemeHTTP}}
execProbe := radixv1.RadixProbeHandler{Exec: &radixv1.RadixProbeExecAction{Command: []string{"/bin/sh", "-c", "/healthz /healthz"}}}
tcpProbe := radixv1.RadixProbeHandler{TCPSocket: &radixv1.RadixProbeTCPSocketAction{Port: pointers.Ptr[int32](8000)}}
tcpProbe := radixv1.RadixProbeHandler{TCPSocket: &radixv1.RadixProbeTCPSocketAction{Port: 8000}}

testCases := []struct {
description string
Expand Down
22 changes: 0 additions & 22 deletions pkg/apis/radix/v1/radixapptypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,28 +815,6 @@ type RadixJobComponentPayload struct {
Path string `json:"path"`
}

type RadixHealthChecks struct {
// Periodic probe of container liveness.
// Container will be restarted if the probe fails.
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
// +optional
LivenessProbe *RadixProbe `json:"livenessProbe,omitempty"`
// Periodic probe of container service readiness.
// Container will be removed from service endpoints if the probe fails.
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
// Defaults to TCP Probe against the first listed port
// +optional
ReadinessProbe *RadixProbe `json:"readinessProbe,omitempty"`
// StartupProbe indicates that the Pod has successfully initialized.
// If specified, no other probes are executed until this completes successfully.
// If this probe fails, the Pod will be restarted, just as if the livenessProbe failed.
// This can be used to provide different probe parameters at the beginning of a Pod's lifecycle,
// when it might take a long time to load data or warm a cache, than during steady-state operation.
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
// +optional
StartupProbe *RadixProbe `json:"startupProbe,omitempty"`
}

// PrivateImageHubEntries defines authentication information for private image registries.
type PrivateImageHubEntries map[string]*RadixPrivateImageHubCredential

Expand Down
92 changes: 46 additions & 46 deletions pkg/apis/radix/v1/radixhealthchecktypes.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
package v1

import (
"github.com/equinor/radix-common/utils/pointers"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

type RadixHealthChecks struct {
// Periodic probe of container liveness.
// Container will be restarted if the probe fails.
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
// +optional
LivenessProbe *RadixProbe `json:"livenessProbe,omitempty"`
// Periodic probe of container service readiness.
// Container will be removed from service endpoints if the probe fails.
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
// Defaults to TCP Probe against the first listed port
// +optional
ReadinessProbe *RadixProbe `json:"readinessProbe,omitempty"`
// StartupProbe indicates that the Pod has successfully initialized.
// If specified, no other probes are executed until this completes successfully.
// If this probe fails, the Pod will be restarted, just as if the livenessProbe failed.
// This can be used to provide different probe parameters at the beginning of a Pod's lifecycle,
// when it might take a long time to load data or warm a cache, than during steady-state operation.
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
// +optional
StartupProbe *RadixProbe `json:"startupProbe,omitempty"`
}

// RadixProbe describes a health check to be performed against a container to determine whether it is
// alive or ready to receive traffic.
type RadixProbe struct {
Expand All @@ -14,42 +35,31 @@ type RadixProbe struct {
// Number of seconds after the container has started before liveness probes are initiated.
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
// +optional
InitialDelaySeconds *int32 `json:"initialDelaySeconds,omitempty"`
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty"`
// Number of seconds after which the probe times out.
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
// +kubebuilder:validation:Minimum=1
// +default=1
// +optional
TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty"`
TimeoutSeconds int32 `json:"timeoutSeconds,omitempty"`
// How often (in seconds) to perform the probe.
// +kubebuilder:validation:Minimum=1
// +default=10
// +optional
PeriodSeconds *int32 `json:"periodSeconds,omitempty"`
PeriodSeconds int32 `json:"periodSeconds,omitempty"`
// Minimum consecutive successes for the probe to be considered successful after having failed.
// Must be 1 for liveness and startup.
// +kubebuilder:validation:Minimum=1
// +default=1
// +optional
SuccessThreshold *int32 `json:"successThreshold,omitempty"`
SuccessThreshold int32 `json:"successThreshold,omitempty"`
// Minimum consecutive failures for the probe to be considered failed after having succeeded.
// +kubebuilder:validation:Minimum=1
// +default=3
// +optional
FailureThreshold *int32 `json:"failureThreshold,omitempty"`

// // Optional duration in seconds the pod needs to terminate gracefully upon probe failure.
// // The grace period is the duration in seconds after the processes running in the pod are sent
// // a termination signal and the time when the processes are forcibly halted with a kill signal.
// // Set this value longer than the expected cleanup time for your process.
// // If this value is nil, the pod's terminationGracePeriodSeconds will be used. Otherwise, this
// // value overrides the value provided by the pod spec.
// // Value must be non-negative integer. The value zero indicates stop immediately via
// // the kill signal (no opportunity to shut down).
// // This is a beta field and requires enabling ProbeTerminationGracePeriod feature gate.
// // +kubebuilder:validation:Minimum=1
// // +default=30
// // +optional
FailureThreshold int32 `json:"failureThreshold,omitempty"`

// Todo: This is a beta property that we might want to take in in the future
// TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
}

Expand All @@ -60,12 +70,11 @@ func (rp *RadixProbe) MapToCoreProbe() *corev1.Probe {

return &corev1.Probe{
ProbeHandler: rp.RadixProbeHandler.MapToCoreProbe(),
InitialDelaySeconds: pointers.Val(rp.InitialDelaySeconds),
TimeoutSeconds: pointers.Val(rp.TimeoutSeconds),
PeriodSeconds: pointers.Val(rp.PeriodSeconds),
SuccessThreshold: pointers.Val(rp.SuccessThreshold),
FailureThreshold: pointers.Val(rp.FailureThreshold),
// TerminationGracePeriodSeconds: rp.TerminationGracePeriodSeconds,
InitialDelaySeconds: rp.InitialDelaySeconds,
TimeoutSeconds: rp.TimeoutSeconds,
PeriodSeconds: rp.PeriodSeconds,
SuccessThreshold: rp.SuccessThreshold,
FailureThreshold: rp.FailureThreshold,
}
}

Expand Down Expand Up @@ -95,20 +104,20 @@ func (p RadixProbeHandler) MapToCoreProbe() corev1.ProbeHandler {
type RadixProbeHTTPGetAction struct {
// Path to access on the HTTP server.
// +optional
Path *string `json:"path,omitempty"`
Path string `json:"path,omitempty"`
// port number to access on the container.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
Port *int32 `json:"port"`
Port int32 `json:"port"`
// Host name to connect to, defaults to the pod IP. You probably want to set
// "Host" in httpHeaders instead.
// +optional
Host *string `json:"host,omitempty"`
Host string `json:"host,omitempty"`
// Scheme to use for connecting to the host.
// Defaults to HTTP.
// +optional
// +kubebuilder:validation:Enum=HTTPS;HTTP
Scheme *corev1.URIScheme `json:"scheme,omitempty"`
Scheme corev1.URIScheme `json:"scheme,omitempty"`
// Custom headers to set in the request. HTTP allows repeated headers.
// +optional
// +listType=atomic
Expand All @@ -120,16 +129,11 @@ func (a *RadixProbeHTTPGetAction) MapToCoreProbe() *corev1.HTTPGetAction {
return nil
}

var port intstr.IntOrString
if a.Port != nil {
port = intstr.FromInt32(*a.Port)
}

return &corev1.HTTPGetAction{
Path: pointers.Val(a.Path),
Port: port,
Host: pointers.Val(a.Host),
Scheme: pointers.Val(a.Scheme),
Path: a.Path,
Port: intstr.FromInt32(a.Port),
Host: a.Host,
Scheme: a.Scheme,
HTTPHeaders: a.HTTPHeaders,
}
}
Expand Down Expand Up @@ -161,24 +165,20 @@ type RadixProbeTCPSocketAction struct {
// port number to access on the container.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
Port *int32 `json:"port"`
Port int32 `json:"port"`
// Optional: Host name to connect to, defaults to the pod IP.
// +optional
Host *string `json:"host,omitempty"`
Host string `json:"host,omitempty"`
}

func (a *RadixProbeTCPSocketAction) MapToCoreProbe() *corev1.TCPSocketAction {
if a == nil {
return nil
}
var port intstr.IntOrString
if a.Port != nil {
port = intstr.FromInt32(*a.Port)
}

return &corev1.TCPSocketAction{
Port: port,
Host: pointers.Val(a.Host),
Port: intstr.FromInt32(a.Port),
Host: a.Host,
}
}

Expand Down
57 changes: 1 addition & 56 deletions pkg/apis/radix/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8dc3a7f

Please sign in to comment.