Skip to content

Commit

Permalink
Merge pull request #1047 from gburges/sidecar
Browse files Browse the repository at this point in the history
feat: add otel-collector sidecar
  • Loading branch information
gburges authored Oct 15, 2024
2 parents 4f29dc9 + 0c3a273 commit 5ad96e8
Show file tree
Hide file tree
Showing 16 changed files with 611 additions and 661 deletions.
2 changes: 1 addition & 1 deletion apis/cloud.redhat.com/v1alpha1/clowdapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ type DeploymentStrategy struct {
}

type Sidecar struct {
// The name of the sidecar, only supported names allowed, (token-refresher)
// The name of the sidecar, only supported names allowed, (otel-collector, token-refresher)
Name string `json:"name"`

// Defines if the sidecar is enabled, defaults to False
Expand Down
8 changes: 4 additions & 4 deletions apis/cloud.redhat.com/v1alpha1/clowdapp_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ func validateSidecars(r *ClowdApp) field.ErrorList {
allErrs := field.ErrorList{}
for depIndx, deployment := range r.Spec.Deployments {
for carIndx, sidecar := range deployment.PodSpec.Sidecars {
if sidecar.Name != "token-refresher" {
if sidecar.Name != "token-refresher" && sidecar.Name != "otel-collector" {
allErrs = append(
allErrs,
field.Forbidden(
field.NewPath(fmt.Sprintf("spec.Deployment[%d].Sidecars[%d]", depIndx, carIndx)),
"Sidecar is of unknown type, must be one of [token-refresher]",
"Sidecar is of unknown type, must be one of [token-refresher] or [otel-collector]",
),
)
}
Expand All @@ -151,12 +151,12 @@ func validateSidecars(r *ClowdApp) field.ErrorList {
continue
}
for carIndx, sidecar := range job.PodSpec.Sidecars {
if sidecar.Name != "token-refresher" {
if sidecar.Name != "token-refresher" && sidecar.Name != "otel-collector" {
allErrs = append(
allErrs,
field.Forbidden(
field.NewPath(fmt.Sprintf("spec.Deployment[%d].Sidecars[%d]", jobIndx, carIndx)),
"Sidecar is of unknown type, must be one of [token-refresher]",
"Sidecar is of unknown type, must be one of [token-refresher] or [otel-collector]",
),
)
}
Expand Down
10 changes: 10 additions & 0 deletions apis/cloud.redhat.com/v1alpha1/clowdenvironment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,21 @@ type ClowdEnvironmentSpec struct {
type TokenRefresherConfig struct {
// Enables or disables token refresher sidecars
Enabled bool `json:"enabled"`
// Configurable image
Image string `json:"image,omitempty"`
}

type OtelCollectorConfig struct {
// Enable or disable otel collector sidecar
Enabled bool `json:"enabled"`
// Configurable image
Image string `json:"image,omitempty"`
}
type Sidecars struct {
// Sets up Token Refresher configuration
TokenRefresher TokenRefresherConfig `json:"tokenRefresher,omitempty"`
// Sets up OpenTelemetry collector configuration
OtelCollector OtelCollectorConfig `json:"otelCollector,omitempty"`
}

type DeploymentConfig struct {
Expand Down
16 changes: 16 additions & 0 deletions apis/cloud.redhat.com/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions config/crd/bases/cloud.redhat.com_clowdapps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ spec:
type: boolean
name:
description: The name of the sidecar, only supported
names allowed, (token-refresher)
names allowed, (otel-collector, token-refresher)
type: string
required:
- enabled
Expand Down Expand Up @@ -4298,7 +4298,7 @@ spec:
type: boolean
name:
description: The name of the sidecar, only supported
names allowed, (token-refresher)
names allowed, (otel-collector, token-refresher)
type: string
required:
- enabled
Expand Down
15 changes: 15 additions & 0 deletions config/crd/bases/cloud.redhat.com_clowdenvironments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,27 @@ spec:
sidecars:
description: Defines the sidecar configuration
properties:
otelCollector:
description: Sets up OpenTelemetry collector configuration
properties:
enabled:
description: Enable or disable otel collector sidecar
type: boolean
image:
description: Configurable image
type: string
required:
- enabled
type: object
tokenRefresher:
description: Sets up Token Refresher configuration
properties:
enabled:
description: Enables or disables token refresher sidecars
type: boolean
image:
description: Configurable image
type: string
required:
- enabled
type: object
Expand Down
2 changes: 2 additions & 0 deletions controllers/cloud.redhat.com/clowderconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type ClowderConfig struct {
CaddyReverseProxy string `json:"caddyReverseProxy"`
ObjectStoreMinio string `json:"objectStoreMinio"`
FeatureFlagsUnleash string `json:"featureFlagsUnleash"`
TokenRefresher string `json:"tokenRefresher"`
OtelCollector string `json:"otelCollector"`
} `json:"images"`
DebugOptions struct {
Logging struct {
Expand Down
36 changes: 36 additions & 0 deletions controllers/cloud.redhat.com/providers/sidecar/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func (sc *sidecarProvider) Provide(app *crd.ClowdApp) error {
d.Spec.Template.Spec.Containers = append(d.Spec.Template.Spec.Containers, *cont)
}
}
case "otel-collector":
if sidecar.Enabled && sc.Env.Spec.Providers.Sidecars.OtelCollector.Enabled {
cont := getOtelCollector()
if cont != nil {
d.Spec.Template.Spec.Containers = append(d.Spec.Template.Spec.Containers, *cont)
}
}
default:
return fmt.Errorf("%s is not a valid sidecar name", sidecar.Name)
}
Expand Down Expand Up @@ -75,6 +82,13 @@ func (sc *sidecarProvider) Provide(app *crd.ClowdApp) error {
cj.Spec.JobTemplate.Spec.Template.Spec.Containers = append(cj.Spec.JobTemplate.Spec.Template.Spec.Containers, *cont)
}
}
case "otel-collector":
if sidecar.Enabled && sc.Env.Spec.Providers.Sidecars.OtelCollector.Enabled {
cont := getOtelCollector()
if cont != nil {
cj.Spec.JobTemplate.Spec.Template.Spec.Containers = append(cj.Spec.JobTemplate.Spec.Template.Spec.Containers, *cont)
}
}
default:
return fmt.Errorf("%s is not a valid sidecar name", sidecar.Name)
}
Expand Down Expand Up @@ -130,3 +144,25 @@ func getTokenRefresher(appName string) *core.Container {

return &cont
}

func getOtelCollector() *core.Container {
cont := core.Container{}

cont.Name = "otel-collector"
cont.Image = DefaultImageSideCarOtelCollector
cont.Args = []string{}
cont.TerminationMessagePath = "/dev/termination-log"
cont.TerminationMessagePolicy = core.TerminationMessageReadFile
cont.ImagePullPolicy = core.PullIfNotPresent
cont.Resources = core.ResourceRequirements{
Limits: core.ResourceList{
"cpu": resource.MustParse("500m"),
"memory": resource.MustParse("2048Mi"),
},
Requests: core.ResourceList{
"cpu": resource.MustParse("250m"),
"memory": resource.MustParse("1024Mi"),
},
}
return &cont
}
25 changes: 24 additions & 1 deletion controllers/cloud.redhat.com/providers/sidecar/provider.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
package sidecar

import (
crd "github.com/RedHatInsights/clowder/apis/cloud.redhat.com/v1alpha1"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/clowderconfig"
"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/providers"
)

var DefaultImageSideCarTokenRefresher = "quay.io/observatorium/token-refresher:master-2023-09-20-f5e3403" // nolint:gosec
var DefaultImageSideCarTokenRefresher = "quay.io/observatorium/token-refresher:master-2022-10-21-a99ce82" // nolint:gosec
var DefaultImageSideCarOtelCollector = "ghcr.io/os-observability/redhat-opentelemetry-collector/redhat-opentelemetry-collector:0.107.0" // nolint:gosec

func GetTokenRefresherSidecar(env *crd.ClowdEnvironment) string {
if env.Spec.Providers.Sidecars.TokenRefresher.Image != "" {
return env.Spec.Providers.Sidecars.TokenRefresher.Image
}
if clowderconfig.LoadedConfig.Images.TokenRefresher != "" {
return clowderconfig.LoadedConfig.Images.TokenRefresher
}
return DefaultImageSideCarTokenRefresher
}

func GetOtelCollectorSidecar(env *crd.ClowdEnvironment) string {
if env.Spec.Providers.Sidecars.OtelCollector.Image != "" {
return env.Spec.Providers.Sidecars.OtelCollector.Image
}
if clowderconfig.LoadedConfig.Images.OtelCollector != "" {
return clowderconfig.LoadedConfig.Images.OtelCollector
}
return DefaultImageSideCarOtelCollector
}

// ProvName sets the provider name identifier
var ProvName = "sidecar"
Expand Down
19 changes: 17 additions & 2 deletions deploy-mutate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ objects:
type: boolean
name:
description: The name of the sidecar, only supported
names allowed, (token-refresher)
names allowed, (otel-collector, token-refresher)
type: string
required:
- enabled
Expand Down Expand Up @@ -4401,7 +4401,7 @@ objects:
type: boolean
name:
description: The name of the sidecar, only supported
names allowed, (token-refresher)
names allowed, (otel-collector, token-refresher)
type: string
required:
- enabled
Expand Down Expand Up @@ -7019,12 +7019,27 @@ objects:
sidecars:
description: Defines the sidecar configuration
properties:
otelCollector:
description: Sets up OpenTelemetry collector configuration
properties:
enabled:
description: Enable or disable otel collector sidecar
type: boolean
image:
description: Configurable image
type: string
required:
- enabled
type: object
tokenRefresher:
description: Sets up Token Refresher configuration
properties:
enabled:
description: Enables or disables token refresher sidecars
type: boolean
image:
description: Configurable image
type: string
required:
- enabled
type: object
Expand Down
19 changes: 17 additions & 2 deletions deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ objects:
type: boolean
name:
description: The name of the sidecar, only supported
names allowed, (token-refresher)
names allowed, (otel-collector, token-refresher)
type: string
required:
- enabled
Expand Down Expand Up @@ -4401,7 +4401,7 @@ objects:
type: boolean
name:
description: The name of the sidecar, only supported
names allowed, (token-refresher)
names allowed, (otel-collector, token-refresher)
type: string
required:
- enabled
Expand Down Expand Up @@ -7019,12 +7019,27 @@ objects:
sidecars:
description: Defines the sidecar configuration
properties:
otelCollector:
description: Sets up OpenTelemetry collector configuration
properties:
enabled:
description: Enable or disable otel collector sidecar
type: boolean
image:
description: Configurable image
type: string
required:
- enabled
type: object
tokenRefresher:
description: Sets up Token Refresher configuration
properties:
enabled:
description: Enables or disables token refresher sidecars
type: boolean
image:
description: Configurable image
type: string
required:
- enabled
type: object
Expand Down
Loading

0 comments on commit 5ad96e8

Please sign in to comment.