From a31f9a0a275cf9edcc46f55bfcd87bc39a54bb58 Mon Sep 17 00:00:00 2001 From: kabicin Date: Tue, 25 Jul 2023 16:45:09 -0400 Subject: [PATCH 01/25] Create BaseComponentProbe as wrapper to corev1.Probe --- api/v1/runtimecomponent_types.go | 18 ++--- api/v1/zz_generated.deepcopy.go | 6 +- api/v1beta2/runtimecomponent_types.go | 18 ++--- api/v1beta2/zz_generated.deepcopy.go | 7 +- common/common.go | 25 +++--- common/types.go | 94 ++++++++++++++++++++-- common/zz_generated.deepcopy.go | 103 ++++++++++++++++++++++++ utils/utils.go | 108 +++++++++++++++++++++----- utils/utils_test.go | 21 ++--- 9 files changed, 328 insertions(+), 72 deletions(-) create mode 100644 common/zz_generated.deepcopy.go diff --git a/api/v1/runtimecomponent_types.go b/api/v1/runtimecomponent_types.go index cd05e1f9e..1e34699b4 100644 --- a/api/v1/runtimecomponent_types.go +++ b/api/v1/runtimecomponent_types.go @@ -177,15 +177,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. @@ -537,32 +537,32 @@ func (cr *RuntimeComponent) GetProbes() common.BaseComponentProbes { } // GetLivenessProbe returns liveness probe -func (p *RuntimeComponentProbes) GetLivenessProbe() *corev1.Probe { +func (p *RuntimeComponentProbes) GetLivenessProbe() *common.BaseComponentProbe { return p.Liveness } // GetReadinessProbe returns readiness probe -func (p *RuntimeComponentProbes) GetReadinessProbe() *corev1.Probe { +func (p *RuntimeComponentProbes) GetReadinessProbe() *common.BaseComponentProbe { return p.Readiness } // GetStartupProbe returns startup probe -func (p *RuntimeComponentProbes) GetStartupProbe() *corev1.Probe { +func (p *RuntimeComponentProbes) GetStartupProbe() *common.BaseComponentProbe { return p.Startup } // GetDefaultLivenessProbe returns default values for liveness probe -func (p *RuntimeComponentProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *corev1.Probe { +func (p *RuntimeComponentProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *common.BaseComponentProbe { return common.GetDefaultMicroProfileLivenessProbe(ba) } // GetDefaultReadinessProbe returns default values for readiness probe -func (p *RuntimeComponentProbes) GetDefaultReadinessProbe(ba common.BaseComponent) *corev1.Probe { +func (p *RuntimeComponentProbes) GetDefaultReadinessProbe(ba common.BaseComponent) *common.BaseComponentProbe { return common.GetDefaultMicroProfileReadinessProbe(ba) } // GetDefaultStartupProbe returns default values for startup probe -func (p *RuntimeComponentProbes) GetDefaultStartupProbe(ba common.BaseComponent) *corev1.Probe { +func (p *RuntimeComponentProbes) GetDefaultStartupProbe(ba common.BaseComponent) *common.BaseComponentProbe { return common.GetDefaultMicroProfileStartupProbe(ba) } diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 8c2f73819..52794d704 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -301,17 +301,17 @@ func (in *RuntimeComponentProbes) DeepCopyInto(out *RuntimeComponentProbes) { *out = *in if in.Liveness != nil { in, out := &in.Liveness, &out.Liveness - *out = new(corev1.Probe) + *out = new(common.BaseComponentProbe) (*in).DeepCopyInto(*out) } if in.Readiness != nil { in, out := &in.Readiness, &out.Readiness - *out = new(corev1.Probe) + *out = new(common.BaseComponentProbe) (*in).DeepCopyInto(*out) } if in.Startup != nil { in, out := &in.Startup, &out.Startup - *out = new(corev1.Probe) + *out = new(common.BaseComponentProbe) (*in).DeepCopyInto(*out) } } diff --git a/api/v1beta2/runtimecomponent_types.go b/api/v1beta2/runtimecomponent_types.go index 6be32cb57..3d602f072 100644 --- a/api/v1beta2/runtimecomponent_types.go +++ b/api/v1beta2/runtimecomponent_types.go @@ -136,27 +136,27 @@ type RuntimeComponentSpec 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"` } -func (in *RuntimeComponentProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *corev1.Probe { +func (in *RuntimeComponentProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *common.BaseComponentProbe { return nil } -func (in *RuntimeComponentProbes) GetDefaultReadinessProbe(ba common.BaseComponent) *corev1.Probe { +func (in *RuntimeComponentProbes) GetDefaultReadinessProbe(ba common.BaseComponent) *common.BaseComponentProbe { return nil } -func (in *RuntimeComponentProbes) GetDefaultStartupProbe(ba common.BaseComponent) *corev1.Probe { +func (in *RuntimeComponentProbes) GetDefaultStartupProbe(ba common.BaseComponent) *common.BaseComponentProbe { return nil } @@ -468,17 +468,17 @@ func (cr *RuntimeComponent) GetProbes() common.BaseComponentProbes { } // GetLivenessProbe returns liveness probe -func (p *RuntimeComponentProbes) GetLivenessProbe() *corev1.Probe { +func (p *RuntimeComponentProbes) GetLivenessProbe() *common.BaseComponentProbe { return p.Liveness } // GetReadinessProbe returns readiness probe -func (p *RuntimeComponentProbes) GetReadinessProbe() *corev1.Probe { +func (p *RuntimeComponentProbes) GetReadinessProbe() *common.BaseComponentProbe { return p.Readiness } // GetStartupProbe returns startup probe -func (p *RuntimeComponentProbes) GetStartupProbe() *corev1.Probe { +func (p *RuntimeComponentProbes) GetStartupProbe() *common.BaseComponentProbe { return p.Startup } diff --git a/api/v1beta2/zz_generated.deepcopy.go b/api/v1beta2/zz_generated.deepcopy.go index 092e14d8f..75a000523 100644 --- a/api/v1beta2/zz_generated.deepcopy.go +++ b/api/v1beta2/zz_generated.deepcopy.go @@ -22,6 +22,7 @@ limitations under the License. package v1beta2 import ( + "github.com/application-stacks/runtime-component-operator/common" routev1 "github.com/openshift/api/route/v1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" appsv1 "k8s.io/api/apps/v1" @@ -236,17 +237,17 @@ func (in *RuntimeComponentProbes) DeepCopyInto(out *RuntimeComponentProbes) { *out = *in if in.Liveness != nil { in, out := &in.Liveness, &out.Liveness - *out = new(v1.Probe) + *out = new(common.BaseComponentProbe) (*in).DeepCopyInto(*out) } if in.Readiness != nil { in, out := &in.Readiness, &out.Readiness - *out = new(v1.Probe) + *out = new(common.BaseComponentProbe) (*in).DeepCopyInto(*out) } if in.Startup != nil { in, out := &in.Startup, &out.Startup - *out = new(v1.Probe) + *out = new(common.BaseComponentProbe) (*in).DeepCopyInto(*out) } } diff --git a/common/common.go b/common/common.go index a8f750e37..8ef209e6b 100644 --- a/common/common.go +++ b/common/common.go @@ -1,15 +1,14 @@ package common import ( - corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" ) // GetDefaultMicroProfileStartupProbe returns the default values for MicroProfile Health-based startup probe. -func GetDefaultMicroProfileStartupProbe(ba BaseComponent) *corev1.Probe { - return &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ +func GetDefaultMicroProfileStartupProbe(ba BaseComponent) *BaseComponentProbe { + return &BaseComponentProbe{ + BaseComponentProbeHandler: BaseComponentProbeHandler{ + HTTPGet: &OptionalHTTPGetAction{ Path: "/health/started", Port: intstr.FromInt(int(ba.GetService().GetPort())), Scheme: "HTTPS", @@ -22,10 +21,10 @@ func GetDefaultMicroProfileStartupProbe(ba BaseComponent) *corev1.Probe { } // GetDefaultMicroProfileReadinessProbe returns the default values for MicroProfile Health-based readiness probe. -func GetDefaultMicroProfileReadinessProbe(ba BaseComponent) *corev1.Probe { - return &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ +func GetDefaultMicroProfileReadinessProbe(ba BaseComponent) *BaseComponentProbe { + return &BaseComponentProbe{ + BaseComponentProbeHandler: BaseComponentProbeHandler{ + HTTPGet: &OptionalHTTPGetAction{ Path: "/health/ready", Port: intstr.FromInt(int(ba.GetService().GetPort())), Scheme: "HTTPS", @@ -39,10 +38,10 @@ func GetDefaultMicroProfileReadinessProbe(ba BaseComponent) *corev1.Probe { } // GetDefaultMicroProfileLivenessProbe returns the default values for MicroProfile Health-based liveness probe. -func GetDefaultMicroProfileLivenessProbe(ba BaseComponent) *corev1.Probe { - return &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ +func GetDefaultMicroProfileLivenessProbe(ba BaseComponent) *BaseComponentProbe { + return &BaseComponentProbe{ + BaseComponentProbeHandler: BaseComponentProbeHandler{ + HTTPGet: &OptionalHTTPGetAction{ Path: "/health/live", Port: intstr.FromInt(int(ba.GetService().GetPort())), Scheme: "HTTPS", diff --git a/common/types.go b/common/types.go index ffaa55a84..401784071 100644 --- a/common/types.go +++ b/common/types.go @@ -7,6 +7,7 @@ import ( corev1 "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 ... @@ -175,15 +176,96 @@ type BaseComponentStatefulSet interface { GetAnnotations() map[string]string } +// +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"` +} + +// +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"` +} + +// +kubebuilder:object:generate=true +type OptionalHTTPGetAction struct { + // Path to access on the HTTP server. + // +optional + Path string `json:"path,omitempty" protobuf:"bytes,1,opt,name=path"` + // 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" protobuf:"bytes,2,opt,name=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" protobuf:"bytes,3,opt,name=host"` + // Scheme to use for connecting to the host. + // Defaults to HTTP. + // +optional + Scheme corev1.URIScheme `json:"scheme,omitempty" protobuf:"bytes,4,opt,name=scheme,casttype=URIScheme"` + // Custom headers to set in the request. HTTP allows repeated headers. + // +optional + HTTPHeaders []corev1.HTTPHeader `json:"httpHeaders,omitempty" protobuf:"bytes,5,rep,name=httpHeaders"` +} + // BaseComponentProbes describes the probes for application container type BaseComponentProbes interface { - GetLivenessProbe() *corev1.Probe - GetReadinessProbe() *corev1.Probe - GetStartupProbe() *corev1.Probe + GetLivenessProbe() *BaseComponentProbe + GetReadinessProbe() *BaseComponentProbe + GetStartupProbe() *BaseComponentProbe - GetDefaultLivenessProbe(ba BaseComponent) *corev1.Probe - GetDefaultReadinessProbe(ba BaseComponent) *corev1.Probe - GetDefaultStartupProbe(ba BaseComponent) *corev1.Probe + GetDefaultLivenessProbe(ba BaseComponent) *BaseComponentProbe + GetDefaultReadinessProbe(ba BaseComponent) *BaseComponentProbe + GetDefaultStartupProbe(ba BaseComponent) *BaseComponentProbe } type BaseComponentServiceAccount interface { diff --git a/common/zz_generated.deepcopy.go b/common/zz_generated.deepcopy.go new file mode 100644 index 000000000..91ae9fa1f --- /dev/null +++ b/common/zz_generated.deepcopy.go @@ -0,0 +1,103 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* + + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package common + +import ( + "k8s.io/api/core/v1" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BaseComponentProbe) DeepCopyInto(out *BaseComponentProbe) { + *out = *in + in.BaseComponentProbeHandler.DeepCopyInto(&out.BaseComponentProbeHandler) + if in.TerminationGracePeriodSeconds != nil { + in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds + *out = new(int64) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BaseComponentProbe. +func (in *BaseComponentProbe) DeepCopy() *BaseComponentProbe { + if in == nil { + return nil + } + out := new(BaseComponentProbe) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BaseComponentProbeHandler) DeepCopyInto(out *BaseComponentProbeHandler) { + *out = *in + if in.Exec != nil { + in, out := &in.Exec, &out.Exec + *out = new(v1.ExecAction) + (*in).DeepCopyInto(*out) + } + if in.HTTPGet != nil { + in, out := &in.HTTPGet, &out.HTTPGet + *out = new(OptionalHTTPGetAction) + (*in).DeepCopyInto(*out) + } + if in.TCPSocket != nil { + in, out := &in.TCPSocket, &out.TCPSocket + *out = new(v1.TCPSocketAction) + **out = **in + } + if in.GRPC != nil { + in, out := &in.GRPC, &out.GRPC + *out = new(v1.GRPCAction) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BaseComponentProbeHandler. +func (in *BaseComponentProbeHandler) DeepCopy() *BaseComponentProbeHandler { + if in == nil { + return nil + } + out := new(BaseComponentProbeHandler) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OptionalHTTPGetAction) DeepCopyInto(out *OptionalHTTPGetAction) { + *out = *in + out.Port = in.Port + if in.HTTPHeaders != nil { + in, out := &in.HTTPHeaders, &out.HTTPHeaders + *out = make([]v1.HTTPHeader, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OptionalHTTPGetAction. +func (in *OptionalHTTPGetAction) DeepCopy() *OptionalHTTPGetAction { + if in == nil { + return nil + } + out := new(OptionalHTTPGetAction) + in.DeepCopyInto(out) + return out +} diff --git a/utils/utils.go b/utils/utils.go index a2f5f8d4c..cf73b99de 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -294,39 +294,109 @@ func CustomizeProbes(container *corev1.Container, ba common.BaseComponent) { container.StartupProbe = customizeProbe(probesConfig.GetStartupProbe(), probesConfig.GetDefaultStartupProbe, ba) } -func customizeProbe(config *corev1.Probe, defaultProbeCallback func(ba common.BaseComponent) *corev1.Probe, ba common.BaseComponent) *corev1.Probe { +func customizeProbe(config *common.BaseComponentProbe, defaultProbeCallback func(ba common.BaseComponent) *common.BaseComponentProbe, ba common.BaseComponent) *corev1.Probe { // Probe not defined -- set probe to nil if config == nil { return nil } // Probe handler is defined in config so use probe as is - if config.ProbeHandler != (corev1.ProbeHandler{}) { - return config + if config.BaseComponentProbeHandler != (common.BaseComponentProbeHandler{}) { + return ConvertToCoreProbe(ba, config) } // Probe handler is not defined so use default values for the probe if values not set in probe config - return customizeProbeDefaults(config, defaultProbeCallback(ba)) + return ConvertToCoreProbe(ba, customizeProbeDefaults(config, defaultProbeCallback(ba))) } -func customizeProbeDefaults(config *corev1.Probe, defaultProbe *corev1.Probe) *corev1.Probe { - probe := defaultProbe - if config.InitialDelaySeconds != 0 { - probe.InitialDelaySeconds = config.InitialDelaySeconds - } - if config.TimeoutSeconds != 0 { - probe.TimeoutSeconds = config.TimeoutSeconds - } - if config.PeriodSeconds != 0 { - probe.PeriodSeconds = config.PeriodSeconds - } - if config.SuccessThreshold != 0 { - probe.SuccessThreshold = config.SuccessThreshold +func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optionalHTTPGetAction *common.OptionalHTTPGetAction) *corev1.HTTPGetAction { + httpGetAction := &corev1.HTTPGetAction{} + if optionalHTTPGetAction != nil { + if len(optionalHTTPGetAction.Host) > 0 { + httpGetAction.Host = optionalHTTPGetAction.Host + } + if len(optionalHTTPGetAction.Path) > 0 { + httpGetAction.Path = optionalHTTPGetAction.Path + } + if len(optionalHTTPGetAction.HTTPHeaders) > 0 { + httpGetAction.HTTPHeaders = optionalHTTPGetAction.HTTPHeaders + } + + manageTLSEnabled := ba.GetManageTLS() != nil && *ba.GetManageTLS() + if ba.GetService().GetPort() == 0 { + if manageTLSEnabled { + httpGetAction.Port = intstr.FromInt(9443) + } else { + httpGetAction.Port = intstr.FromInt(9080) + } + } else { + httpGetAction.Port = intstr.FromInt(int(ba.GetService().GetPort())) + } + + if manageTLSEnabled { + httpGetAction.Scheme = corev1.URISchemeHTTPS + } else { + httpGetAction.Scheme = corev1.URISchemeHTTP + } } - if config.FailureThreshold != 0 { - probe.FailureThreshold = config.FailureThreshold + return httpGetAction +} + +func ConvertToCoreProbe(ba common.BaseComponent, baseProbe *common.BaseComponentProbe) *corev1.Probe { + probe := &corev1.Probe{} + if baseProbe != nil { + if baseProbe.BaseComponentProbeHandler.Exec != nil { + probe.ProbeHandler.Exec = baseProbe.BaseComponentProbeHandler.Exec + } + probe.ProbeHandler.HTTPGet = createHTTPGetActionFromOptionalHTTPGetAction(ba, baseProbe.BaseComponentProbeHandler.HTTPGet) + if baseProbe.BaseComponentProbeHandler.TCPSocket != nil { + probe.ProbeHandler.TCPSocket = baseProbe.BaseComponentProbeHandler.TCPSocket + } + if baseProbe.BaseComponentProbeHandler.GRPC != nil { + probe.ProbeHandler.GRPC = baseProbe.BaseComponentProbeHandler.GRPC + } + + if baseProbe.InitialDelaySeconds != 0 { + probe.InitialDelaySeconds = baseProbe.InitialDelaySeconds + } + if baseProbe.TimeoutSeconds != 0 { + probe.TimeoutSeconds = baseProbe.TimeoutSeconds + } + if baseProbe.PeriodSeconds != 0 { + probe.PeriodSeconds = baseProbe.PeriodSeconds + } + if baseProbe.SuccessThreshold != 0 { + probe.SuccessThreshold = baseProbe.SuccessThreshold + } + if baseProbe.FailureThreshold != 0 { + probe.FailureThreshold = baseProbe.FailureThreshold + } + if baseProbe.TerminationGracePeriodSeconds != nil && *baseProbe.TerminationGracePeriodSeconds != 0 { + probe.TerminationGracePeriodSeconds = baseProbe.TerminationGracePeriodSeconds + } } + return probe +} +func customizeProbeDefaults(config *common.BaseComponentProbe, defaultProbe *common.BaseComponentProbe) *common.BaseComponentProbe { + probe := defaultProbe + if config != nil { + if config.InitialDelaySeconds != 0 { + probe.InitialDelaySeconds = config.InitialDelaySeconds + } + if config.TimeoutSeconds != 0 { + probe.TimeoutSeconds = config.TimeoutSeconds + } + if config.PeriodSeconds != 0 { + probe.PeriodSeconds = config.PeriodSeconds + } + if config.SuccessThreshold != 0 { + probe.SuccessThreshold = config.SuccessThreshold + } + if config.FailureThreshold != 0 { + probe.FailureThreshold = config.FailureThreshold + } + } return probe } diff --git a/utils/utils_test.go b/utils/utils_test.go index f62dbe3ff..be97986be 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -1,13 +1,14 @@ package utils import ( - appstacksv1 "github.com/application-stacks/runtime-component-operator/api/v1" "os" "reflect" "strconv" "testing" + appstacksv1 "github.com/application-stacks/runtime-component-operator/api/v1" "github.com/application-stacks/runtime-component-operator/common" + routev1 "github.com/openshift/api/route/v1" prometheusv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" appsv1 "k8s.io/api/apps/v1" @@ -55,21 +56,21 @@ var ( TypeMeta: metav1.TypeMeta{Kind: "StatefulSet"}} storage = appstacksv1.RuntimeComponentStorage{Size: "10Mi", MountPath: "/mnt/data", VolumeClaimTemplate: volumeCT} arch = []string{"ppc64le"} - readinessProbe = &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{}, + readinessProbe = &common.BaseComponentProbe{ + BaseComponentProbeHandler: common.BaseComponentProbeHandler{ + HTTPGet: &common.OptionalHTTPGetAction{}, TCPSocket: &corev1.TCPSocketAction{}, }, } - livenessProbe = &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{}, + livenessProbe = &common.BaseComponentProbe{ + BaseComponentProbeHandler: common.BaseComponentProbeHandler{ + HTTPGet: &common.OptionalHTTPGetAction{}, TCPSocket: &corev1.TCPSocketAction{}, }, } - startupProbe = &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{}, + startupProbe = &common.BaseComponentProbe{ + BaseComponentProbeHandler: common.BaseComponentProbeHandler{ + HTTPGet: &common.OptionalHTTPGetAction{}, TCPSocket: &corev1.TCPSocketAction{}, }, } From b2109605654133a30553e692d53af7ab782f0705 Mon Sep 17 00:00:00 2001 From: kabicin Date: Tue, 25 Jul 2023 16:45:33 -0400 Subject: [PATCH 02/25] Make port optional --- .../crd/bases/rc.app.stacks_runtimecomponents.yaml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml index dfb91eb7f..c01dc48a1 100644 --- a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml +++ b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml @@ -3127,8 +3127,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -3278,8 +3276,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -3430,8 +3426,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10497,8 +10491,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10648,8 +10640,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10800,8 +10790,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started From 5002432ca54e3f272c97430f5743a0daf0ce7d48 Mon Sep 17 00:00:00 2001 From: kabicin Date: Wed, 26 Jul 2023 11:21:30 -0400 Subject: [PATCH 03/25] Override fields using extending operators' default probe --- utils/utils.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index cf73b99de..eb0897ab7 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -322,21 +322,24 @@ func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optio httpGetAction.HTTPHeaders = optionalHTTPGetAction.HTTPHeaders } - manageTLSEnabled := ba.GetManageTLS() != nil && *ba.GetManageTLS() - if ba.GetService().GetPort() == 0 { - if manageTLSEnabled { - httpGetAction.Port = intstr.FromInt(9443) - } else { - httpGetAction.Port = intstr.FromInt(9080) - } - } else { + if len(optionalHTTPGetAction.Port.String()) > 0 { + httpGetAction.Port = optionalHTTPGetAction.Port + } else if ba.GetService().GetPort() > 0 { httpGetAction.Port = intstr.FromInt(int(ba.GetService().GetPort())) + } else { + // Can't create HTTPGetAction without a port specified, so return nil. + return nil } - if manageTLSEnabled { - httpGetAction.Scheme = corev1.URISchemeHTTPS + if optionalHTTPGetAction.Scheme == corev1.URISchemeHTTP || optionalHTTPGetAction.Scheme == corev1.URISchemeHTTPS { + httpGetAction.Scheme = optionalHTTPGetAction.Scheme } else { - httpGetAction.Scheme = corev1.URISchemeHTTP + manageTLSEnabled := ba.GetManageTLS() != nil && *ba.GetManageTLS() + if manageTLSEnabled { + httpGetAction.Scheme = corev1.URISchemeHTTPS + } else { + httpGetAction.Scheme = corev1.URISchemeHTTP + } } } return httpGetAction From cb16ef97a2a2e48460f44d57b5ae2c925b69e105 Mon Sep 17 00:00:00 2001 From: kabicin Date: Wed, 26 Jul 2023 11:22:55 -0400 Subject: [PATCH 04/25] Update utils.go --- utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index eb0897ab7..c81353253 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -331,7 +331,7 @@ func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optio return nil } - if optionalHTTPGetAction.Scheme == corev1.URISchemeHTTP || optionalHTTPGetAction.Scheme == corev1.URISchemeHTTPS { + if len(optionalHTTPGetAction.Scheme) > 0 { httpGetAction.Scheme = optionalHTTPGetAction.Scheme } else { manageTLSEnabled := ba.GetManageTLS() != nil && *ba.GetManageTLS() From 0c789948c39aad00eb3abcdea689a9a46cead9cc Mon Sep 17 00:00:00 2001 From: kabicin Date: Wed, 26 Jul 2023 13:08:27 -0400 Subject: [PATCH 05/25] Update utils.go --- utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index c81353253..075942445 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -331,7 +331,7 @@ func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optio return nil } - if len(optionalHTTPGetAction.Scheme) > 0 { + if optionalHTTPGetAction.Scheme != corev1.URISchemeHTTP { httpGetAction.Scheme = optionalHTTPGetAction.Scheme } else { manageTLSEnabled := ba.GetManageTLS() != nil && *ba.GetManageTLS() From b35349c4767655ea55e8275708eabd87fbac483d Mon Sep 17 00:00:00 2001 From: kabicin Date: Wed, 26 Jul 2023 14:37:45 -0400 Subject: [PATCH 06/25] Set default port to nil --- common/common.go | 9 ++++++--- common/types.go | 10 +++++----- utils/utils.go | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/common/common.go b/common/common.go index 8ef209e6b..9d790ec89 100644 --- a/common/common.go +++ b/common/common.go @@ -6,11 +6,12 @@ import ( // GetDefaultMicroProfileStartupProbe returns the default values for MicroProfile Health-based startup probe. func GetDefaultMicroProfileStartupProbe(ba BaseComponent) *BaseComponentProbe { + port := intstr.FromInt(int(ba.GetService().GetPort())) return &BaseComponentProbe{ BaseComponentProbeHandler: BaseComponentProbeHandler{ HTTPGet: &OptionalHTTPGetAction{ Path: "/health/started", - Port: intstr.FromInt(int(ba.GetService().GetPort())), + Port: &port, Scheme: "HTTPS", }, }, @@ -22,11 +23,12 @@ func GetDefaultMicroProfileStartupProbe(ba BaseComponent) *BaseComponentProbe { // GetDefaultMicroProfileReadinessProbe returns the default values for MicroProfile Health-based readiness probe. func GetDefaultMicroProfileReadinessProbe(ba BaseComponent) *BaseComponentProbe { + port := intstr.FromInt(int(ba.GetService().GetPort())) return &BaseComponentProbe{ BaseComponentProbeHandler: BaseComponentProbeHandler{ HTTPGet: &OptionalHTTPGetAction{ Path: "/health/ready", - Port: intstr.FromInt(int(ba.GetService().GetPort())), + Port: &port, Scheme: "HTTPS", }, }, @@ -39,11 +41,12 @@ func GetDefaultMicroProfileReadinessProbe(ba BaseComponent) *BaseComponentProbe // GetDefaultMicroProfileLivenessProbe returns the default values for MicroProfile Health-based liveness probe. func GetDefaultMicroProfileLivenessProbe(ba BaseComponent) *BaseComponentProbe { + port := intstr.FromInt(int(ba.GetService().GetPort())) return &BaseComponentProbe{ BaseComponentProbeHandler: BaseComponentProbeHandler{ HTTPGet: &OptionalHTTPGetAction{ Path: "/health/live", - Port: intstr.FromInt(int(ba.GetService().GetPort())), + Port: &port, Scheme: "HTTPS", }, }, diff --git a/common/types.go b/common/types.go index 401784071..4e94d0a59 100644 --- a/common/types.go +++ b/common/types.go @@ -238,23 +238,23 @@ type BaseComponentProbeHandler struct { type OptionalHTTPGetAction struct { // Path to access on the HTTP server. // +optional - Path string `json:"path,omitempty" protobuf:"bytes,1,opt,name=path"` + 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" protobuf:"bytes,2,opt,name=port"` + Port *intstr.IntOrString `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" protobuf:"bytes,3,opt,name=host"` + Host string `json:"host,omitempty"` // Scheme to use for connecting to the host. // Defaults to HTTP. // +optional - Scheme corev1.URIScheme `json:"scheme,omitempty" protobuf:"bytes,4,opt,name=scheme,casttype=URIScheme"` + Scheme corev1.URIScheme `json:"scheme,omitempty"` // Custom headers to set in the request. HTTP allows repeated headers. // +optional - HTTPHeaders []corev1.HTTPHeader `json:"httpHeaders,omitempty" protobuf:"bytes,5,rep,name=httpHeaders"` + HTTPHeaders []corev1.HTTPHeader `json:"httpHeaders,omitempty"` } // BaseComponentProbes describes the probes for application container diff --git a/utils/utils.go b/utils/utils.go index 075942445..9f7ad1e21 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -322,8 +322,8 @@ func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optio httpGetAction.HTTPHeaders = optionalHTTPGetAction.HTTPHeaders } - if len(optionalHTTPGetAction.Port.String()) > 0 { - httpGetAction.Port = optionalHTTPGetAction.Port + if optionalHTTPGetAction.Port != nil { + httpGetAction.Port = *optionalHTTPGetAction.Port } else if ba.GetService().GetPort() > 0 { httpGetAction.Port = intstr.FromInt(int(ba.GetService().GetPort())) } else { From 96925306b4bcde4c22be536ac81d7b9c6f9a2c5c Mon Sep 17 00:00:00 2001 From: kabicin Date: Wed, 26 Jul 2023 14:38:41 -0400 Subject: [PATCH 07/25] Update zz_generated.deepcopy.go --- common/zz_generated.deepcopy.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/zz_generated.deepcopy.go b/common/zz_generated.deepcopy.go index 91ae9fa1f..88bed28ba 100644 --- a/common/zz_generated.deepcopy.go +++ b/common/zz_generated.deepcopy.go @@ -23,6 +23,7 @@ package common import ( "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -84,7 +85,11 @@ func (in *BaseComponentProbeHandler) DeepCopy() *BaseComponentProbeHandler { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OptionalHTTPGetAction) DeepCopyInto(out *OptionalHTTPGetAction) { *out = *in - out.Port = in.Port + if in.Port != nil { + in, out := &in.Port, &out.Port + *out = new(intstr.IntOrString) + **out = **in + } if in.HTTPHeaders != nil { in, out := &in.HTTPHeaders, &out.HTTPHeaders *out = make([]v1.HTTPHeader, len(*in)) From 6c68adce9c641fd98ccd0f76d10dbdc5990b8a83 Mon Sep 17 00:00:00 2001 From: kabicin Date: Wed, 26 Jul 2023 15:03:34 -0400 Subject: [PATCH 08/25] Set values of probes to pointers --- common/common.go | 33 ++++++++++++++++++++++----------- common/types.go | 10 +++++----- common/zz_generated.deepcopy.go | 25 +++++++++++++++++++++++++ utils/utils.go | 30 +++++++++++++++--------------- 4 files changed, 67 insertions(+), 31 deletions(-) diff --git a/common/common.go b/common/common.go index 9d790ec89..724dec26b 100644 --- a/common/common.go +++ b/common/common.go @@ -7,6 +7,9 @@ import ( // GetDefaultMicroProfileStartupProbe returns the default values for MicroProfile Health-based startup probe. func GetDefaultMicroProfileStartupProbe(ba BaseComponent) *BaseComponentProbe { port := intstr.FromInt(int(ba.GetService().GetPort())) + periodSeconds := int32(10) + timeoutSeconds := int32(2) + failureThreshold := int32(20) return &BaseComponentProbe{ BaseComponentProbeHandler: BaseComponentProbeHandler{ HTTPGet: &OptionalHTTPGetAction{ @@ -15,15 +18,19 @@ func GetDefaultMicroProfileStartupProbe(ba BaseComponent) *BaseComponentProbe { Scheme: "HTTPS", }, }, - PeriodSeconds: 10, - TimeoutSeconds: 2, - FailureThreshold: 20, + PeriodSeconds: &periodSeconds, + TimeoutSeconds: &timeoutSeconds, + FailureThreshold: &failureThreshold, } } // GetDefaultMicroProfileReadinessProbe returns the default values for MicroProfile Health-based readiness probe. func GetDefaultMicroProfileReadinessProbe(ba BaseComponent) *BaseComponentProbe { port := intstr.FromInt(int(ba.GetService().GetPort())) + initialDelaySeconds := int32(10) + periodSeconds := int32(10) + timeoutSeconds := int32(2) + failureThreshold := int32(20) return &BaseComponentProbe{ BaseComponentProbeHandler: BaseComponentProbeHandler{ HTTPGet: &OptionalHTTPGetAction{ @@ -32,16 +39,20 @@ func GetDefaultMicroProfileReadinessProbe(ba BaseComponent) *BaseComponentProbe Scheme: "HTTPS", }, }, - InitialDelaySeconds: 10, - PeriodSeconds: 10, - TimeoutSeconds: 2, - FailureThreshold: 10, + InitialDelaySeconds: &initialDelaySeconds, + PeriodSeconds: &periodSeconds, + TimeoutSeconds: &timeoutSeconds, + FailureThreshold: &failureThreshold, } } // GetDefaultMicroProfileLivenessProbe returns the default values for MicroProfile Health-based liveness probe. func GetDefaultMicroProfileLivenessProbe(ba BaseComponent) *BaseComponentProbe { port := intstr.FromInt(int(ba.GetService().GetPort())) + initialDelaySeconds := int32(60) + periodSeconds := int32(10) + timeoutSeconds := int32(2) + failureThreshold := int32(3) return &BaseComponentProbe{ BaseComponentProbeHandler: BaseComponentProbeHandler{ HTTPGet: &OptionalHTTPGetAction{ @@ -50,10 +61,10 @@ func GetDefaultMicroProfileLivenessProbe(ba BaseComponent) *BaseComponentProbe { Scheme: "HTTPS", }, }, - InitialDelaySeconds: 60, - PeriodSeconds: 10, - TimeoutSeconds: 2, - FailureThreshold: 3, + InitialDelaySeconds: &initialDelaySeconds, + PeriodSeconds: &periodSeconds, + TimeoutSeconds: &timeoutSeconds, + FailureThreshold: &failureThreshold, } } diff --git a/common/types.go b/common/types.go index 4e94d0a59..f434ae52d 100644 --- a/common/types.go +++ b/common/types.go @@ -183,24 +183,24 @@ type BaseComponentProbe 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. // 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"` + 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"` + 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"` + 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"` + 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. diff --git a/common/zz_generated.deepcopy.go b/common/zz_generated.deepcopy.go index 88bed28ba..0a2049de1 100644 --- a/common/zz_generated.deepcopy.go +++ b/common/zz_generated.deepcopy.go @@ -30,6 +30,31 @@ import ( func (in *BaseComponentProbe) DeepCopyInto(out *BaseComponentProbe) { *out = *in in.BaseComponentProbeHandler.DeepCopyInto(&out.BaseComponentProbeHandler) + if in.InitialDelaySeconds != nil { + in, out := &in.InitialDelaySeconds, &out.InitialDelaySeconds + *out = new(int32) + **out = **in + } + if in.TimeoutSeconds != nil { + in, out := &in.TimeoutSeconds, &out.TimeoutSeconds + *out = new(int32) + **out = **in + } + if in.PeriodSeconds != nil { + in, out := &in.PeriodSeconds, &out.PeriodSeconds + *out = new(int32) + **out = **in + } + if in.SuccessThreshold != nil { + in, out := &in.SuccessThreshold, &out.SuccessThreshold + *out = new(int32) + **out = **in + } + if in.FailureThreshold != nil { + in, out := &in.FailureThreshold, &out.FailureThreshold + *out = new(int32) + **out = **in + } if in.TerminationGracePeriodSeconds != nil { in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds *out = new(int64) diff --git a/utils/utils.go b/utils/utils.go index 9f7ad1e21..62def74cf 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -359,20 +359,20 @@ func ConvertToCoreProbe(ba common.BaseComponent, baseProbe *common.BaseComponent probe.ProbeHandler.GRPC = baseProbe.BaseComponentProbeHandler.GRPC } - if baseProbe.InitialDelaySeconds != 0 { - probe.InitialDelaySeconds = baseProbe.InitialDelaySeconds + if baseProbe.InitialDelaySeconds != nil && *baseProbe.InitialDelaySeconds != 0 { + probe.InitialDelaySeconds = *baseProbe.InitialDelaySeconds } - if baseProbe.TimeoutSeconds != 0 { - probe.TimeoutSeconds = baseProbe.TimeoutSeconds + if baseProbe.TimeoutSeconds != nil && *baseProbe.TimeoutSeconds != 0 { + probe.TimeoutSeconds = *baseProbe.TimeoutSeconds } - if baseProbe.PeriodSeconds != 0 { - probe.PeriodSeconds = baseProbe.PeriodSeconds + if baseProbe.PeriodSeconds != nil && *baseProbe.PeriodSeconds != 0 { + probe.PeriodSeconds = *baseProbe.PeriodSeconds } - if baseProbe.SuccessThreshold != 0 { - probe.SuccessThreshold = baseProbe.SuccessThreshold + if baseProbe.SuccessThreshold != nil && *baseProbe.SuccessThreshold != 0 { + probe.SuccessThreshold = *baseProbe.SuccessThreshold } - if baseProbe.FailureThreshold != 0 { - probe.FailureThreshold = baseProbe.FailureThreshold + if baseProbe.FailureThreshold != nil && *baseProbe.FailureThreshold != 0 { + probe.FailureThreshold = *baseProbe.FailureThreshold } if baseProbe.TerminationGracePeriodSeconds != nil && *baseProbe.TerminationGracePeriodSeconds != 0 { probe.TerminationGracePeriodSeconds = baseProbe.TerminationGracePeriodSeconds @@ -384,19 +384,19 @@ func ConvertToCoreProbe(ba common.BaseComponent, baseProbe *common.BaseComponent func customizeProbeDefaults(config *common.BaseComponentProbe, defaultProbe *common.BaseComponentProbe) *common.BaseComponentProbe { probe := defaultProbe if config != nil { - if config.InitialDelaySeconds != 0 { + if config.InitialDelaySeconds != nil && *config.InitialDelaySeconds != 0 { probe.InitialDelaySeconds = config.InitialDelaySeconds } - if config.TimeoutSeconds != 0 { + if config.TimeoutSeconds != nil && *config.TimeoutSeconds != 0 { probe.TimeoutSeconds = config.TimeoutSeconds } - if config.PeriodSeconds != 0 { + if config.PeriodSeconds != nil && *config.PeriodSeconds != 0 { probe.PeriodSeconds = config.PeriodSeconds } - if config.SuccessThreshold != 0 { + if config.SuccessThreshold != nil && *config.SuccessThreshold != 0 { probe.SuccessThreshold = config.SuccessThreshold } - if config.FailureThreshold != 0 { + if config.FailureThreshold != nil && *config.FailureThreshold != 0 { probe.FailureThreshold = config.FailureThreshold } } From 310180f3a6313e38e8423e8064c8802a9c1bd9db Mon Sep 17 00:00:00 2001 From: kabicin Date: Wed, 26 Jul 2023 16:09:36 -0400 Subject: [PATCH 09/25] Add probe defaults override function to interface --- api/v1/runtimecomponent_types.go | 15 ++++ api/v1beta2/runtimecomponent_types.go | 15 ++++ common/types.go | 14 ++-- .../rc.app.stacks_runtimecomponents.yaml | 78 +++++++------------ utils/utils.go | 27 +++++-- 5 files changed, 88 insertions(+), 61 deletions(-) diff --git a/api/v1/runtimecomponent_types.go b/api/v1/runtimecomponent_types.go index 1e34699b4..f4a2325ff 100644 --- a/api/v1/runtimecomponent_types.go +++ b/api/v1/runtimecomponent_types.go @@ -566,6 +566,21 @@ func (p *RuntimeComponentProbes) GetDefaultStartupProbe(ba common.BaseComponent) return common.GetDefaultMicroProfileStartupProbe(ba) } +// OverrideDefaultLivenessProbe overrides default values for and returns the liveness probe +func (p *RuntimeComponentProbes) OverrideDefaultLivenessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { + return probe +} + +// OverrideDefaultReadinessProbe overrides default values for and returns the readiness probe +func (p *RuntimeComponentProbes) OverrideDefaultReadinessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { + return probe +} + +// OverrideDefaultStartupProbe overrides default values for and returns the startup probe +func (p *RuntimeComponentProbes) OverrideDefaultStartupProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { + return probe +} + // GetVolumes returns volumes slice func (cr *RuntimeComponent) GetVolumes() []corev1.Volume { return cr.Spec.Volumes diff --git a/api/v1beta2/runtimecomponent_types.go b/api/v1beta2/runtimecomponent_types.go index 3d602f072..302f96425 100644 --- a/api/v1beta2/runtimecomponent_types.go +++ b/api/v1beta2/runtimecomponent_types.go @@ -147,6 +147,21 @@ type RuntimeComponentProbes struct { Startup *common.BaseComponentProbe `json:"startup,omitempty"` } +// OverrideDefaultLivenessProbe overrides default values for and returns the liveness probe +func (p *RuntimeComponentProbes) OverrideDefaultLivenessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { + return probe +} + +// OverrideDefaultReadinessProbe overrides default values for and returns the readiness probe +func (p *RuntimeComponentProbes) OverrideDefaultReadinessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { + return probe +} + +// OverrideDefaultStartupProbe overrides default values for and returns the startup probe +func (p *RuntimeComponentProbes) OverrideDefaultStartupProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { + return probe +} + func (in *RuntimeComponentProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *common.BaseComponentProbe { return nil } diff --git a/common/types.go b/common/types.go index f434ae52d..db01732df 100644 --- a/common/types.go +++ b/common/types.go @@ -185,20 +185,20 @@ type BaseComponentProbe struct { // +optional InitialDelaySeconds *int32 `json:"initialDelaySeconds,omitempty"` // Number of seconds after which the probe times out. - // Defaults to 1 second. Minimum value is 1. + // Defaults to nil. // 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. + // Defaults to nil. // +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. + // Defaults to nil. // +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. + // Defaults to nil. // +optional FailureThreshold *int32 `json:"failureThreshold,omitempty"` // Optional duration in seconds the pod needs to terminate gracefully upon probe failure. @@ -210,7 +210,7 @@ type BaseComponentProbe struct { // 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. + // Defaults to nil // +optional TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` } @@ -266,6 +266,10 @@ type BaseComponentProbes interface { GetDefaultLivenessProbe(ba BaseComponent) *BaseComponentProbe GetDefaultReadinessProbe(ba BaseComponent) *BaseComponentProbe GetDefaultStartupProbe(ba BaseComponent) *BaseComponentProbe + + OverrideDefaultLivenessProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe + OverrideDefaultReadinessProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe + OverrideDefaultStartupProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe } type BaseComponentServiceAccount interface { diff --git a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml index c01dc48a1..e3ed73aa5 100644 --- a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml +++ b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml @@ -3062,7 +3062,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - 3. Minimum value is 1. + nil. format: int32 type: integer grpc: @@ -3135,14 +3135,13 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Default to 10 seconds. Minimum value is 1. + Defaults to nil. format: int32 type: integer successThreshold: description: 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. + nil. format: int32 type: integer tcpSocket: @@ -3177,14 +3176,12 @@ spec: 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. + Defaults to nil format: int64 type: integer timeoutSeconds: description: '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' + out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -3211,7 +3208,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - 3. Minimum value is 1. + nil. format: int32 type: integer grpc: @@ -3284,14 +3281,13 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Default to 10 seconds. Minimum value is 1. + Defaults to nil. format: int32 type: integer successThreshold: description: 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. + nil. format: int32 type: integer tcpSocket: @@ -3326,14 +3322,12 @@ spec: 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. + Defaults to nil format: int64 type: integer timeoutSeconds: description: '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' + out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -3361,7 +3355,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - 3. Minimum value is 1. + nil. format: int32 type: integer grpc: @@ -3434,14 +3428,13 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Default to 10 seconds. Minimum value is 1. + Defaults to nil. format: int32 type: integer successThreshold: description: 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. + nil. format: int32 type: integer tcpSocket: @@ -3476,14 +3469,12 @@ spec: 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. + Defaults to nil format: int64 type: integer timeoutSeconds: description: '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' + out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -10426,7 +10417,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - 3. Minimum value is 1. + nil. format: int32 type: integer grpc: @@ -10499,14 +10490,13 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Default to 10 seconds. Minimum value is 1. + Defaults to nil. format: int32 type: integer successThreshold: description: 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. + nil. format: int32 type: integer tcpSocket: @@ -10541,14 +10531,12 @@ spec: 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. + Defaults to nil format: int64 type: integer timeoutSeconds: description: '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' + out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -10575,7 +10563,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - 3. Minimum value is 1. + nil. format: int32 type: integer grpc: @@ -10648,14 +10636,13 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Default to 10 seconds. Minimum value is 1. + Defaults to nil. format: int32 type: integer successThreshold: description: 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. + nil. format: int32 type: integer tcpSocket: @@ -10690,14 +10677,12 @@ spec: 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. + Defaults to nil format: int64 type: integer timeoutSeconds: description: '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' + out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -10725,7 +10710,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - 3. Minimum value is 1. + nil. format: int32 type: integer grpc: @@ -10798,14 +10783,13 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Default to 10 seconds. Minimum value is 1. + Defaults to nil. format: int32 type: integer successThreshold: description: 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. + nil. format: int32 type: integer tcpSocket: @@ -10840,14 +10824,12 @@ spec: 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. + Defaults to nil format: int64 type: integer timeoutSeconds: description: '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' + out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object diff --git a/utils/utils.go b/utils/utils.go index 62def74cf..b863bc050 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -289,12 +289,12 @@ func CustomizeProbes(container *corev1.Container, ba common.BaseComponent) { return } - container.ReadinessProbe = customizeProbe(probesConfig.GetReadinessProbe(), probesConfig.GetDefaultReadinessProbe, ba) - container.LivenessProbe = customizeProbe(probesConfig.GetLivenessProbe(), probesConfig.GetDefaultLivenessProbe, ba) - container.StartupProbe = customizeProbe(probesConfig.GetStartupProbe(), probesConfig.GetDefaultStartupProbe, ba) + container.ReadinessProbe = customizeProbe(probesConfig.GetReadinessProbe(), probesConfig.GetDefaultReadinessProbe, probesConfig.OverrideDefaultReadinessProbe, ba) + container.LivenessProbe = customizeProbe(probesConfig.GetLivenessProbe(), probesConfig.GetDefaultLivenessProbe, probesConfig.OverrideDefaultLivenessProbe, ba) + container.StartupProbe = customizeProbe(probesConfig.GetStartupProbe(), probesConfig.GetDefaultStartupProbe, probesConfig.OverrideDefaultStartupProbe, ba) } -func customizeProbe(config *common.BaseComponentProbe, defaultProbeCallback func(ba common.BaseComponent) *common.BaseComponentProbe, ba common.BaseComponent) *corev1.Probe { +func customizeProbe(config *common.BaseComponentProbe, getDefaultProbeCallback func(ba common.BaseComponent) *common.BaseComponentProbe, overrideProbeDefaultsCallback func(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe, ba common.BaseComponent) *corev1.Probe { // Probe not defined -- set probe to nil if config == nil { return nil @@ -302,11 +302,11 @@ func customizeProbe(config *common.BaseComponentProbe, defaultProbeCallback func // Probe handler is defined in config so use probe as is if config.BaseComponentProbeHandler != (common.BaseComponentProbeHandler{}) { - return ConvertToCoreProbe(ba, config) + return ConvertToCoreProbe(ba, overrideProbeDefaultsCallback(ba, config)) } // Probe handler is not defined so use default values for the probe if values not set in probe config - return ConvertToCoreProbe(ba, customizeProbeDefaults(config, defaultProbeCallback(ba))) + return ConvertToCoreProbe(ba, overrideProbeDefaultsCallback(ba, customizeProbeDefaults(config, getDefaultProbeCallback(ba)))) } func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optionalHTTPGetAction *common.OptionalHTTPGetAction) *corev1.HTTPGetAction { @@ -334,8 +334,7 @@ func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optio if optionalHTTPGetAction.Scheme != corev1.URISchemeHTTP { httpGetAction.Scheme = optionalHTTPGetAction.Scheme } else { - manageTLSEnabled := ba.GetManageTLS() != nil && *ba.GetManageTLS() - if manageTLSEnabled { + if ba.GetManageTLS() != nil && *ba.GetManageTLS() { httpGetAction.Scheme = corev1.URISchemeHTTPS } else { httpGetAction.Scheme = corev1.URISchemeHTTP @@ -384,6 +383,18 @@ func ConvertToCoreProbe(ba common.BaseComponent, baseProbe *common.BaseComponent func customizeProbeDefaults(config *common.BaseComponentProbe, defaultProbe *common.BaseComponentProbe) *common.BaseComponentProbe { probe := defaultProbe if config != nil { + if config.BaseComponentProbeHandler.Exec != nil { + probe.BaseComponentProbeHandler.Exec = config.BaseComponentProbeHandler.Exec + } + if config.BaseComponentProbeHandler.HTTPGet != nil { + probe.BaseComponentProbeHandler.HTTPGet = config.BaseComponentProbeHandler.HTTPGet + } + if config.BaseComponentProbeHandler.TCPSocket != nil { + probe.BaseComponentProbeHandler.TCPSocket = config.BaseComponentProbeHandler.TCPSocket + } + if config.BaseComponentProbeHandler.GRPC != nil { + probe.BaseComponentProbeHandler.GRPC = config.BaseComponentProbeHandler.GRPC + } if config.InitialDelaySeconds != nil && *config.InitialDelaySeconds != 0 { probe.InitialDelaySeconds = config.InitialDelaySeconds } From 0d4066c908e71dc329a93071b31e69a8bb44d5c0 Mon Sep 17 00:00:00 2001 From: kabicin Date: Wed, 26 Jul 2023 16:19:15 -0400 Subject: [PATCH 10/25] Update naming from override to patch --- api/v1/runtimecomponent_types.go | 30 +++++++++++++-------------- api/v1beta2/runtimecomponent_types.go | 12 +++++------ common/types.go | 6 +++--- utils/utils.go | 12 +++++------ 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/api/v1/runtimecomponent_types.go b/api/v1/runtimecomponent_types.go index f4a2325ff..61ca4dad3 100644 --- a/api/v1/runtimecomponent_types.go +++ b/api/v1/runtimecomponent_types.go @@ -551,6 +551,21 @@ func (p *RuntimeComponentProbes) GetStartupProbe() *common.BaseComponentProbe { return p.Startup } +// PatchLivenessProbe updates values for and returns the liveness probe +func (p *RuntimeComponentProbes) PatchLivenessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { + return probe +} + +// PatchReadinessProbe updates values for and returns the readiness probe +func (p *RuntimeComponentProbes) PatchReadinessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { + return probe +} + +// PatchStartupProbe updates values for and returns the startup probe +func (p *RuntimeComponentProbes) PatchStartupProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { + return probe +} + // GetDefaultLivenessProbe returns default values for liveness probe func (p *RuntimeComponentProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *common.BaseComponentProbe { return common.GetDefaultMicroProfileLivenessProbe(ba) @@ -566,21 +581,6 @@ func (p *RuntimeComponentProbes) GetDefaultStartupProbe(ba common.BaseComponent) return common.GetDefaultMicroProfileStartupProbe(ba) } -// OverrideDefaultLivenessProbe overrides default values for and returns the liveness probe -func (p *RuntimeComponentProbes) OverrideDefaultLivenessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { - return probe -} - -// OverrideDefaultReadinessProbe overrides default values for and returns the readiness probe -func (p *RuntimeComponentProbes) OverrideDefaultReadinessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { - return probe -} - -// OverrideDefaultStartupProbe overrides default values for and returns the startup probe -func (p *RuntimeComponentProbes) OverrideDefaultStartupProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { - return probe -} - // GetVolumes returns volumes slice func (cr *RuntimeComponent) GetVolumes() []corev1.Volume { return cr.Spec.Volumes diff --git a/api/v1beta2/runtimecomponent_types.go b/api/v1beta2/runtimecomponent_types.go index 302f96425..aec600930 100644 --- a/api/v1beta2/runtimecomponent_types.go +++ b/api/v1beta2/runtimecomponent_types.go @@ -147,18 +147,18 @@ type RuntimeComponentProbes struct { Startup *common.BaseComponentProbe `json:"startup,omitempty"` } -// OverrideDefaultLivenessProbe overrides default values for and returns the liveness probe -func (p *RuntimeComponentProbes) OverrideDefaultLivenessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { +// PatchLivenessProbe updates values for and returns the liveness probe +func (p *RuntimeComponentProbes) PatchLivenessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { return probe } -// OverrideDefaultReadinessProbe overrides default values for and returns the readiness probe -func (p *RuntimeComponentProbes) OverrideDefaultReadinessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { +// PatchReadinessProbe updates values for and returns the readiness probe +func (p *RuntimeComponentProbes) PatchReadinessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { return probe } -// OverrideDefaultStartupProbe overrides default values for and returns the startup probe -func (p *RuntimeComponentProbes) OverrideDefaultStartupProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { +// PatchStartupProbe updates values for and returns the startup probe +func (p *RuntimeComponentProbes) PatchStartupProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { return probe } diff --git a/common/types.go b/common/types.go index db01732df..0f10d3f91 100644 --- a/common/types.go +++ b/common/types.go @@ -267,9 +267,9 @@ type BaseComponentProbes interface { GetDefaultReadinessProbe(ba BaseComponent) *BaseComponentProbe GetDefaultStartupProbe(ba BaseComponent) *BaseComponentProbe - OverrideDefaultLivenessProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe - OverrideDefaultReadinessProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe - OverrideDefaultStartupProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe + PatchLivenessProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe + PatchReadinessProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe + PatchStartupProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe } type BaseComponentServiceAccount interface { diff --git a/utils/utils.go b/utils/utils.go index b863bc050..4e5c63508 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -289,12 +289,12 @@ func CustomizeProbes(container *corev1.Container, ba common.BaseComponent) { return } - container.ReadinessProbe = customizeProbe(probesConfig.GetReadinessProbe(), probesConfig.GetDefaultReadinessProbe, probesConfig.OverrideDefaultReadinessProbe, ba) - container.LivenessProbe = customizeProbe(probesConfig.GetLivenessProbe(), probesConfig.GetDefaultLivenessProbe, probesConfig.OverrideDefaultLivenessProbe, ba) - container.StartupProbe = customizeProbe(probesConfig.GetStartupProbe(), probesConfig.GetDefaultStartupProbe, probesConfig.OverrideDefaultStartupProbe, ba) + container.ReadinessProbe = customizeProbe(probesConfig.GetReadinessProbe(), probesConfig.GetDefaultReadinessProbe, probesConfig.PatchReadinessProbe, ba) + container.LivenessProbe = customizeProbe(probesConfig.GetLivenessProbe(), probesConfig.GetDefaultLivenessProbe, probesConfig.PatchLivenessProbe, ba) + container.StartupProbe = customizeProbe(probesConfig.GetStartupProbe(), probesConfig.GetDefaultStartupProbe, probesConfig.PatchStartupProbe, ba) } -func customizeProbe(config *common.BaseComponentProbe, getDefaultProbeCallback func(ba common.BaseComponent) *common.BaseComponentProbe, overrideProbeDefaultsCallback func(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe, ba common.BaseComponent) *corev1.Probe { +func customizeProbe(config *common.BaseComponentProbe, getDefaultProbeCallback func(ba common.BaseComponent) *common.BaseComponentProbe, patchProbeCallback func(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe, ba common.BaseComponent) *corev1.Probe { // Probe not defined -- set probe to nil if config == nil { return nil @@ -302,11 +302,11 @@ func customizeProbe(config *common.BaseComponentProbe, getDefaultProbeCallback f // Probe handler is defined in config so use probe as is if config.BaseComponentProbeHandler != (common.BaseComponentProbeHandler{}) { - return ConvertToCoreProbe(ba, overrideProbeDefaultsCallback(ba, config)) + return ConvertToCoreProbe(ba, patchProbeCallback(ba, config)) } // Probe handler is not defined so use default values for the probe if values not set in probe config - return ConvertToCoreProbe(ba, overrideProbeDefaultsCallback(ba, customizeProbeDefaults(config, getDefaultProbeCallback(ba)))) + return ConvertToCoreProbe(ba, patchProbeCallback(ba, customizeProbeDefaults(config, getDefaultProbeCallback(ba)))) } func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optionalHTTPGetAction *common.OptionalHTTPGetAction) *corev1.HTTPGetAction { From 0d16ff5de143f82031b9f8329e602e0e43cc7155 Mon Sep 17 00:00:00 2001 From: kabicin Date: Thu, 27 Jul 2023 08:59:17 -0400 Subject: [PATCH 11/25] Update runtimecomponent_types.go --- api/v1beta2/runtimecomponent_types.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/v1beta2/runtimecomponent_types.go b/api/v1beta2/runtimecomponent_types.go index aec600930..774cd67db 100644 --- a/api/v1beta2/runtimecomponent_types.go +++ b/api/v1beta2/runtimecomponent_types.go @@ -162,15 +162,18 @@ func (p *RuntimeComponentProbes) PatchStartupProbe(ba common.BaseComponent, prob return probe } +// GetDefaultLivenessProbe returns default values for liveness probe func (in *RuntimeComponentProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *common.BaseComponentProbe { return nil } +// GetDefaultReadinessProbe returns default values for readiness probe func (in *RuntimeComponentProbes) GetDefaultReadinessProbe(ba common.BaseComponent) *common.BaseComponentProbe { return nil } +// GetDefaultStartupProbe returns default values for startup probe func (in *RuntimeComponentProbes) GetDefaultStartupProbe(ba common.BaseComponent) *common.BaseComponentProbe { return nil } From 2405dcb974fc5f95a5542538a9cb483d822df3b9 Mon Sep 17 00:00:00 2001 From: kabicin Date: Thu, 27 Jul 2023 10:18:35 -0400 Subject: [PATCH 12/25] Cite struct code from k8s impl --- common/types.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/types.go b/common/types.go index 0f10d3f91..7dbeb169f 100644 --- a/common/types.go +++ b/common/types.go @@ -176,6 +176,7 @@ type BaseComponentStatefulSet interface { GetAnnotations() map[string]string } +// This struct is taken from the Probe implementation in https://github.com/kubernetes/api/blob/v0.24.2/core/v1/types.go // +kubebuilder:object:generate=true type BaseComponentProbe struct { // The action taken to determine the health of a container @@ -215,6 +216,7 @@ type BaseComponentProbe struct { TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` } +// This struct is taken from the ProbeHandler implementation in https://github.com/kubernetes/api/blob/v0.24.2/core/v1/types.go // +kubebuilder:object:generate=true type BaseComponentProbeHandler struct { // Exec specifies the action to take. @@ -234,6 +236,7 @@ type BaseComponentProbeHandler struct { GRPC *corev1.GRPCAction `json:"grpc,omitempty"` } +// This struct is based upon the HTTPGetAction implementation in https://github.com/kubernetes/api/blob/v0.24.2/core/v1/types.go // +kubebuilder:object:generate=true type OptionalHTTPGetAction struct { // Path to access on the HTTP server. From 7f6b8d67b6661d54c5ccbd3b6258ff1384f11cf4 Mon Sep 17 00:00:00 2001 From: kabicin Date: Thu, 27 Jul 2023 10:21:16 -0400 Subject: [PATCH 13/25] Update types.go --- common/types.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/types.go b/common/types.go index 7dbeb169f..b38ef8150 100644 --- a/common/types.go +++ b/common/types.go @@ -176,7 +176,7 @@ type BaseComponentStatefulSet interface { GetAnnotations() map[string]string } -// This struct is taken from the Probe implementation in https://github.com/kubernetes/api/blob/v0.24.2/core/v1/types.go +// This struct is taken from the Probe specification in https://github.com/kubernetes/api/blob/v0.24.2/core/v1/types.go // +kubebuilder:object:generate=true type BaseComponentProbe struct { // The action taken to determine the health of a container @@ -216,7 +216,7 @@ type BaseComponentProbe struct { TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` } -// This struct is taken from the ProbeHandler implementation in https://github.com/kubernetes/api/blob/v0.24.2/core/v1/types.go +// This struct is taken from the ProbeHandler specification in https://github.com/kubernetes/api/blob/v0.24.2/core/v1/types.go // +kubebuilder:object:generate=true type BaseComponentProbeHandler struct { // Exec specifies the action to take. @@ -236,7 +236,7 @@ type BaseComponentProbeHandler struct { GRPC *corev1.GRPCAction `json:"grpc,omitempty"` } -// This struct is based upon the HTTPGetAction implementation in https://github.com/kubernetes/api/blob/v0.24.2/core/v1/types.go +// This struct is based upon the HTTPGetAction specification in https://github.com/kubernetes/api/blob/v0.24.2/core/v1/types.go // +kubebuilder:object:generate=true type OptionalHTTPGetAction struct { // Path to access on the HTTP server. From 927e6ee6fb557903aeddeca9a6d08c9f8d5a2ecc Mon Sep 17 00:00:00 2001 From: kabicin Date: Thu, 5 Oct 2023 15:47:30 -0400 Subject: [PATCH 14/25] Simplify ProbeHandler type --- .../rc.app.stacks_runtimecomponents.yaml | 12 --- common/common.go | 33 +++----- common/types.go | 22 +++--- common/zz_generated.deepcopy.go | 25 ------ .../rc.app.stacks_runtimecomponents.yaml | 78 ++++++++++++------- .../deploy/kubectl/runtime-component-crd.yaml | 12 --- .../daily/base/runtime-component-crd.yaml | 12 --- utils/utils.go | 45 +++-------- 8 files changed, 81 insertions(+), 158 deletions(-) diff --git a/bundle/manifests/rc.app.stacks_runtimecomponents.yaml b/bundle/manifests/rc.app.stacks_runtimecomponents.yaml index c367198cd..5cc06e8cc 100644 --- a/bundle/manifests/rc.app.stacks_runtimecomponents.yaml +++ b/bundle/manifests/rc.app.stacks_runtimecomponents.yaml @@ -3130,8 +3130,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -3281,8 +3279,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -3433,8 +3429,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10500,8 +10494,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10651,8 +10643,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10803,8 +10793,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started diff --git a/common/common.go b/common/common.go index 724dec26b..9d790ec89 100644 --- a/common/common.go +++ b/common/common.go @@ -7,9 +7,6 @@ import ( // GetDefaultMicroProfileStartupProbe returns the default values for MicroProfile Health-based startup probe. func GetDefaultMicroProfileStartupProbe(ba BaseComponent) *BaseComponentProbe { port := intstr.FromInt(int(ba.GetService().GetPort())) - periodSeconds := int32(10) - timeoutSeconds := int32(2) - failureThreshold := int32(20) return &BaseComponentProbe{ BaseComponentProbeHandler: BaseComponentProbeHandler{ HTTPGet: &OptionalHTTPGetAction{ @@ -18,19 +15,15 @@ func GetDefaultMicroProfileStartupProbe(ba BaseComponent) *BaseComponentProbe { Scheme: "HTTPS", }, }, - PeriodSeconds: &periodSeconds, - TimeoutSeconds: &timeoutSeconds, - FailureThreshold: &failureThreshold, + PeriodSeconds: 10, + TimeoutSeconds: 2, + FailureThreshold: 20, } } // GetDefaultMicroProfileReadinessProbe returns the default values for MicroProfile Health-based readiness probe. func GetDefaultMicroProfileReadinessProbe(ba BaseComponent) *BaseComponentProbe { port := intstr.FromInt(int(ba.GetService().GetPort())) - initialDelaySeconds := int32(10) - periodSeconds := int32(10) - timeoutSeconds := int32(2) - failureThreshold := int32(20) return &BaseComponentProbe{ BaseComponentProbeHandler: BaseComponentProbeHandler{ HTTPGet: &OptionalHTTPGetAction{ @@ -39,20 +32,16 @@ func GetDefaultMicroProfileReadinessProbe(ba BaseComponent) *BaseComponentProbe Scheme: "HTTPS", }, }, - InitialDelaySeconds: &initialDelaySeconds, - PeriodSeconds: &periodSeconds, - TimeoutSeconds: &timeoutSeconds, - FailureThreshold: &failureThreshold, + InitialDelaySeconds: 10, + PeriodSeconds: 10, + TimeoutSeconds: 2, + FailureThreshold: 10, } } // GetDefaultMicroProfileLivenessProbe returns the default values for MicroProfile Health-based liveness probe. func GetDefaultMicroProfileLivenessProbe(ba BaseComponent) *BaseComponentProbe { port := intstr.FromInt(int(ba.GetService().GetPort())) - initialDelaySeconds := int32(60) - periodSeconds := int32(10) - timeoutSeconds := int32(2) - failureThreshold := int32(3) return &BaseComponentProbe{ BaseComponentProbeHandler: BaseComponentProbeHandler{ HTTPGet: &OptionalHTTPGetAction{ @@ -61,10 +50,10 @@ func GetDefaultMicroProfileLivenessProbe(ba BaseComponent) *BaseComponentProbe { Scheme: "HTTPS", }, }, - InitialDelaySeconds: &initialDelaySeconds, - PeriodSeconds: &periodSeconds, - TimeoutSeconds: &timeoutSeconds, - FailureThreshold: &failureThreshold, + InitialDelaySeconds: 60, + PeriodSeconds: 10, + TimeoutSeconds: 2, + FailureThreshold: 3, } } diff --git a/common/types.go b/common/types.go index b38ef8150..ca09a8d2e 100644 --- a/common/types.go +++ b/common/types.go @@ -184,24 +184,24 @@ type BaseComponentProbe 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. - // Defaults to nil. + // 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"` + TimeoutSeconds int32 `json:"timeoutSeconds,omitempty"` // How often (in seconds) to perform the probe. - // Defaults to nil. + // Default to 10 seconds. Minimum value is 1. // +optional - PeriodSeconds *int32 `json:"periodSeconds,omitempty"` + PeriodSeconds int32 `json:"periodSeconds,omitempty"` // Minimum consecutive successes for the probe to be considered successful after having failed. - // Defaults to nil. + // Defaults to 1. Must be 1 for liveness and startup. Minimum value is 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. - // Defaults to nil. + // Defaults to 3. Minimum value is 1. // +optional - FailureThreshold *int32 `json:"failureThreshold,omitempty"` + 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. @@ -211,7 +211,7 @@ type BaseComponentProbe struct { // 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. - // Defaults to nil + // Minimum value is 1. spec.terminationGracePeriodSeconds is used if unset. // +optional TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` } @@ -246,7 +246,7 @@ type OptionalHTTPGetAction struct { // Number must be in the range 1 to 65535. // Name must be an IANA_SVC_NAME. // +optional - Port *intstr.IntOrString `json:"port"` + 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 diff --git a/common/zz_generated.deepcopy.go b/common/zz_generated.deepcopy.go index 0a2049de1..88bed28ba 100644 --- a/common/zz_generated.deepcopy.go +++ b/common/zz_generated.deepcopy.go @@ -30,31 +30,6 @@ import ( func (in *BaseComponentProbe) DeepCopyInto(out *BaseComponentProbe) { *out = *in in.BaseComponentProbeHandler.DeepCopyInto(&out.BaseComponentProbeHandler) - if in.InitialDelaySeconds != nil { - in, out := &in.InitialDelaySeconds, &out.InitialDelaySeconds - *out = new(int32) - **out = **in - } - if in.TimeoutSeconds != nil { - in, out := &in.TimeoutSeconds, &out.TimeoutSeconds - *out = new(int32) - **out = **in - } - if in.PeriodSeconds != nil { - in, out := &in.PeriodSeconds, &out.PeriodSeconds - *out = new(int32) - **out = **in - } - if in.SuccessThreshold != nil { - in, out := &in.SuccessThreshold, &out.SuccessThreshold - *out = new(int32) - **out = **in - } - if in.FailureThreshold != nil { - in, out := &in.FailureThreshold, &out.FailureThreshold - *out = new(int32) - **out = **in - } if in.TerminationGracePeriodSeconds != nil { in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds *out = new(int64) diff --git a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml index e3ed73aa5..c01dc48a1 100644 --- a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml +++ b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml @@ -3062,7 +3062,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - nil. + 3. Minimum value is 1. format: int32 type: integer grpc: @@ -3135,13 +3135,14 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Defaults to nil. + Default to 10 seconds. Minimum value is 1. format: int32 type: integer successThreshold: description: Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to - nil. + 1. Must be 1 for liveness and startup. Minimum value is + 1. format: int32 type: integer tcpSocket: @@ -3176,12 +3177,14 @@ spec: 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. - Defaults to nil + Minimum value is 1. spec.terminationGracePeriodSeconds is + used if unset. format: int64 type: integer timeoutSeconds: description: 'Number of seconds after which the probe times - out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + out. Defaults to 1 second. Minimum value is 1. More info: + https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -3208,7 +3211,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - nil. + 3. Minimum value is 1. format: int32 type: integer grpc: @@ -3281,13 +3284,14 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Defaults to nil. + Default to 10 seconds. Minimum value is 1. format: int32 type: integer successThreshold: description: Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to - nil. + 1. Must be 1 for liveness and startup. Minimum value is + 1. format: int32 type: integer tcpSocket: @@ -3322,12 +3326,14 @@ spec: 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. - Defaults to nil + Minimum value is 1. spec.terminationGracePeriodSeconds is + used if unset. format: int64 type: integer timeoutSeconds: description: 'Number of seconds after which the probe times - out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + out. Defaults to 1 second. Minimum value is 1. More info: + https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -3355,7 +3361,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - nil. + 3. Minimum value is 1. format: int32 type: integer grpc: @@ -3428,13 +3434,14 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Defaults to nil. + Default to 10 seconds. Minimum value is 1. format: int32 type: integer successThreshold: description: Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to - nil. + 1. Must be 1 for liveness and startup. Minimum value is + 1. format: int32 type: integer tcpSocket: @@ -3469,12 +3476,14 @@ spec: 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. - Defaults to nil + Minimum value is 1. spec.terminationGracePeriodSeconds is + used if unset. format: int64 type: integer timeoutSeconds: description: 'Number of seconds after which the probe times - out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + out. Defaults to 1 second. Minimum value is 1. More info: + https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -10417,7 +10426,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - nil. + 3. Minimum value is 1. format: int32 type: integer grpc: @@ -10490,13 +10499,14 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Defaults to nil. + Default to 10 seconds. Minimum value is 1. format: int32 type: integer successThreshold: description: Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to - nil. + 1. Must be 1 for liveness and startup. Minimum value is + 1. format: int32 type: integer tcpSocket: @@ -10531,12 +10541,14 @@ spec: 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. - Defaults to nil + Minimum value is 1. spec.terminationGracePeriodSeconds is + used if unset. format: int64 type: integer timeoutSeconds: description: 'Number of seconds after which the probe times - out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + out. Defaults to 1 second. Minimum value is 1. More info: + https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -10563,7 +10575,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - nil. + 3. Minimum value is 1. format: int32 type: integer grpc: @@ -10636,13 +10648,14 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Defaults to nil. + Default to 10 seconds. Minimum value is 1. format: int32 type: integer successThreshold: description: Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to - nil. + 1. Must be 1 for liveness and startup. Minimum value is + 1. format: int32 type: integer tcpSocket: @@ -10677,12 +10690,14 @@ spec: 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. - Defaults to nil + Minimum value is 1. spec.terminationGracePeriodSeconds is + used if unset. format: int64 type: integer timeoutSeconds: description: 'Number of seconds after which the probe times - out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + out. Defaults to 1 second. Minimum value is 1. More info: + https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object @@ -10710,7 +10725,7 @@ spec: failureThreshold: description: Minimum consecutive failures for the probe to be considered failed after having succeeded. Defaults to - nil. + 3. Minimum value is 1. format: int32 type: integer grpc: @@ -10783,13 +10798,14 @@ spec: type: integer periodSeconds: description: How often (in seconds) to perform the probe. - Defaults to nil. + Default to 10 seconds. Minimum value is 1. format: int32 type: integer successThreshold: description: Minimum consecutive successes for the probe to be considered successful after having failed. Defaults to - nil. + 1. Must be 1 for liveness and startup. Minimum value is + 1. format: int32 type: integer tcpSocket: @@ -10824,12 +10840,14 @@ spec: 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. - Defaults to nil + Minimum value is 1. spec.terminationGracePeriodSeconds is + used if unset. format: int64 type: integer timeoutSeconds: description: 'Number of seconds after which the probe times - out. Defaults to nil. More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' + out. Defaults to 1 second. Minimum value is 1. More info: + https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes' format: int32 type: integer type: object diff --git a/internal/deploy/kubectl/runtime-component-crd.yaml b/internal/deploy/kubectl/runtime-component-crd.yaml index 73483ecaf..9dd88d948 100644 --- a/internal/deploy/kubectl/runtime-component-crd.yaml +++ b/internal/deploy/kubectl/runtime-component-crd.yaml @@ -3129,8 +3129,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -3280,8 +3278,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -3432,8 +3428,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10499,8 +10493,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10650,8 +10642,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10802,8 +10792,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started diff --git a/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml b/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml index 73483ecaf..9dd88d948 100644 --- a/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml +++ b/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml @@ -3129,8 +3129,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -3280,8 +3278,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -3432,8 +3428,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10499,8 +10493,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10650,8 +10642,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10802,8 +10792,6 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string - required: - - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started diff --git a/utils/utils.go b/utils/utils.go index 4e5c63508..50e6a6da0 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -357,25 +357,12 @@ func ConvertToCoreProbe(ba common.BaseComponent, baseProbe *common.BaseComponent if baseProbe.BaseComponentProbeHandler.GRPC != nil { probe.ProbeHandler.GRPC = baseProbe.BaseComponentProbeHandler.GRPC } - - if baseProbe.InitialDelaySeconds != nil && *baseProbe.InitialDelaySeconds != 0 { - probe.InitialDelaySeconds = *baseProbe.InitialDelaySeconds - } - if baseProbe.TimeoutSeconds != nil && *baseProbe.TimeoutSeconds != 0 { - probe.TimeoutSeconds = *baseProbe.TimeoutSeconds - } - if baseProbe.PeriodSeconds != nil && *baseProbe.PeriodSeconds != 0 { - probe.PeriodSeconds = *baseProbe.PeriodSeconds - } - if baseProbe.SuccessThreshold != nil && *baseProbe.SuccessThreshold != 0 { - probe.SuccessThreshold = *baseProbe.SuccessThreshold - } - if baseProbe.FailureThreshold != nil && *baseProbe.FailureThreshold != 0 { - probe.FailureThreshold = *baseProbe.FailureThreshold - } - if baseProbe.TerminationGracePeriodSeconds != nil && *baseProbe.TerminationGracePeriodSeconds != 0 { - probe.TerminationGracePeriodSeconds = baseProbe.TerminationGracePeriodSeconds - } + probe.InitialDelaySeconds = baseProbe.InitialDelaySeconds + probe.TimeoutSeconds = baseProbe.TimeoutSeconds + probe.PeriodSeconds = baseProbe.PeriodSeconds + probe.SuccessThreshold = baseProbe.SuccessThreshold + probe.FailureThreshold = baseProbe.FailureThreshold + probe.TerminationGracePeriodSeconds = baseProbe.TerminationGracePeriodSeconds } return probe } @@ -395,21 +382,11 @@ func customizeProbeDefaults(config *common.BaseComponentProbe, defaultProbe *com if config.BaseComponentProbeHandler.GRPC != nil { probe.BaseComponentProbeHandler.GRPC = config.BaseComponentProbeHandler.GRPC } - if config.InitialDelaySeconds != nil && *config.InitialDelaySeconds != 0 { - probe.InitialDelaySeconds = config.InitialDelaySeconds - } - if config.TimeoutSeconds != nil && *config.TimeoutSeconds != 0 { - probe.TimeoutSeconds = config.TimeoutSeconds - } - if config.PeriodSeconds != nil && *config.PeriodSeconds != 0 { - probe.PeriodSeconds = config.PeriodSeconds - } - if config.SuccessThreshold != nil && *config.SuccessThreshold != 0 { - probe.SuccessThreshold = config.SuccessThreshold - } - if config.FailureThreshold != nil && *config.FailureThreshold != 0 { - probe.FailureThreshold = config.FailureThreshold - } + probe.InitialDelaySeconds = config.InitialDelaySeconds + probe.TimeoutSeconds = config.TimeoutSeconds + probe.PeriodSeconds = config.PeriodSeconds + probe.SuccessThreshold = config.SuccessThreshold + probe.FailureThreshold = config.FailureThreshold } return probe } From f30075a31b54f36c1a05457e785baf87c0616b79 Mon Sep 17 00:00:00 2001 From: Kirby Chin <37311900+kabicin@users.noreply.github.com> Date: Mon, 22 Apr 2024 17:02:23 -0400 Subject: [PATCH 15/25] Update utils.go --- utils/utils.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 50e6a6da0..35bb5031b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -382,11 +382,21 @@ func customizeProbeDefaults(config *common.BaseComponentProbe, defaultProbe *com if config.BaseComponentProbeHandler.GRPC != nil { probe.BaseComponentProbeHandler.GRPC = config.BaseComponentProbeHandler.GRPC } - probe.InitialDelaySeconds = config.InitialDelaySeconds - probe.TimeoutSeconds = config.TimeoutSeconds - probe.PeriodSeconds = config.PeriodSeconds - probe.SuccessThreshold = config.SuccessThreshold - probe.FailureThreshold = config.FailureThreshold + if config.InitialDelaySeconds != 0 { + probe.InitialDelaySeconds = config.InitialDelaySeconds + } + if config.TimeoutSeconds != 0 { + probe.TimeoutSeconds = config.TimeoutSeconds + } + if config.PeriodSeconds != 0 { + probe.PeriodSeconds = config.PeriodSeconds + } + if config.SuccessThreshold != 0 { + probe.SuccessThreshold = config.SuccessThreshold + } + if config.FailureThreshold != 0 { + probe.FailureThreshold = config.FailureThreshold + } } return probe } From f3350c990e4e818eca2b2d3a80fbb1ed8ed42ded Mon Sep 17 00:00:00 2001 From: Kirby Chin <37311900+kabicin@users.noreply.github.com> Date: Wed, 24 Apr 2024 13:30:46 -0400 Subject: [PATCH 16/25] Resolve incorrect default value for optionalHTTPGetAction.Scheme and fix manageTLS to true by default when setting scheme to HTTPS --- utils/utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index e6917c70f..342ae5530 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -330,10 +330,10 @@ func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optio return nil } - if optionalHTTPGetAction.Scheme != corev1.URISchemeHTTP { + if optionalHTTPGetAction.Scheme != "" { httpGetAction.Scheme = optionalHTTPGetAction.Scheme } else { - if ba.GetManageTLS() != nil && *ba.GetManageTLS() { + if ba.GetManageTLS() == nil || *ba.GetManageTLS() { httpGetAction.Scheme = corev1.URISchemeHTTPS } else { httpGetAction.Scheme = corev1.URISchemeHTTP From 0153a316dd6847ba73dbec202005ad62b036deee Mon Sep 17 00:00:00 2001 From: Kirby Chin <37311900+kabicin@users.noreply.github.com> Date: Wed, 24 Apr 2024 18:08:43 -0400 Subject: [PATCH 17/25] Don't make manageTLS affect httpGet.scheme --- utils/utils.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 342ae5530..31c44c4ff 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -333,11 +333,7 @@ func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optio if optionalHTTPGetAction.Scheme != "" { httpGetAction.Scheme = optionalHTTPGetAction.Scheme } else { - if ba.GetManageTLS() == nil || *ba.GetManageTLS() { - httpGetAction.Scheme = corev1.URISchemeHTTPS - } else { - httpGetAction.Scheme = corev1.URISchemeHTTP - } + httpGetAction.Scheme = corev1.URISchemeHTTP } } return httpGetAction From 0547cc1421f8c7ed1560d88d55fff54e51f36cd4 Mon Sep 17 00:00:00 2001 From: Kirby Chin <37311900+kabicin@users.noreply.github.com> Date: Fri, 10 May 2024 10:30:01 -0400 Subject: [PATCH 18/25] Revert v1beta2 probe changes --- api/v1beta2/runtimecomponent_types.go | 36 +++++-------------- api/v1beta2/zz_generated.deepcopy.go | 7 ++-- .../rc.app.stacks_runtimecomponents.yaml | 6 ++++ ...ntime-component.clusterserviceversion.yaml | 2 +- .../rc.app.stacks_runtimecomponents.yaml | 6 ++++ .../deploy/kubectl/runtime-component-crd.yaml | 6 ++++ .../daily/base/runtime-component-crd.yaml | 6 ++++ 7 files changed, 37 insertions(+), 32 deletions(-) diff --git a/api/v1beta2/runtimecomponent_types.go b/api/v1beta2/runtimecomponent_types.go index ee579c7c5..f18249215 100644 --- a/api/v1beta2/runtimecomponent_types.go +++ b/api/v1beta2/runtimecomponent_types.go @@ -136,45 +136,27 @@ type RuntimeComponentSpec 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 *common.BaseComponentProbe `json:"liveness,omitempty"` + Liveness *corev1.Probe `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 *common.BaseComponentProbe `json:"readiness,omitempty"` + Readiness *corev1.Probe `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 *common.BaseComponentProbe `json:"startup,omitempty"` + Startup *corev1.Probe `json:"startup,omitempty"` } -// PatchLivenessProbe updates values for and returns the liveness probe -func (p *RuntimeComponentProbes) PatchLivenessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { - return probe -} - -// PatchReadinessProbe updates values for and returns the readiness probe -func (p *RuntimeComponentProbes) PatchReadinessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { - return probe -} - -// PatchStartupProbe updates values for and returns the startup probe -func (p *RuntimeComponentProbes) PatchStartupProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { - return probe -} - -// GetDefaultLivenessProbe returns default values for liveness probe -func (in *RuntimeComponentProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *common.BaseComponentProbe { +func (in *RuntimeComponentProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *corev1.Probe { return nil } -// GetDefaultReadinessProbe returns default values for readiness probe -func (in *RuntimeComponentProbes) GetDefaultReadinessProbe(ba common.BaseComponent) *common.BaseComponentProbe { +func (in *RuntimeComponentProbes) GetDefaultReadinessProbe(ba common.BaseComponent) *corev1.Probe { return nil } -// GetDefaultStartupProbe returns default values for startup probe -func (in *RuntimeComponentProbes) GetDefaultStartupProbe(ba common.BaseComponent) *common.BaseComponentProbe { +func (in *RuntimeComponentProbes) GetDefaultStartupProbe(ba common.BaseComponent) *corev1.Probe { return nil } @@ -486,17 +468,17 @@ func (cr *RuntimeComponent) GetProbes() common.BaseComponentProbes { } // GetLivenessProbe returns liveness probe -func (p *RuntimeComponentProbes) GetLivenessProbe() *common.BaseComponentProbe { +func (p *RuntimeComponentProbes) GetLivenessProbe() *corev1.Probe { return p.Liveness } // GetReadinessProbe returns readiness probe -func (p *RuntimeComponentProbes) GetReadinessProbe() *common.BaseComponentProbe { +func (p *RuntimeComponentProbes) GetReadinessProbe() *corev1.Probe { return p.Readiness } // GetStartupProbe returns startup probe -func (p *RuntimeComponentProbes) GetStartupProbe() *common.BaseComponentProbe { +func (p *RuntimeComponentProbes) GetStartupProbe() *corev1.Probe { return p.Startup } diff --git a/api/v1beta2/zz_generated.deepcopy.go b/api/v1beta2/zz_generated.deepcopy.go index 75a000523..092e14d8f 100644 --- a/api/v1beta2/zz_generated.deepcopy.go +++ b/api/v1beta2/zz_generated.deepcopy.go @@ -22,7 +22,6 @@ limitations under the License. package v1beta2 import ( - "github.com/application-stacks/runtime-component-operator/common" routev1 "github.com/openshift/api/route/v1" monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" appsv1 "k8s.io/api/apps/v1" @@ -237,17 +236,17 @@ func (in *RuntimeComponentProbes) DeepCopyInto(out *RuntimeComponentProbes) { *out = *in if in.Liveness != nil { in, out := &in.Liveness, &out.Liveness - *out = new(common.BaseComponentProbe) + *out = new(v1.Probe) (*in).DeepCopyInto(*out) } if in.Readiness != nil { in, out := &in.Readiness, &out.Readiness - *out = new(common.BaseComponentProbe) + *out = new(v1.Probe) (*in).DeepCopyInto(*out) } if in.Startup != nil { in, out := &in.Startup, &out.Startup - *out = new(common.BaseComponentProbe) + *out = new(v1.Probe) (*in).DeepCopyInto(*out) } } diff --git a/bundle/manifests/rc.app.stacks_runtimecomponents.yaml b/bundle/manifests/rc.app.stacks_runtimecomponents.yaml index 8031ea0a5..906083e8d 100644 --- a/bundle/manifests/rc.app.stacks_runtimecomponents.yaml +++ b/bundle/manifests/rc.app.stacks_runtimecomponents.yaml @@ -10513,6 +10513,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10662,6 +10664,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10812,6 +10816,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started diff --git a/bundle/manifests/runtime-component.clusterserviceversion.yaml b/bundle/manifests/runtime-component.clusterserviceversion.yaml index 0a9cae7b4..c57ee37b1 100644 --- a/bundle/manifests/runtime-component.clusterserviceversion.yaml +++ b/bundle/manifests/runtime-component.clusterserviceversion.yaml @@ -71,7 +71,7 @@ metadata: categories: Application Runtime certified: "true" containerImage: icr.io/appcafe/runtime-component-operator:daily - createdAt: "2024-05-07T20:25:49Z" + createdAt: "2024-05-10T14:28:02Z" description: Deploys any runtime component with dynamic and auto-tuning configuration olm.skipRange: '>=0.8.0 <1.3.2' operators.openshift.io/infrastructure-features: '["disconnected"]' diff --git a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml index 9c193d7f5..52f8fd009 100644 --- a/config/crd/bases/rc.app.stacks_runtimecomponents.yaml +++ b/config/crd/bases/rc.app.stacks_runtimecomponents.yaml @@ -10509,6 +10509,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10658,6 +10660,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10808,6 +10812,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started diff --git a/internal/deploy/kubectl/runtime-component-crd.yaml b/internal/deploy/kubectl/runtime-component-crd.yaml index 7bb0f290a..149fce52f 100644 --- a/internal/deploy/kubectl/runtime-component-crd.yaml +++ b/internal/deploy/kubectl/runtime-component-crd.yaml @@ -10512,6 +10512,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10661,6 +10663,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10811,6 +10815,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started diff --git a/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml b/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml index 7bb0f290a..149fce52f 100644 --- a/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml +++ b/internal/deploy/kustomize/daily/base/runtime-component-crd.yaml @@ -10512,6 +10512,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10661,6 +10663,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started @@ -10811,6 +10815,8 @@ spec: description: Scheme to use for connecting to the host. Defaults to HTTP. type: string + required: + - port type: object initialDelaySeconds: description: 'Number of seconds after the container has started From 2c99928be9853dc154da42858553ebd605d5f2f1 Mon Sep 17 00:00:00 2001 From: kabicin <37311900+kabicin@users.noreply.github.com> Date: Fri, 10 May 2024 14:50:45 -0400 Subject: [PATCH 19/25] Use MicroProfile probe defaults and set scheme based on manageTLS --- .../runtime-component.clusterserviceversion.yaml | 2 +- utils/utils.go | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bundle/manifests/runtime-component.clusterserviceversion.yaml b/bundle/manifests/runtime-component.clusterserviceversion.yaml index 0a9cae7b4..39a618c22 100644 --- a/bundle/manifests/runtime-component.clusterserviceversion.yaml +++ b/bundle/manifests/runtime-component.clusterserviceversion.yaml @@ -71,7 +71,7 @@ metadata: categories: Application Runtime certified: "true" containerImage: icr.io/appcafe/runtime-component-operator:daily - createdAt: "2024-05-07T20:25:49Z" + createdAt: "2024-05-10T18:40:55Z" description: Deploys any runtime component with dynamic and auto-tuning configuration olm.skipRange: '>=0.8.0 <1.3.2' operators.openshift.io/infrastructure-features: '["disconnected"]' diff --git a/utils/utils.go b/utils/utils.go index cc3a537a1..7c953c80d 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -299,12 +299,7 @@ func customizeProbe(config *common.BaseComponentProbe, getDefaultProbeCallback f return nil } - // Probe handler is defined in config so use probe as is - if config.BaseComponentProbeHandler != (common.BaseComponentProbeHandler{}) { - return ConvertToCoreProbe(ba, patchProbeCallback(ba, config)) - } - - // Probe handler is not defined so use default values for the probe if values not set in probe config + // Always use MicroProfile default values for the probe return ConvertToCoreProbe(ba, patchProbeCallback(ba, customizeProbeDefaults(config, getDefaultProbeCallback(ba)))) } @@ -332,7 +327,15 @@ func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optio if optionalHTTPGetAction.Scheme != "" { httpGetAction.Scheme = optionalHTTPGetAction.Scheme + } else if httpGetAction.Port.IntValue() == int(ba.GetService().GetPort()) { + // If .spec.service.port matches the configured probe port, set the scheme based on the .spec.manageTLS flag + if ba.GetManageTLS() == nil || *ba.GetManageTLS() { + httpGetAction.Scheme = corev1.URISchemeHTTPS + } else { + httpGetAction.Scheme = corev1.URISchemeHTTP + } } else { + // Otherwise, use the Kubernetes default scheme httpGetAction.Scheme = corev1.URISchemeHTTP } } From eeecf5f626c9dfa3a154d68e0e04255fcc0500c3 Mon Sep 17 00:00:00 2001 From: kabicin <37311900+kabicin@users.noreply.github.com> Date: Tue, 14 May 2024 09:50:13 -0400 Subject: [PATCH 20/25] Add common_v1beta2 for v1beta2 API to use deprecated Probes interface --- api/v1beta2/runtimecomponent_types.go | 2 +- ...ntime-component.clusterserviceversion.yaml | 2 +- common_v1beta2/common.go | 61 +++++ common_v1beta2/config.go | 43 ++++ common_v1beta2/types.go | 236 ++++++++++++++++++ 5 files changed, 342 insertions(+), 2 deletions(-) create mode 100644 common_v1beta2/common.go create mode 100644 common_v1beta2/config.go create mode 100644 common_v1beta2/types.go diff --git a/api/v1beta2/runtimecomponent_types.go b/api/v1beta2/runtimecomponent_types.go index f18249215..7ab0c0116 100644 --- a/api/v1beta2/runtimecomponent_types.go +++ b/api/v1beta2/runtimecomponent_types.go @@ -19,7 +19,7 @@ package v1beta2 import ( "time" - "github.com/application-stacks/runtime-component-operator/common" + common "github.com/application-stacks/runtime-component-operator/common_v1beta2" routev1 "github.com/openshift/api/route/v1" prometheusv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" appsv1 "k8s.io/api/apps/v1" diff --git a/bundle/manifests/runtime-component.clusterserviceversion.yaml b/bundle/manifests/runtime-component.clusterserviceversion.yaml index 39a618c22..2796401e0 100644 --- a/bundle/manifests/runtime-component.clusterserviceversion.yaml +++ b/bundle/manifests/runtime-component.clusterserviceversion.yaml @@ -71,7 +71,7 @@ metadata: categories: Application Runtime certified: "true" containerImage: icr.io/appcafe/runtime-component-operator:daily - createdAt: "2024-05-10T18:40:55Z" + createdAt: "2024-05-14T13:44:12Z" description: Deploys any runtime component with dynamic and auto-tuning configuration olm.skipRange: '>=0.8.0 <1.3.2' operators.openshift.io/infrastructure-features: '["disconnected"]' diff --git a/common_v1beta2/common.go b/common_v1beta2/common.go new file mode 100644 index 000000000..f28400ffe --- /dev/null +++ b/common_v1beta2/common.go @@ -0,0 +1,61 @@ +package common_v1beta2 + +import ( + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +// GetDefaultMicroProfileStartupProbe returns the default values for MicroProfile Health-based startup probe. +func GetDefaultMicroProfileStartupProbeV1Beta2(ba BaseComponent) *corev1.Probe { + return &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/health/started", + Port: intstr.FromInt(int(ba.GetService().GetPort())), + Scheme: "HTTPS", + }, + }, + PeriodSeconds: 10, + TimeoutSeconds: 2, + FailureThreshold: 20, + } +} + +// GetDefaultMicroProfileReadinessProbe returns the default values for MicroProfile Health-based readiness probe. +func GetDefaultMicroProfileReadinessProbeV1Beta2(ba BaseComponent) *corev1.Probe { + return &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/health/ready", + Port: intstr.FromInt(int(ba.GetService().GetPort())), + Scheme: "HTTPS", + }, + }, + InitialDelaySeconds: 10, + PeriodSeconds: 10, + TimeoutSeconds: 2, + FailureThreshold: 10, + } +} + +// GetDefaultMicroProfileLivenessProbe returns the default values for MicroProfile Health-based liveness probe. +func GetDefaultMicroProfileLivenessProbeV1Beta2(ba BaseComponent) *corev1.Probe { + return &corev1.Probe{ + ProbeHandler: corev1.ProbeHandler{ + HTTPGet: &corev1.HTTPGetAction{ + Path: "/health/live", + Port: intstr.FromInt(int(ba.GetService().GetPort())), + Scheme: "HTTPS", + }, + }, + InitialDelaySeconds: 60, + PeriodSeconds: 10, + TimeoutSeconds: 2, + FailureThreshold: 3, + } +} + +// GetComponentNameLabel returns the component's name label. +func GetComponentNameLabel(ba BaseComponent) string { + return ba.GetGroupName() + "/name" +} diff --git a/common_v1beta2/config.go b/common_v1beta2/config.go new file mode 100644 index 000000000..b54497637 --- /dev/null +++ b/common_v1beta2/config.go @@ -0,0 +1,43 @@ +package common_v1beta2 + +import ( + corev1 "k8s.io/api/core/v1" +) + +// OpConfig stored operator configuration +type OpConfig map[string]string + +const ( + + // OpConfigDefaultHostname a DNS name to be used for hostname generation. + OpConfigDefaultHostname = "defaultHostname" + + // OpConfigCMCADuration default duration for cert-manager issued CA + OpConfigCMCADuration = "certManagerCACertDuration" + + // OpConfigCMCADuration default duration for cert-manager issued service certificate + OpConfigCMCertDuration = "certManagerCertDuration" +) + +// Config stores operator configuration +var Config = OpConfig{} + +// LoadFromConfigMap creates a config out of kubernetes config map +func (oc OpConfig) LoadFromConfigMap(cm *corev1.ConfigMap) { + for k, v := range DefaultOpConfig() { + oc[k] = v + } + + for k, v := range cm.Data { + oc[k] = v + } +} + +// DefaultOpConfig returns default configuration +func DefaultOpConfig() OpConfig { + cfg := OpConfig{} + cfg[OpConfigDefaultHostname] = "" + cfg[OpConfigCMCADuration] = "8766h" + cfg[OpConfigCMCertDuration] = "2160h" + return cfg +} diff --git a/common_v1beta2/types.go b/common_v1beta2/types.go new file mode 100644 index 000000000..f397dc1cf --- /dev/null +++ b/common_v1beta2/types.go @@ -0,0 +1,236 @@ +package common_v1beta2 + +import ( + routev1 "github.com/openshift/api/route/v1" + prometheusv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// StatusConditionType ... +type StatusConditionType string + +// StatusEndpointScope ... +type StatusEndpointScope string + +type StatusReferences map[string]string + +const ( + StatusReferenceCertSecretName = "svcCertSecretName" + StatusReferencePullSecretName = "saPullSecretName" + StatusReferenceSAResourceVersion = "saResourceVersion" + StatusReferenceRouteHost = "routeHost" +) + +// StatusCondition ... +type StatusCondition interface { + GetLastTransitionTime() *metav1.Time + SetLastTransitionTime(*metav1.Time) + + GetReason() string + SetReason(string) + + GetMessage() string + SetMessage(string) + + GetStatus() corev1.ConditionStatus + SetStatus(corev1.ConditionStatus) + + GetType() StatusConditionType + SetType(StatusConditionType) + + SetConditionFields(string, string, corev1.ConditionStatus) StatusCondition +} + +// StatusEndpoint ... +type StatusEndpoint interface { + GetEndpointName() string + SetEndpointName(string) + + GetEndpointScope() StatusEndpointScope + SetEndpointScope(StatusEndpointScope) + + GetEndpointType() string + SetEndpointType(string) + + GetEndpointUri() string + SetEndpointUri(string) + + SetStatusEndpointFields(StatusEndpointScope, string, string) StatusEndpoint +} + +// BaseComponentStatus returns base appplication status +type BaseComponentStatus interface { + GetConditions() []StatusCondition + GetCondition(StatusConditionType) StatusCondition + SetCondition(StatusCondition) + UnsetCondition(StatusCondition) + NewCondition(StatusConditionType) StatusCondition + + GetStatusEndpoint(string) StatusEndpoint + SetStatusEndpoint(StatusEndpoint) + NewStatusEndpoint(string) StatusEndpoint + RemoveStatusEndpoint(string) + + GetImageReference() string + SetImageReference(string) + + GetBinding() *corev1.LocalObjectReference + SetBinding(*corev1.LocalObjectReference) + + GetReferences() StatusReferences + SetReferences(StatusReferences) + SetReference(string, string) +} + +const ( + // Status Condition Types + StatusConditionTypeReconciled StatusConditionType = "Reconciled" + StatusConditionTypeResourcesReady StatusConditionType = "ResourcesReady" + StatusConditionTypeReady StatusConditionType = "Ready" + StatusConditionTypeWarning StatusConditionType = "Warning" + + // Status Condition Type Messages + StatusConditionTypeReadyMessage string = "Application is reconciled and resources are ready." + + // Status Endpoint Scopes + StatusEndpointScopeExternal StatusEndpointScope = "External" + StatusEndpointScopeInternal StatusEndpointScope = "Internal" +) + +// BaseComponentAutoscaling represents basic HPA configuration +type BaseComponentAutoscaling interface { + GetMinReplicas() *int32 + GetMaxReplicas() int32 + GetTargetCPUUtilizationPercentage() *int32 +} + +// BaseComponentStorage represents basic PVC configuration +type BaseComponentStorage interface { + GetSize() string + GetClassName() string + GetMountPath() string + GetVolumeClaimTemplate() *corev1.PersistentVolumeClaim +} + +// BaseComponentService represents basic service configuration +type BaseComponentService interface { + GetPort() int32 + GetTargetPort() *int32 + GetPortName() string + GetType() *corev1.ServiceType + GetNodePort() *int32 + GetPorts() []corev1.ServicePort + GetAnnotations() map[string]string + GetCertificateSecretRef() *string + GetCertificate() BaseComponentCertificate + GetBindable() *bool +} +type BaseComponentCertificate interface { + GetAnnotations() map[string]string +} + +// BaseComponentNetworkPolicy represents a basic network policy configuration +type BaseComponentNetworkPolicy interface { + GetNamespaceLabels() map[string]string + GetFromLabels() map[string]string +} + +// BaseComponentMonitoring represents basic service monitoring configuration +type BaseComponentMonitoring interface { + GetLabels() map[string]string + GetEndpoints() []prometheusv1.Endpoint +} + +// BaseComponentRoute represents route configuration +type BaseComponentRoute interface { + GetTermination() *routev1.TLSTerminationType + GetInsecureEdgeTerminationPolicy() *routev1.InsecureEdgeTerminationPolicyType + GetAnnotations() map[string]string + GetHost() string + GetPath() string + GetPathType() networkingv1.PathType + GetCertificateSecretRef() *string +} + +// BaseComponentAffinity describes deployment and pod affinity +type BaseComponentAffinity interface { + GetNodeAffinity() *corev1.NodeAffinity + GetPodAffinity() *corev1.PodAffinity + GetPodAntiAffinity() *corev1.PodAntiAffinity + GetArchitecture() []string + GetNodeAffinityLabels() map[string]string +} + +// BaseComponentDeployment describes deployment +type BaseComponentDeployment interface { + GetDeploymentUpdateStrategy() *appsv1.DeploymentStrategy + GetAnnotations() map[string]string +} + +// BaseComponentStatefulSet describes deployment +type BaseComponentStatefulSet interface { + GetStatefulSetUpdateStrategy() *appsv1.StatefulSetUpdateStrategy + GetStorage() BaseComponentStorage + GetAnnotations() map[string]string +} + +// BaseComponentProbes describes the probes for application container +type BaseComponentProbes interface { + GetLivenessProbe() *corev1.Probe + GetReadinessProbe() *corev1.Probe + GetStartupProbe() *corev1.Probe + + GetDefaultLivenessProbe(ba BaseComponent) *corev1.Probe + GetDefaultReadinessProbe(ba BaseComponent) *corev1.Probe + GetDefaultStartupProbe(ba BaseComponent) *corev1.Probe +} + +type BaseComponentServiceAccount interface { + GetMountToken() *bool + GetName() *string +} + +type BaseComponentTopologySpreadConstraints interface { + GetConstraints() *[]corev1.TopologySpreadConstraint + GetDisableOperatorDefaults() *bool +} + +// BaseComponent represents basic kubernetes application +type BaseComponent interface { + GetApplicationImage() string + GetPullPolicy() *corev1.PullPolicy + GetPullSecret() *string + GetServiceAccountName() *string + GetServiceAccount() BaseComponentServiceAccount + GetReplicas() *int32 + GetProbes() BaseComponentProbes + GetVolumes() []corev1.Volume + GetVolumeMounts() []corev1.VolumeMount + GetResourceConstraints() *corev1.ResourceRequirements + GetExpose() *bool + GetEnv() []corev1.EnvVar + GetEnvFrom() []corev1.EnvFromSource + GetCreateKnativeService() *bool + GetAutoscaling() BaseComponentAutoscaling + GetService() BaseComponentService + GetNetworkPolicy() BaseComponentNetworkPolicy + GetDeployment() BaseComponentDeployment + GetStatefulSet() BaseComponentStatefulSet + GetApplicationVersion() string + GetApplicationName() string + GetMonitoring() BaseComponentMonitoring + GetLabels() map[string]string + GetAnnotations() map[string]string + GetStatus() BaseComponentStatus + GetInitContainers() []corev1.Container + GetSidecarContainers() []corev1.Container + GetGroupName() string + GetRoute() BaseComponentRoute + GetAffinity() BaseComponentAffinity + GetTopologySpreadConstraints() BaseComponentTopologySpreadConstraints + GetSecurityContext() *corev1.SecurityContext + GetManageTLS() *bool +} From 812d07575e8c9a1179c7486f269edf8598a67e38 Mon Sep 17 00:00:00 2001 From: kabicin <37311900+kabicin@users.noreply.github.com> Date: Tue, 14 May 2024 09:55:33 -0400 Subject: [PATCH 21/25] Remove unused common components from v1beta2 --- ...ntime-component.clusterserviceversion.yaml | 2 +- common_v1beta2/common.go | 61 ------------------- common_v1beta2/config.go | 43 ------------- 3 files changed, 1 insertion(+), 105 deletions(-) delete mode 100644 common_v1beta2/common.go delete mode 100644 common_v1beta2/config.go diff --git a/bundle/manifests/runtime-component.clusterserviceversion.yaml b/bundle/manifests/runtime-component.clusterserviceversion.yaml index 2796401e0..ce9ffe002 100644 --- a/bundle/manifests/runtime-component.clusterserviceversion.yaml +++ b/bundle/manifests/runtime-component.clusterserviceversion.yaml @@ -71,7 +71,7 @@ metadata: categories: Application Runtime certified: "true" containerImage: icr.io/appcafe/runtime-component-operator:daily - createdAt: "2024-05-14T13:44:12Z" + createdAt: "2024-05-14T13:54:13Z" description: Deploys any runtime component with dynamic and auto-tuning configuration olm.skipRange: '>=0.8.0 <1.3.2' operators.openshift.io/infrastructure-features: '["disconnected"]' diff --git a/common_v1beta2/common.go b/common_v1beta2/common.go deleted file mode 100644 index f28400ffe..000000000 --- a/common_v1beta2/common.go +++ /dev/null @@ -1,61 +0,0 @@ -package common_v1beta2 - -import ( - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/util/intstr" -) - -// GetDefaultMicroProfileStartupProbe returns the default values for MicroProfile Health-based startup probe. -func GetDefaultMicroProfileStartupProbeV1Beta2(ba BaseComponent) *corev1.Probe { - return &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Path: "/health/started", - Port: intstr.FromInt(int(ba.GetService().GetPort())), - Scheme: "HTTPS", - }, - }, - PeriodSeconds: 10, - TimeoutSeconds: 2, - FailureThreshold: 20, - } -} - -// GetDefaultMicroProfileReadinessProbe returns the default values for MicroProfile Health-based readiness probe. -func GetDefaultMicroProfileReadinessProbeV1Beta2(ba BaseComponent) *corev1.Probe { - return &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Path: "/health/ready", - Port: intstr.FromInt(int(ba.GetService().GetPort())), - Scheme: "HTTPS", - }, - }, - InitialDelaySeconds: 10, - PeriodSeconds: 10, - TimeoutSeconds: 2, - FailureThreshold: 10, - } -} - -// GetDefaultMicroProfileLivenessProbe returns the default values for MicroProfile Health-based liveness probe. -func GetDefaultMicroProfileLivenessProbeV1Beta2(ba BaseComponent) *corev1.Probe { - return &corev1.Probe{ - ProbeHandler: corev1.ProbeHandler{ - HTTPGet: &corev1.HTTPGetAction{ - Path: "/health/live", - Port: intstr.FromInt(int(ba.GetService().GetPort())), - Scheme: "HTTPS", - }, - }, - InitialDelaySeconds: 60, - PeriodSeconds: 10, - TimeoutSeconds: 2, - FailureThreshold: 3, - } -} - -// GetComponentNameLabel returns the component's name label. -func GetComponentNameLabel(ba BaseComponent) string { - return ba.GetGroupName() + "/name" -} diff --git a/common_v1beta2/config.go b/common_v1beta2/config.go deleted file mode 100644 index b54497637..000000000 --- a/common_v1beta2/config.go +++ /dev/null @@ -1,43 +0,0 @@ -package common_v1beta2 - -import ( - corev1 "k8s.io/api/core/v1" -) - -// OpConfig stored operator configuration -type OpConfig map[string]string - -const ( - - // OpConfigDefaultHostname a DNS name to be used for hostname generation. - OpConfigDefaultHostname = "defaultHostname" - - // OpConfigCMCADuration default duration for cert-manager issued CA - OpConfigCMCADuration = "certManagerCACertDuration" - - // OpConfigCMCADuration default duration for cert-manager issued service certificate - OpConfigCMCertDuration = "certManagerCertDuration" -) - -// Config stores operator configuration -var Config = OpConfig{} - -// LoadFromConfigMap creates a config out of kubernetes config map -func (oc OpConfig) LoadFromConfigMap(cm *corev1.ConfigMap) { - for k, v := range DefaultOpConfig() { - oc[k] = v - } - - for k, v := range cm.Data { - oc[k] = v - } -} - -// DefaultOpConfig returns default configuration -func DefaultOpConfig() OpConfig { - cfg := OpConfig{} - cfg[OpConfigDefaultHostname] = "" - cfg[OpConfigCMCADuration] = "8766h" - cfg[OpConfigCMCertDuration] = "2160h" - return cfg -} From ea15efc009bc3f6f48f718e5ef06963eca9dd9a7 Mon Sep 17 00:00:00 2001 From: Kirby Chin <37311900+kabicin@users.noreply.github.com> Date: Wed, 15 May 2024 16:57:11 -0400 Subject: [PATCH 22/25] Remove probe patch, centralize probes logic to RCO --- api/v1/runtimecomponent_types.go | 15 --------------- .../runtime-component.clusterserviceversion.yaml | 2 +- common/types.go | 4 ---- utils/utils.go | 10 +++++----- 4 files changed, 6 insertions(+), 25 deletions(-) diff --git a/api/v1/runtimecomponent_types.go b/api/v1/runtimecomponent_types.go index fcaedd1b9..f1063104c 100644 --- a/api/v1/runtimecomponent_types.go +++ b/api/v1/runtimecomponent_types.go @@ -558,21 +558,6 @@ func (p *RuntimeComponentProbes) GetStartupProbe() *common.BaseComponentProbe { return p.Startup } -// PatchLivenessProbe updates values for and returns the liveness probe -func (p *RuntimeComponentProbes) PatchLivenessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { - return probe -} - -// PatchReadinessProbe updates values for and returns the readiness probe -func (p *RuntimeComponentProbes) PatchReadinessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { - return probe -} - -// PatchStartupProbe updates values for and returns the startup probe -func (p *RuntimeComponentProbes) PatchStartupProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe { - return probe -} - // GetDefaultLivenessProbe returns default values for liveness probe func (p *RuntimeComponentProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *common.BaseComponentProbe { return common.GetDefaultMicroProfileLivenessProbe(ba) diff --git a/bundle/manifests/runtime-component.clusterserviceversion.yaml b/bundle/manifests/runtime-component.clusterserviceversion.yaml index ce9ffe002..93fdfd573 100644 --- a/bundle/manifests/runtime-component.clusterserviceversion.yaml +++ b/bundle/manifests/runtime-component.clusterserviceversion.yaml @@ -71,7 +71,7 @@ metadata: categories: Application Runtime certified: "true" containerImage: icr.io/appcafe/runtime-component-operator:daily - createdAt: "2024-05-14T13:54:13Z" + createdAt: "2024-05-15T20:55:30Z" description: Deploys any runtime component with dynamic and auto-tuning configuration olm.skipRange: '>=0.8.0 <1.3.2' operators.openshift.io/infrastructure-features: '["disconnected"]' diff --git a/common/types.go b/common/types.go index c9b1698c4..8725013bd 100644 --- a/common/types.go +++ b/common/types.go @@ -271,10 +271,6 @@ type BaseComponentProbes interface { GetDefaultLivenessProbe(ba BaseComponent) *BaseComponentProbe GetDefaultReadinessProbe(ba BaseComponent) *BaseComponentProbe GetDefaultStartupProbe(ba BaseComponent) *BaseComponentProbe - - PatchLivenessProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe - PatchReadinessProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe - PatchStartupProbe(ba BaseComponent, probe *BaseComponentProbe) *BaseComponentProbe } type BaseComponentServiceAccount interface { diff --git a/utils/utils.go b/utils/utils.go index 7c953c80d..58a1b6c6c 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -288,19 +288,19 @@ func CustomizeProbes(container *corev1.Container, ba common.BaseComponent) { return } - container.ReadinessProbe = customizeProbe(probesConfig.GetReadinessProbe(), probesConfig.GetDefaultReadinessProbe, probesConfig.PatchReadinessProbe, ba) - container.LivenessProbe = customizeProbe(probesConfig.GetLivenessProbe(), probesConfig.GetDefaultLivenessProbe, probesConfig.PatchLivenessProbe, ba) - container.StartupProbe = customizeProbe(probesConfig.GetStartupProbe(), probesConfig.GetDefaultStartupProbe, probesConfig.PatchStartupProbe, ba) + container.ReadinessProbe = customizeProbe(probesConfig.GetReadinessProbe(), probesConfig.GetDefaultReadinessProbe, ba) + container.LivenessProbe = customizeProbe(probesConfig.GetLivenessProbe(), probesConfig.GetDefaultLivenessProbe, ba) + container.StartupProbe = customizeProbe(probesConfig.GetStartupProbe(), probesConfig.GetDefaultStartupProbe, ba) } -func customizeProbe(config *common.BaseComponentProbe, getDefaultProbeCallback func(ba common.BaseComponent) *common.BaseComponentProbe, patchProbeCallback func(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe, ba common.BaseComponent) *corev1.Probe { +func customizeProbe(config *common.BaseComponentProbe, getDefaultProbeCallback func(ba common.BaseComponent) *common.BaseComponentProbe, ba common.BaseComponent) *corev1.Probe { // Probe not defined -- set probe to nil if config == nil { return nil } // Always use MicroProfile default values for the probe - return ConvertToCoreProbe(ba, patchProbeCallback(ba, customizeProbeDefaults(config, getDefaultProbeCallback(ba)))) + return ConvertToCoreProbe(ba, customizeProbeDefaults(config, getDefaultProbeCallback(ba))) } func createHTTPGetActionFromOptionalHTTPGetAction(ba common.BaseComponent, optionalHTTPGetAction *common.OptionalHTTPGetAction) *corev1.HTTPGetAction { From 9e2fa7a0d43fc5d73f9f7c51cc7d317defd9daee Mon Sep 17 00:00:00 2001 From: Kirby Chin <37311900+kabicin@users.noreply.github.com> Date: Thu, 16 May 2024 10:09:00 -0400 Subject: [PATCH 23/25] Pass on HTTPGet attributes from default MP config --- .../runtime-component.clusterserviceversion.yaml | 2 +- utils/utils.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bundle/manifests/runtime-component.clusterserviceversion.yaml b/bundle/manifests/runtime-component.clusterserviceversion.yaml index 93fdfd573..9c266038b 100644 --- a/bundle/manifests/runtime-component.clusterserviceversion.yaml +++ b/bundle/manifests/runtime-component.clusterserviceversion.yaml @@ -71,7 +71,7 @@ metadata: categories: Application Runtime certified: "true" containerImage: icr.io/appcafe/runtime-component-operator:daily - createdAt: "2024-05-15T20:55:30Z" + createdAt: "2024-05-16T14:08:31Z" description: Deploys any runtime component with dynamic and auto-tuning configuration olm.skipRange: '>=0.8.0 <1.3.2' operators.openshift.io/infrastructure-features: '["disconnected"]' diff --git a/utils/utils.go b/utils/utils.go index 58a1b6c6c..fe501c5ed 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -373,6 +373,21 @@ func customizeProbeDefaults(config *common.BaseComponentProbe, defaultProbe *com } if config.BaseComponentProbeHandler.HTTPGet != nil { probe.BaseComponentProbeHandler.HTTPGet = config.BaseComponentProbeHandler.HTTPGet + if config.BaseComponentProbeHandler.HTTPGet.Path != "" { + probe.BaseComponentProbeHandler.HTTPGet.Path = config.BaseComponentProbeHandler.HTTPGet.Path + } + if config.BaseComponentProbeHandler.HTTPGet.Host != "" { + probe.BaseComponentProbeHandler.HTTPGet.Host = config.BaseComponentProbeHandler.HTTPGet.Host + } + if config.BaseComponentProbeHandler.HTTPGet.Port != nil { + probe.BaseComponentProbeHandler.HTTPGet.Port = config.BaseComponentProbeHandler.HTTPGet.Port + } + if config.BaseComponentProbeHandler.HTTPGet.Scheme != "" { + probe.BaseComponentProbeHandler.HTTPGet.Scheme = config.BaseComponentProbeHandler.HTTPGet.Scheme + } + if len(config.BaseComponentProbeHandler.HTTPGet.HTTPHeaders) > 0 { + probe.BaseComponentProbeHandler.HTTPGet.HTTPHeaders = config.BaseComponentProbeHandler.HTTPGet.HTTPHeaders + } } if config.BaseComponentProbeHandler.TCPSocket != nil { probe.BaseComponentProbeHandler.TCPSocket = config.BaseComponentProbeHandler.TCPSocket From e89f9b85b0d7ca3b936ee2c4c2477662e27aff27 Mon Sep 17 00:00:00 2001 From: Kirby Chin <37311900+kabicin@users.noreply.github.com> Date: Thu, 16 May 2024 10:10:04 -0400 Subject: [PATCH 24/25] Update utils.go --- utils/utils.go | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index fe501c5ed..53c4cb2ba 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -372,7 +372,6 @@ func customizeProbeDefaults(config *common.BaseComponentProbe, defaultProbe *com probe.BaseComponentProbeHandler.Exec = config.BaseComponentProbeHandler.Exec } if config.BaseComponentProbeHandler.HTTPGet != nil { - probe.BaseComponentProbeHandler.HTTPGet = config.BaseComponentProbeHandler.HTTPGet if config.BaseComponentProbeHandler.HTTPGet.Path != "" { probe.BaseComponentProbeHandler.HTTPGet.Path = config.BaseComponentProbeHandler.HTTPGet.Path } From 336488006a05f44c70c866f2be316d1ca0e5c1fb Mon Sep 17 00:00:00 2001 From: Kirby Chin <37311900+kabicin@users.noreply.github.com> Date: Thu, 16 May 2024 10:20:46 -0400 Subject: [PATCH 25/25] Update utils.go --- utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index 53c4cb2ba..62ad0f558 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -372,7 +372,7 @@ func customizeProbeDefaults(config *common.BaseComponentProbe, defaultProbe *com probe.BaseComponentProbeHandler.Exec = config.BaseComponentProbeHandler.Exec } if config.BaseComponentProbeHandler.HTTPGet != nil { - if config.BaseComponentProbeHandler.HTTPGet.Path != "" { + if config.BaseComponentProbeHandler.HTTPGet.Path != "" && config.BaseComponentProbeHandler.HTTPGet.Path != "/" { probe.BaseComponentProbeHandler.HTTPGet.Path = config.BaseComponentProbeHandler.HTTPGet.Path } if config.BaseComponentProbeHandler.HTTPGet.Host != "" {