Skip to content

Commit

Permalink
Merge branch 'main' of github.com:odigos-io/odigos into feature/sourc…
Browse files Browse the repository at this point in the history
…e-ui
  • Loading branch information
BenElferink committed Dec 30, 2024
2 parents a2b06ef + 6c6bcc3 commit c9d31b3
Show file tree
Hide file tree
Showing 14 changed files with 515 additions and 89 deletions.
27 changes: 27 additions & 0 deletions api/odigos/v1alpha1/instrumentationconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,33 @@ type InstrumentationConfig struct {
Status InstrumentationConfigStatus `json:"status,omitempty"`
}

type OtherAgent struct {
Name string `json:"name,omitempty"`
}

// +kubebuilder:object:generate=true
type EnvVar struct {
Name string `json:"name"`
Value string `json:"value"`
}

// +kubebuilder:object:generate=true
type RuntimeDetailsByContainer struct {
ContainerName string `json:"containerName"`
Language common.ProgrammingLanguage `json:"language"`
RuntimeVersion string `json:"runtimeVersion,omitempty"`
EnvVars []EnvVar `json:"envVars,omitempty"`
OtherAgent *OtherAgent `json:"otherAgent,omitempty"`
LibCType *common.LibCType `json:"libCType,omitempty"`

// Stores the error message from the CRI runtime if returned to prevent instrumenting the container if an error exists.
CriErrorMessage *string `json:"criErrorMessage,omitempty"`
// Holds the environment variables retrieved from the container runtime.
EnvFromContainerRuntime []EnvVar `json:"envFromContainerRuntime,omitempty"`
// A temporary variable used during migration to track whether the new runtime detection process has been executed. If empty, it indicates the process has not yet been run. This field may be removed later.
RuntimeUpdateState *ProcessingState `json:"runtimeUpdateState,omitempty"`
}

type InstrumentationConfigStatus struct {
// Capture Runtime Details for the workloads that this CR applies to.
RuntimeDetailsByContainer []RuntimeDetailsByContainer `json:"runtimeDetailsByContainer,omitempty"`
Expand Down
33 changes: 3 additions & 30 deletions api/odigos/v1alpha1/instrumentedapplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,14 @@ type InstrumentationLibraryOptions struct {
Options []ConfigOption `json:"options"`
}

// +kubebuilder:object:generate=true
type EnvVar struct {
Name string `json:"name"`
Value string `json:"value"`
}

type OtherAgent struct {
Name string `json:"name,omitempty"`
}

type ProcessingState string

const (
ProcessingStateFailed ProcessingState = "Failed"
ProcessingStateSucceeded ProcessingState = "Succeeded"
ProcessingStateSkipped ProcessingState = "Skipped"
ProcessingStateFailed ProcessingState = "Failed" // Used when CRI fails to detect the runtime envs
ProcessingStateSucceeded ProcessingState = "Succeeded" // Indicates that CRI successfully processed the runtime environments, even if no environments were detected.
ProcessingStateSkipped ProcessingState = "Skipped" // Used when env originally come from manifest
)

// +kubebuilder:object:generate=true
type RuntimeDetailsByContainer struct {
ContainerName string `json:"containerName"`
Language common.ProgrammingLanguage `json:"language"`
RuntimeVersion string `json:"runtimeVersion,omitempty"`
EnvVars []EnvVar `json:"envVars,omitempty"`
OtherAgent *OtherAgent `json:"otherAgent,omitempty"`
LibCType *common.LibCType `json:"libCType,omitempty"`

// Stores the error message from the CRI runtime if returned to prevent instrumenting the container if an error exists.
CriErrorMessage *string `json:"criErrorMessage,omitempty"`
// Holds the environment variables retrieved from the container runtime.
EnvFromContainerRuntime []EnvVar `json:"envFromContainerRuntime,omitempty"`
// A temporary variable used during migration to track whether the new runtime detection process has been executed. If empty, it indicates the process has not yet been run. This field may be removed later.
RuntimeUpdateState *ProcessingState `json:"runtimeUpdateState,omitempty"`
}

// +kubebuilder:object:generate=true
type OptionByContainer struct {
ContainerName string `json:"containerName"`
Expand Down
25 changes: 14 additions & 11 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
skipWait bool
telemetryEnabled bool
openshiftEnabled bool
skipWebhookIssuerCreation bool
psp bool
userInputIgnoredNamespaces []string
userInputIgnoredContainers []string
Expand Down Expand Up @@ -203,17 +204,18 @@ func createOdigosConfig(odigosTier common.OdigosTier) common.OdigosConfiguration
}

return common.OdigosConfiguration{
ConfigVersion: 1, // config version starts at 1 and incremented on every config change
TelemetryEnabled: telemetryEnabled,
OpenshiftEnabled: openshiftEnabled,
IgnoredNamespaces: fullIgnoredNamespaces,
IgnoredContainers: fullIgnoredContainers,
Psp: psp,
ImagePrefix: imagePrefix,
OdigletImage: odigletImage,
InstrumentorImage: instrumentorImage,
AutoscalerImage: autoScalerImage,
Profiles: selectedProfiles,
ConfigVersion: 1, // config version starts at 1 and incremented on every config change
TelemetryEnabled: telemetryEnabled,
OpenshiftEnabled: openshiftEnabled,
IgnoredNamespaces: fullIgnoredNamespaces,
IgnoredContainers: fullIgnoredContainers,
SkipWebhookIssuerCreation: skipWebhookIssuerCreation,
Psp: psp,
ImagePrefix: imagePrefix,
OdigletImage: odigletImage,
InstrumentorImage: instrumentorImage,
AutoscalerImage: autoScalerImage,
Profiles: selectedProfiles,
}
}

