Skip to content

Commit

Permalink
Patch probe defaults with port and scheme based on manageTLS
Browse files Browse the repository at this point in the history
  • Loading branch information
kabicin committed Jul 27, 2023
1 parent c85ceb0 commit b83ffcc
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 84 deletions.
49 changes: 40 additions & 9 deletions api/v1/openlibertyapplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ type OpenLibertyApplicationSpec struct {
type OpenLibertyApplicationProbes struct {
// Periodic probe of container liveness. Container will be restarted if the probe fails.
// +operator-sdk:csv:customresourcedefinitions:order=49,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=50,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=51,type=spec,displayName="Startup Probe"
Startup *corev1.Probe `json:"startup,omitempty"`
Startup *common.BaseComponentProbe `json:"startup,omitempty"`
}

// Configure pods to run on particular Nodes.
Expand Down Expand Up @@ -640,32 +640,63 @@ func (cr *OpenLibertyApplication) GetProbes() common.BaseComponentProbes {
}

// GetLivenessProbe returns liveness probe
func (p *OpenLibertyApplicationProbes) GetLivenessProbe() *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetLivenessProbe() *common.BaseComponentProbe {
return p.Liveness
}

// GetReadinessProbe returns readiness probe
func (p *OpenLibertyApplicationProbes) GetReadinessProbe() *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetReadinessProbe() *common.BaseComponentProbe {
return p.Readiness
}

// GetStartupProbe returns startup probe
func (p *OpenLibertyApplicationProbes) GetStartupProbe() *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetStartupProbe() *common.BaseComponentProbe {
return p.Startup
}

func (p *OpenLibertyApplicationProbes) PatchLivenessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe {
return patchLibertyProbe(ba, probe)
}

func (p *OpenLibertyApplicationProbes) PatchReadinessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe {
return patchLibertyProbe(ba, probe)
}

func (p *OpenLibertyApplicationProbes) PatchStartupProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe {
return patchLibertyProbe(ba, probe)
}

func patchLibertyProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe {
if probe != nil {
manageTLSEnabled := ba.GetManageTLS() == nil || *ba.GetManageTLS()
if probe.BaseComponentProbeHandler.HTTPGet != nil {
if manageTLSEnabled {
probe.BaseComponentProbeHandler.HTTPGet.Scheme = "HTTPS"
} else {
probe.BaseComponentProbeHandler.HTTPGet.Scheme = "HTTP"
}
portValue := ba.GetService().GetPort()
if portValue != 0 {
port := intstr.FromInt(int(portValue))
probe.BaseComponentProbeHandler.HTTPGet.Port = &port
}
}
}
return probe
}

// GetDefaultLivenessProbe returns default values for liveness probe
func (p *OpenLibertyApplicationProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetDefaultLivenessProbe(ba common.BaseComponent) *common.BaseComponentProbe {
return common.GetDefaultMicroProfileLivenessProbe(ba)
}

// GetDefaultReadinessProbe returns default values for readiness probe
func (p *OpenLibertyApplicationProbes) GetDefaultReadinessProbe(ba common.BaseComponent) *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetDefaultReadinessProbe(ba common.BaseComponent) *common.BaseComponentProbe {
return common.GetDefaultMicroProfileReadinessProbe(ba)
}

// GetDefaultStartupProbe returns default values for startup probe
func (p *OpenLibertyApplicationProbes) GetDefaultStartupProbe(ba common.BaseComponent) *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetDefaultStartupProbe(ba common.BaseComponent) *common.BaseComponentProbe {
return common.GetDefaultMicroProfileStartupProbe(ba)
}

Expand Down
1 change: 1 addition & 0 deletions api/v1/openlibertydump_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type OpenLibertyDumpStatus struct {
type DumpStatusVersions struct {
Reconciled string `json:"reconciled,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
Expand Down
1 change: 1 addition & 0 deletions api/v1/openlibertytrace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type OpenLibertyTraceStatus struct {
type TraceStatusVersions struct {
Reconciled string `json:"reconciled,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
Expand Down
6 changes: 3 additions & 3 deletions api/v1/zz_generated.deepcopy.go

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

30 changes: 21 additions & 9 deletions api/v1beta2/openlibertyapplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,38 @@ type OpenLibertyApplicationSpec struct {
type OpenLibertyApplicationProbes struct {
// Periodic probe of container liveness. Container will be restarted if the probe fails.
// +operator-sdk:csv:customresourcedefinitions:order=49,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=50,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=51,type=spec,displayName="Startup Probe"
Startup *corev1.Probe `json:"startup,omitempty"`
Startup *common.BaseComponentProbe `json:"startup,omitempty"`
}

func (p *OpenLibertyApplicationProbes) GetDefaultLivenessProbe(common.BaseComponent) *corev1.Probe {
func (p *OpenLibertyApplicationProbes) PatchLivenessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe {
return probe
}

func (p *OpenLibertyApplicationProbes) PatchReadinessProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe {
return probe
}

func (p *OpenLibertyApplicationProbes) PatchStartupProbe(ba common.BaseComponent, probe *common.BaseComponentProbe) *common.BaseComponentProbe {
return probe
}

func (p *OpenLibertyApplicationProbes) GetDefaultLivenessProbe(common.BaseComponent) *common.BaseComponentProbe {
return nil
}

func (p *OpenLibertyApplicationProbes) GetDefaultReadinessProbe(common.BaseComponent) *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetDefaultReadinessProbe(common.BaseComponent) *common.BaseComponentProbe {
return nil
}

func (p *OpenLibertyApplicationProbes) GetDefaultStartupProbe(common.BaseComponent) *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetDefaultStartupProbe(common.BaseComponent) *common.BaseComponentProbe {
return nil
}

Expand Down Expand Up @@ -538,17 +550,17 @@ func (cr *OpenLibertyApplication) GetProbes() common.BaseComponentProbes {
}

// GetLivenessProbe returns liveness probe
func (p *OpenLibertyApplicationProbes) GetLivenessProbe() *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetLivenessProbe() *common.BaseComponentProbe {
return p.Liveness
}

// GetReadinessProbe returns readiness probe
func (p *OpenLibertyApplicationProbes) GetReadinessProbe() *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetReadinessProbe() *common.BaseComponentProbe {
return p.Readiness
}

// GetStartupProbe returns startup probe
func (p *OpenLibertyApplicationProbes) GetStartupProbe() *corev1.Probe {
func (p *OpenLibertyApplicationProbes) GetStartupProbe() *common.BaseComponentProbe {
return p.Startup
}

Expand Down
7 changes: 4 additions & 3 deletions api/v1beta2/zz_generated.deepcopy.go

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

Loading

0 comments on commit b83ffcc

Please sign in to comment.