Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove unsupported probe-path property from container trait #2458

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions deploy/traits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ traits:
- name: probes-enabled
type: bool
description: ProbesEnabled enable/disable probes on the container (default `false`)
- name: probe-path
type: string
description: Path to access on the probe ( default `/health`). Note that this
property is not supportedon quarkus runtime and setting it will result in the
integration failing to start.
- name: liveness-initial-delay
type: int32
description: Number of seconds after the container has started before liveness
Expand Down
5 changes: 0 additions & 5 deletions docs/modules/traits/pages/container.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ The following configuration options are available:
| bool
| ProbesEnabled enable/disable probes on the container (default `false`)

| container.probe-path
| string
| Path to access on the probe ( default `/health`). Note that this property is not supported
on quarkus runtime and setting it will result in the integration failing to start.

| container.liveness-initial-delay
| int32
| Number of seconds after the container has started before liveness probes are initiated.
Expand Down
4 changes: 2 additions & 2 deletions pkg/resources/resources.go

Large diffs are not rendered by default.

70 changes: 6 additions & 64 deletions pkg/trait/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ type containerTrait struct {

// ProbesEnabled enable/disable probes on the container (default `false`)
ProbesEnabled *bool `property:"probes-enabled" json:"probesEnabled,omitempty"`
// Path to access on the probe ( default `/health`). Note that this property is not supported
// on quarkus runtime and setting it will result in the integration failing to start.
ProbePath string `property:"probe-path" json:"probePath,omitempty"`
// Number of seconds after the container has started before liveness probes are initiated.
LivenessInitialDelay int32 `property:"liveness-initial-delay" json:"livenessInitialDelay,omitempty"`
// Number of seconds after which the probe times out. Applies to the liveness probe.
Expand Down Expand Up @@ -118,7 +115,6 @@ func newContainerTrait() Trait {
ServicePortName: defaultContainerPortName,
Name: defaultContainerName,
ProbesEnabled: util.BoolP(false),
ProbePath: defaultProbePath,
}
}

Expand Down Expand Up @@ -233,9 +229,7 @@ func (t *containerTrait) configureContainer(e *Environment) error {
if t.Expose != nil && *t.Expose {
t.configureService(e, &container)
}
if err := t.configureCapabilities(e); err != nil {
return err
}
t.configureCapabilities(e)

portName := t.PortName
if portName == "" {
Expand All @@ -244,9 +238,7 @@ func (t *containerTrait) configureContainer(e *Environment) error {
// Deployment
if err := e.Resources.VisitDeploymentE(func(deployment *appsv1.Deployment) error {
if util.IsTrue(t.ProbesEnabled) && portName == defaultContainerPortName {
if err := t.configureProbes(e, &container, t.Port, t.ProbePath); err != nil {
return err
}
t.configureProbes(&container, t.Port, defaultProbePath)
}

for _, envVar := range e.EnvVars {
Expand Down Expand Up @@ -274,9 +266,7 @@ func (t *containerTrait) configureContainer(e *Environment) error {
if err := e.Resources.VisitKnativeServiceE(func(service *serving.Service) error {
if util.IsTrue(t.ProbesEnabled) && portName == defaultContainerPortName {
// don't set the port on Knative service as it is not allowed.
if err := t.configureProbes(e, &container, 0, t.ProbePath); err != nil {
return err
}
t.configureProbes(&container, 0, defaultProbePath)
}

for _, env := range e.EnvVars {
Expand Down Expand Up @@ -314,9 +304,7 @@ func (t *containerTrait) configureContainer(e *Environment) error {
// CronJob
if err := e.Resources.VisitCronJobE(func(cron *v1beta1.CronJob) error {
if util.IsTrue(t.ProbesEnabled) && portName == defaultContainerPortName {
if err := t.configureProbes(e, &container, t.Port, t.ProbePath); err != nil {
return err
}
t.configureProbes(&container, t.Port, defaultProbePath)
}

for _, envVar := range e.EnvVars {
Expand Down Expand Up @@ -431,61 +419,15 @@ func (t *containerTrait) configureResources(_ *Environment, container *corev1.Co
}
}

func (t *containerTrait) configureHTTP(e *Environment) error {
switch e.CamelCatalog.Runtime.Provider {
case v1.RuntimeProviderQuarkus:
// Quarkus does not offer a runtime option to change http listening ports
return nil
default:
return fmt.Errorf("unsupported runtime: %s", e.CamelCatalog.Runtime.Provider)
}
}

func (t *containerTrait) configureCapabilities(e *Environment) error {
requiresHTTP := false

func (t *containerTrait) configureCapabilities(e *Environment) {
if util.StringSliceExists(e.Integration.Status.Capabilities, v1.CapabilityRest) {
e.ApplicationProperties["camel.context.rest-configuration.component"] = "platform-http"
requiresHTTP = true
}

if util.StringSliceExists(e.Integration.Status.Capabilities, v1.CapabilityPlatformHTTP) {
requiresHTTP = true
}

if requiresHTTP {
return t.configureHTTP(e)
}

return nil
}

func (t *containerTrait) configureProbes(e *Environment, container *corev1.Container, port int, path string) error {
if err := t.configureHTTP(e); err != nil {
return nil
}

switch e.CamelCatalog.Runtime.Provider {
case v1.RuntimeProviderQuarkus:
// Quarkus does not offer a runtime option to change the path of the health endpoint but there
// is a build time property:
//
// quarkus.smallrye-health.root-path
//
// so failing in case user tries to change the path.
//
// NOTE: we could probably be more opinionated and make the path an internal detail.
if path != defaultProbePath {
return fmt.Errorf("health check root path can't be changed at runtimme on Quarkus")
}
default:
return fmt.Errorf("unsupported runtime: %s", e.CamelCatalog.Runtime.Provider)
}

func (t *containerTrait) configureProbes(container *corev1.Container, port int, path string) {
container.LivenessProbe = t.newLivenessProbe(port, path)
container.ReadinessProbe = t.newReadinessProbe(port, path)

return nil
}

func (t *containerTrait) newLivenessProbe(port int, path string) *corev1.Probe {
Expand Down