Expand All @@ -235,6 +237,7 @@ func init() {
installCmd.Flags().BoolVar(&skipWait, "nowait", false, "skip waiting for odigos pods to be ready")
installCmd.Flags().BoolVar(&telemetryEnabled, "telemetry", true, "send general telemetry regarding Odigos usage")
installCmd.Flags().BoolVar(&openshiftEnabled, "openshift", false, "configure selinux on openshift nodes")
installCmd.Flags().BoolVar(&skipWebhookIssuerCreation, "skip-webhook-issuer-creation", false, "Skip creating the Issuer and Certificate for the Instrumentor pod webhook if cert-manager is installed.")
installCmd.Flags().StringVar(&odigletImage, "odiglet-image", "", "odiglet container image name")
installCmd.Flags().StringVar(&instrumentorImage, "instrumentor-image", "keyval/odigos-instrumentor", "instrumentor container image name")
installCmd.Flags().StringVar(&autoScalerImage, "autoscaler-image", "keyval/odigos-autoscaler", "autoscaler container image name")
Expand Down
3 changes: 1 addition & 2 deletions cli/cmd/resources/instrumentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,7 @@ func (a *instrumentorResourceManager) InstallFromScratch(ctx context.Context) er
NewInstrumentorDeployment(a.ns, a.odigosVersion, a.config.TelemetryEnabled, a.config.ImagePrefix, a.config.InstrumentorImage),
NewInstrumentorService(a.ns),
}

