-
Notifications
You must be signed in to change notification settings - Fork 24
Set probes port and scheme based on .spec.manageTLS #735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
bc833d5
0dff493
ed7e090
6fd775c
9fccebe
72b5eca
70bfde7
652a0c6
d739fcc
705ae0b
dde3d2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,15 +206,15 @@ type RuntimeComponentServiceAccount struct { | |
| type RuntimeComponentProbes struct { | ||
| // Periodic probe of container liveness. Container will be restarted if the probe fails. | ||
| // +operator-sdk:csv:customresourcedefinitions:order=3,type=spec,displayName="Liveness Probe" | ||
| Liveness *corev1.Probe `json:"liveness,omitempty"` | ||
| Liveness *common.BaseComponentProbe `json:"liveness,omitempty"` | ||
|
|
||
| // Periodic probe of container service readiness. Container will be removed from service endpoints if the probe fails. | ||
| // +operator-sdk:csv:customresourcedefinitions:order=2,type=spec,displayName="Readiness Probe" | ||
| Readiness *corev1.Probe `json:"readiness,omitempty"` | ||
| Readiness *common.BaseComponentProbe `json:"readiness,omitempty"` | ||
|
|
||
| // Probe to determine successful initialization. If specified, other probes are not executed until this completes successfully. | ||
| // +operator-sdk:csv:customresourcedefinitions:order=1,type=spec,displayName="Startup Probe" | ||
| Startup *corev1.Probe `json:"startup,omitempty"` | ||
| Startup *common.BaseComponentProbe `json:"startup,omitempty"` | ||
| } | ||
|
|
||
| // Configure pods to run on particular Nodes. | ||
|
|
@@ -611,18 +611,18 @@ func (cr *RuntimeComponent) GetProbes() common.BaseComponentProbes { | |
| } | ||
|
|
||
| // GetLivenessProbe returns liveness probe | ||
| func (p *RuntimeComponentProbes) GetLivenessProbe() *corev1.Probe { | ||
| return p.Liveness | ||
| func (p *RuntimeComponentProbes) GetLivenessProbe(ba common.BaseComponent) *corev1.Probe { | ||
| return common.ConvertBaseComponentProbeToCoreProbe(p.Liveness, p.GetDefaultLivenessProbe(ba)) | ||
| } | ||
|
|
||
| // GetReadinessProbe returns readiness probe | ||
| func (p *RuntimeComponentProbes) GetReadinessProbe() *corev1.Probe { | ||
| return p.Readiness | ||
| func (p *RuntimeComponentProbes) GetReadinessProbe(ba common.BaseComponent) *corev1.Probe { | ||
| return common.ConvertBaseComponentProbeToCoreProbe(p.Readiness, p.GetDefaultReadinessProbe(ba)) | ||
| } | ||
|
|
||
| // GetStartupProbe returns startup probe | ||
| func (p *RuntimeComponentProbes) GetStartupProbe() *corev1.Probe { | ||
| return p.Startup | ||
| func (p *RuntimeComponentProbes) GetStartupProbe(ba common.BaseComponent) *corev1.Probe { | ||
| return common.ConvertBaseComponentProbeToCoreProbe(p.Startup, p.GetDefaultStartupProbe(ba)) | ||
| } | ||
|
|
||
| // GetDefaultLivenessProbe returns default values for liveness probe | ||
|
|
@@ -765,6 +765,17 @@ func (cr *RuntimeComponent) GetManageTLS() *bool { | |
| return cr.Spec.ManageTLS | ||
| } | ||
|
|
||
| func (cr *RuntimeComponent) GetManagedPort() int { | ||
| return int(cr.GetService().GetPort()) | ||
| } | ||
|
|
||
| func (cr *RuntimeComponent) GetManagedScheme() corev1.URIScheme { | ||
| if cr.GetManageTLS() != nil && *cr.GetManageTLS() { | ||
|
||
| return corev1.URISchemeHTTPS | ||
| } | ||
| return corev1.URISchemeHTTP | ||
| } | ||
|
|
||
| // GetDeployment returns deployment settings | ||
| func (cr *RuntimeComponent) GetDeployment() common.BaseComponentDeployment { | ||
| if cr.Spec.Deployment == nil { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| v1 "k8s.io/api/core/v1" | ||
| networkingv1 "k8s.io/api/networking/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/util/intstr" | ||
| ) | ||
|
|
||
| // StatusConditionType ... | ||
|
|
@@ -195,11 +196,95 @@ type BaseComponentStatefulSet interface { | |
| GetAnnotations() map[string]string | ||
| } | ||
|
|
||
| // This struct is taken from the Probe specification in https://github.com/kubernetes/api/blob/v0.33.4/core/v1/types.go | ||
| // +kubebuilder:object:generate=true | ||
| type BaseComponentProbe struct { | ||
|
||
| // The action taken to determine the health of a container | ||
| BaseComponentProbeHandler `json:",inline"` | ||
| // 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"` | ||
| // Number of seconds after which the probe times out. | ||
| // Defaults to 1 second. Minimum value is 1. | ||
| // More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes | ||
| // +optional | ||
| TimeoutSeconds int32 `json:"timeoutSeconds,omitempty"` | ||
| // How often (in seconds) to perform the probe. | ||
| // Default to 10 seconds. Minimum value is 1. | ||
| // +optional | ||
| PeriodSeconds int32 `json:"periodSeconds,omitempty"` | ||
| // Minimum consecutive successes for the probe to be considered successful after having failed. | ||
| // Defaults to 1. Must be 1 for liveness and startup. Minimum value is 1. | ||
| // +optional | ||
| SuccessThreshold int32 `json:"successThreshold,omitempty"` | ||
| // Minimum consecutive failures for the probe to be considered failed after having succeeded. | ||
| // Defaults to 3. Minimum value is 1. | ||
| // +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. | ||
| // Minimum value is 1. spec.terminationGracePeriodSeconds is used if unset. | ||
| // +optional | ||
| TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` | ||
| } | ||
|
|
||
| // This struct is taken from the ProbeHandler specification in https://github.com/kubernetes/api/blob/v0.33.4/core/v1/types.go | ||
| // +kubebuilder:object:generate=true | ||
| type BaseComponentProbeHandler struct { | ||
| // Exec specifies the action to take. | ||
| // +optional | ||
| Exec *corev1.ExecAction `json:"exec,omitempty"` | ||
| // HTTPGet specifies the http request to perform. | ||
| // +optional | ||
| HTTPGet *OptionalHTTPGetAction `json:"httpGet,omitempty"` | ||
| // TCPSocket specifies an action involving a TCP port. | ||
| // +optional | ||
| TCPSocket *corev1.TCPSocketAction `json:"tcpSocket,omitempty"` | ||
|
|
||
| // GRPC specifies an action involving a GRPC port. | ||
| // This is a beta field and requires enabling GRPCContainerProbe feature gate. | ||
| // +featureGate=GRPCContainerProbe | ||
| // +optional | ||
| GRPC *corev1.GRPCAction `json:"grpc,omitempty"` | ||
| } | ||
|
|
||
| // This struct is based upon the HTTPGetAction specification in https://github.com/kubernetes/api/blob/v0.33.4/core/v1/types.go | ||
| // +kubebuilder:object:generate=true | ||
| type OptionalHTTPGetAction struct { | ||
| // Path to access on the HTTP server. | ||
| // +optional | ||
| Path *string `json:"path,omitempty"` | ||
| // Name or number of the port to access on the container. | ||
| // Number must be in the range 1 to 65535. | ||
| // Name must be an IANA_SVC_NAME. | ||
| // +optional | ||
| Port *intstr.IntOrString `json:"port,omitempty"` | ||
| // 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"` | ||
| // Scheme to use for connecting to the host. | ||
| // Defaults to HTTP. | ||
| // +optional | ||
| Scheme *corev1.URIScheme `json:"scheme,omitempty"` | ||
| // Custom headers to set in the request. HTTP allows repeated headers. | ||
| // +optional | ||
| HTTPHeaders *[]corev1.HTTPHeader `json:"httpHeaders,omitempty"` | ||
| } | ||
|
|
||
| // BaseComponentProbes describes the probes for application container | ||
| type BaseComponentProbes interface { | ||
| GetLivenessProbe() *corev1.Probe | ||
| GetReadinessProbe() *corev1.Probe | ||
| GetStartupProbe() *corev1.Probe | ||
| GetLivenessProbe(ba BaseComponent) *corev1.Probe | ||
| GetReadinessProbe(ba BaseComponent) *corev1.Probe | ||
| GetStartupProbe(ba BaseComponent) *corev1.Probe | ||
|
|
||
| GetDefaultLivenessProbe(ba BaseComponent) *corev1.Probe | ||
| GetDefaultReadinessProbe(ba BaseComponent) *corev1.Probe | ||
|
|
@@ -257,6 +342,8 @@ type BaseComponent interface { | |
| GetTopologySpreadConstraints() BaseComponentTopologySpreadConstraints | ||
| GetSecurityContext() *corev1.SecurityContext | ||
| GetManageTLS() *bool | ||
| GetManagedPort() int | ||
| GetManagedScheme() corev1.URIScheme | ||
| GetDisableServiceLinks() *bool | ||
| GetTolerations() []corev1.Toleration | ||
| GetDNS() BaseComponentDNS | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate that the default value Operator sets (when user hasn't configured Service port) is retrieved here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added nil check on
GetService()and fallback to8080