if certManagerInstalled {
if certManagerInstalled && a.config.SkipWebhookIssuerCreation != true {
resources = append([]kube.Object{NewInstrumentorIssuer(a.ns),
NewInstrumentorCertificate(a.ns),
NewMutatingWebhookConfiguration(a.ns, nil),
Expand Down
4 changes: 4 additions & 0 deletions common/envOverwrite/overwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,7 @@ func ValToAppend(envName string, sdk common.OtelSdk) (string, bool) {

return valToAppend, true
}

func GetPossibleValuesPerEnv(env string) map[common.OtelSdk]string {
return EnvValuesMap[env].values
}
29 changes: 15 additions & 14 deletions common/odigos_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,21 @@ type CollectorGatewayConfiguration struct {

// OdigosConfiguration defines the desired state of OdigosConfiguration
type OdigosConfiguration struct {
ConfigVersion int `json:"configVersion"`
TelemetryEnabled bool `json:"telemetryEnabled,omitempty"`
OpenshiftEnabled bool `json:"openshiftEnabled,omitempty"`
IgnoredNamespaces []string `json:"ignoredNamespaces,omitempty"`
IgnoredContainers []string `json:"ignoredContainers,omitempty"`
Psp bool `json:"psp,omitempty"`
ImagePrefix string `json:"imagePrefix,omitempty"`
OdigletImage string `json:"odigletImage,omitempty"`
InstrumentorImage string `json:"instrumentorImage,omitempty"`
AutoscalerImage string `json:"autoscalerImage,omitempty"`
CollectorGateway *CollectorGatewayConfiguration `json:"collectorGateway,omitempty"`
CollectorNode *CollectorNodeConfiguration `json:"collectorNode,omitempty"`
Profiles []ProfileName `json:"profiles,omitempty"`
AllowConcurrentAgents *bool `json:"allowConcurrentAgents,omitempty"`
ConfigVersion int `json:"configVersion"`
TelemetryEnabled bool `json:"telemetryEnabled,omitempty"`
OpenshiftEnabled bool `json:"openshiftEnabled,omitempty"`
IgnoredNamespaces []string `json:"ignoredNamespaces,omitempty"`
IgnoredContainers []string `json:"ignoredContainers,omitempty"`
Psp bool `json:"psp,omitempty"`
ImagePrefix string `json:"imagePrefix,omitempty"`
OdigletImage string `json:"odigletImage,omitempty"`
InstrumentorImage string `json:"instrumentorImage,omitempty"`
AutoscalerImage string `json:"autoscalerImage,omitempty"`
SkipWebhookIssuerCreation bool `json:"skipWebhookIssuerCreation,omitempty"`
CollectorGateway *CollectorGatewayConfiguration `json:"collectorGateway,omitempty"`
CollectorNode *CollectorNodeConfiguration `json:"collectorNode,omitempty"`
Profiles []ProfileName `json:"profiles,omitempty"`
AllowConcurrentAgents *bool `json:"allowConcurrentAgents,omitempty"`
// this is internal currently, and is not exposed on the CLI / helm
// used for odigos enterprise
GoAutoIncludeCodeAttributes bool `json:"goAutoIncludeCodeAttributes,omitempty"`
Expand Down
12 changes: 8 additions & 4 deletions helm/odigos/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{{- define "utils.certManagerApiVersion" -}}
{{- if .Capabilities.APIVersions.Has "cert-manager.io/v1" -}}
{{- if not (eq .Values.instrumentor.skipWebhookIssuerCreation true) -}}
{{- if .Capabilities.APIVersions.Has "cert-manager.io/v1" -}}
cert-manager.io/v1
{{- else if .Capabilities.APIVersions.Has "cert-manager.io/v1beta1" -}}
{{- else if .Capabilities.APIVersions.Has "cert-manager.io/v1beta1" -}}
cert-manager.io/v1beta1
{{- else if .Capabilities.APIVersions.Has "cert-manager.io/v1alpha2" -}}
{{- else if .Capabilities.APIVersions.Has "cert-manager.io/v1alpha2" -}}
cert-manager.io/v1alpha2
{{- else if .Capabilities.APIVersions.Has "certmanager.k8s.io/v1alpha1" -}}
{{- else if .Capabilities.APIVersions.Has "certmanager.k8s.io/v1alpha1" -}}
certmanager.k8s.io/v1alpha1
{{- else -}}
{{- print "" -}}
{{- end -}}
{{- else -}}
{{- print "" -}}
{{- end -}}
Expand Down
11 changes: 11 additions & 0 deletions helm/odigos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ instrumentor:
kubernetes.io/os: linux
tolerations: []
affinity: {}
# skipWebhookIssuerCreation:
# - This flag controls whether the chart should skip creating an Issuer
# and associated Certificate for securing the mutating webhook communication.
# - Setting this to "true" will skip the creation of an Issuer and Certificate,
# even if cert-manager is detected in the cluster and the required API version is available.
# - In some cases, the Issuer and Certificate are necessary for the instrumentor service
# to run its pod mutating webhook, which requires a signed certificate to comply with
# Kubernetes' TLS requirements.
# - If cert-manager is not installed or detected, no Issuer or Certificate will be created
# regardless of this flag.
skipWebhookIssuerCreation: false

odiglet:
image:
Expand Down
6 changes: 3 additions & 3 deletions instrumentor/controllers/instrumentationdevice/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ func isDataCollectionReady(ctx context.Context, c client.Client) bool {
return nodeCollectorsGroup.Status.Ready
}

func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.Client, runtimeDetails *odigosv1.InstrumentedApplication) (error, bool) {
func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.Client, instApp *odigosv1.InstrumentedApplication) (error, bool) {
// devicePartiallyApplied is used to indicate that the instrumentation device was partially applied for some of the containers.
devicePartiallyApplied := false
deviceNotAppliedDueToPresenceOfAnotherAgent := false

logger := log.FromContext(ctx)
obj, err := getWorkloadObject(ctx, kubeClient, runtimeDetails)
obj, err := getWorkloadObject(ctx, kubeClient, instApp)
if err != nil {
return err, false
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.C
agentsCanRunConcurrently = *odigosConfiguration.AllowConcurrentAgents
}

err, deviceApplied, deviceSkippedDueToOtherAgent := instrumentation.ApplyInstrumentationDevicesToPodTemplate(podSpec, runtimeDetails, otelSdkToUse, obj, logger, agentsCanRunConcurrently)
err, deviceApplied, deviceSkippedDueToOtherAgent := instrumentation.ApplyInstrumentationDevicesToPodTemplate(podSpec, instApp.Spec.RuntimeDetails, otelSdkToUse, obj, logger, agentsCanRunConcurrently)
if err != nil {
return err
}
Expand Down
38 changes: 19 additions & 19 deletions instrumentor/instrumentation/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
ErrPatchEnvVars = errors.New("failed to patch env vars")
)

func ApplyInstrumentationDevicesToPodTemplate(original *corev1.PodTemplateSpec, runtimeDetails *odigosv1.InstrumentedApplication, defaultSdks map[common.ProgrammingLanguage]common.OtelSdk, targetObj client.Object,
func ApplyInstrumentationDevicesToPodTemplate(original *corev1.PodTemplateSpec, runtimeDetails []odigosv1.RuntimeDetailsByContainer, defaultSdks map[common.ProgrammingLanguage]common.OtelSdk, targetObj client.Object,
logger logr.Logger, agentsCanRunConcurrently bool) (error, bool, bool) {
// delete any existing instrumentation devices.
// this is necessary for example when migrating from community to enterprise,
Expand Down Expand Up @@ -154,31 +154,31 @@ func RevertInstrumentationDevices(original *corev1.PodTemplateSpec) bool {
return changed
}

func getLanguageOfContainer(instrumentation *odigosv1.InstrumentedApplication, containerName string) common.ProgrammingLanguage {
for _, l := range instrumentation.Spec.RuntimeDetails {
if l.ContainerName == containerName {
return l.Language
func getLanguageOfContainer(runtimeDetails []odigosv1.RuntimeDetailsByContainer, containerName string) common.ProgrammingLanguage {
for _, rd := range runtimeDetails {
if rd.ContainerName == containerName {
return rd.Language
}
}

return common.UnknownProgrammingLanguage
}

func getContainerOtherAgents(instrumentation *odigosv1.InstrumentedApplication, containerName string) *odigosv1.OtherAgent {
for _, l := range instrumentation.Spec.RuntimeDetails {
if l.ContainerName == containerName {
if l.OtherAgent != nil && *l.OtherAgent != (odigosv1.OtherAgent{}) {
return l.OtherAgent
func getContainerOtherAgents(runtimeDetails []odigosv1.RuntimeDetailsByContainer, containerName string) *odigosv1.OtherAgent {
for _, rd := range runtimeDetails {
if rd.ContainerName == containerName {
if rd.OtherAgent != nil && *rd.OtherAgent != (odigosv1.OtherAgent{}) {
return rd.OtherAgent
}
}
}
return nil
}

func getLibCTypeOfContainer(instrumentation *odigosv1.InstrumentedApplication, containerName string) *common.LibCType {
for _, l := range instrumentation.Spec.RuntimeDetails {
if l.ContainerName == containerName {
return l.LibCType
func getLibCTypeOfContainer(runtimeDetails []odigosv1.RuntimeDetailsByContainer, containerName string) *common.LibCType {
for _, rd := range runtimeDetails {
if rd.ContainerName == containerName {
return rd.LibCType
}
}

Expand All @@ -187,12 +187,12 @@ func getLibCTypeOfContainer(instrumentation *odigosv1.InstrumentedApplication, c

// getEnvVarsOfContainer returns the env vars which are defined for the given container and are used for instrumentation purposes.
// This function also returns env vars which are declared in the container build.
func getEnvVarsOfContainer(instrumentation *odigosv1.InstrumentedApplication, containerName string) map[string]string {
func getEnvVarsOfContainer(runtimeDetails []odigosv1.RuntimeDetailsByContainer, containerName string) map[string]string {
envVars := make(map[string]string)

for _, l := range instrumentation.Spec.RuntimeDetails {
if l.ContainerName == containerName {
for _, env := range l.EnvVars {
for _, rd := range runtimeDetails {
if rd.ContainerName == containerName {
for _, env := range rd.EnvVars {
envVars[env.Name] = env.Value
}
return envVars
Expand All @@ -204,7 +204,7 @@ func getEnvVarsOfContainer(instrumentation *odigosv1.InstrumentedApplication, co

// when otelsdk is nil, it means that the container is not instrumented.
// this will trigger reverting of any existing env vars which were set by odigos before.
func patchEnvVarsForContainer(runtimeDetails *odigosv1.InstrumentedApplication, container *corev1.Container, sdk *common.OtelSdk, programmingLanguage common.ProgrammingLanguage, manifestEnvOriginal *envoverwrite.OrigWorkloadEnvValues) error {
func patchEnvVarsForContainer(runtimeDetails []odigosv1.RuntimeDetailsByContainer, container *corev1.Container, sdk *common.OtelSdk, programmingLanguage common.ProgrammingLanguage, manifestEnvOriginal *envoverwrite.OrigWorkloadEnvValues) error {

observedEnvs := getEnvVarsOfContainer(runtimeDetails, container.Name)

Expand Down
5 changes: 5 additions & 0 deletions instrumentor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

corev1 "k8s.io/api/core/v1"

runtimemigration "github.com/odigos-io/odigos/instrumentor/runtimemigration"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
Expand Down Expand Up @@ -152,6 +153,10 @@ func main() {

ctx := signals.SetupSignalHandler()

// This temporary migration step ensures the runtimeDetails migration in the instrumentationConfig is performed.
// This code can be removed once the migration is confirmed to be successful.
mgr.Add(&runtimemigration.MigrationRunnable{KubeClient: mgr.GetClient(), Logger: setupLog})

err = sdks.SetDefaultSDKs(ctx)

if err != nil {
Expand Down
Loading

0 comments on commit c9d31b3

Please sign in to comment.