diff --git a/api/config/crd/bases/odigos.io_odigosconfigurations.yaml b/api/config/crd/bases/odigos.io_odigosconfigurations.yaml index 2399ed066..33153b21f 100644 --- a/api/config/crd/bases/odigos.io_odigosconfigurations.yaml +++ b/api/config/crd/bases/odigos.io_odigosconfigurations.yaml @@ -53,8 +53,6 @@ spec: type: string psp: type: boolean - sidecarInstrumentation: - type: boolean telemetryEnabled: type: boolean required: diff --git a/api/odigos/v1alpha1/odigosconfig_types.go b/api/odigos/v1alpha1/odigosconfig_types.go index 42fbecea1..08d172cf3 100644 --- a/api/odigos/v1alpha1/odigosconfig_types.go +++ b/api/odigos/v1alpha1/odigosconfig_types.go @@ -6,16 +6,15 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" // OdigosConfigurationSpec defines the desired state of OdigosConfiguration type OdigosConfigurationSpec struct { - OdigosVersion string `json:"odigosVersion"` - ConfigVersion int `json:"configVersion"` - TelemetryEnabled bool `json:"telemetryEnabled,omitempty"` - SidecarInstrumentation bool `json:"sidecarInstrumentation,omitempty"` - IgnoredNamespaces []string `json:"ignoredNamespaces,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"` + OdigosVersion string `json:"odigosVersion"` + ConfigVersion int `json:"configVersion"` + TelemetryEnabled bool `json:"telemetryEnabled,omitempty"` + IgnoredNamespaces []string `json:"ignoredNamespaces,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"` } //+genclient diff --git a/cli/cmd/install.go b/cli/cmd/install.go index 984e77254..d553d5e36 100644 --- a/cli/cmd/install.go +++ b/cli/cmd/install.go @@ -24,7 +24,6 @@ var ( versionFlag string skipWait bool telemetryEnabled bool - sidecarInstrumentation bool psp bool ignoredNamespaces []string DefaultIgnoredNamespaces = []string{"odigos-system", "kube-system", "local-path-storage", "istio-system", "linkerd"} @@ -129,16 +128,15 @@ func createNamespace(ctx context.Context, cmd *cobra.Command, client *kube.Clien func createOdigosConfigSpec() odigosv1.OdigosConfigurationSpec { return odigosv1.OdigosConfigurationSpec{ - OdigosVersion: versionFlag, - ConfigVersion: 1, // config version starts at 1 and incremented on every config change - TelemetryEnabled: telemetryEnabled, - SidecarInstrumentation: sidecarInstrumentation, - IgnoredNamespaces: ignoredNamespaces, - Psp: psp, - ImagePrefix: imagePrefix, - OdigletImage: odigletImage, - InstrumentorImage: instrumentorImage, - AutoscalerImage: autoScalerImage, + OdigosVersion: versionFlag, + ConfigVersion: 1, // config version starts at 1 and incremented on every config change + TelemetryEnabled: telemetryEnabled, + IgnoredNamespaces: ignoredNamespaces, + Psp: psp, + ImagePrefix: imagePrefix, + OdigletImage: odigletImage, + InstrumentorImage: instrumentorImage, + AutoscalerImage: autoScalerImage, } } @@ -158,7 +156,6 @@ func init() { installCmd.Flags().StringVarP(&odigosCloudApiKeyFlag, "api-key", "k", "", "api key for odigos cloud") 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(&sidecarInstrumentation, "sidecar-instrumentation", false, "use sidecars for eBPF instrumentations") installCmd.Flags().StringVar(&odigletImage, "odiglet-image", "keyval/odigos-odiglet", "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") diff --git a/cli/cmd/resources/crds/configuration.go b/cli/cmd/resources/crds/configuration.go index bb54554b6..90e5f3a4f 100644 --- a/cli/cmd/resources/crds/configuration.go +++ b/cli/cmd/resources/crds/configuration.go @@ -76,9 +76,6 @@ func NewConfiguration() *apiextensionsv1.CustomResourceDefinition { "psp": { Type: "boolean", }, - "sidecarInstrumentation": { - Type: "boolean", - }, "telemetryEnabled": { Type: "boolean", }, diff --git a/cli/cmd/resources/instrumentor.go b/cli/cmd/resources/instrumentor.go index 233cfc248..fcc123bc8 100644 --- a/cli/cmd/resources/instrumentor.go +++ b/cli/cmd/resources/instrumentor.go @@ -375,7 +375,7 @@ func NewInstrumentorClusterRoleBinding(ns string) *rbacv1.ClusterRoleBinding { } } -func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool, sidecarInstrumentation bool, ignoredNamespaces []string, imagePrefix string, imageName string) *appsv1.Deployment { +func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool, ignoredNamespaces []string, imagePrefix string, imageName string) *appsv1.Deployment { args := []string{ "--health-probe-bind-address=:8081", "--metrics-bind-address=127.0.0.1:8080", @@ -389,10 +389,6 @@ func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool, args = append(args, "--telemetry-disabled") } - if sidecarInstrumentation { - args = append(args, "--golang-sidecar-instrumentation") - } - return &appsv1.Deployment{ TypeMeta: metav1.TypeMeta{ Kind: "Deployment", @@ -529,7 +525,7 @@ func (a *instrumentorResourceManager) InstallFromScratch(ctx context.Context) er NewInstrumentorRoleBinding(a.ns), NewInstrumentorClusterRole(), NewInstrumentorClusterRoleBinding(a.ns), - NewInstrumentorDeployment(a.ns, a.config.OdigosVersion, a.config.TelemetryEnabled, a.config.SidecarInstrumentation, a.config.IgnoredNamespaces, a.config.ImagePrefix, a.config.InstrumentorImage), + NewInstrumentorDeployment(a.ns, a.config.OdigosVersion, a.config.TelemetryEnabled, a.config.IgnoredNamespaces, a.config.ImagePrefix, a.config.InstrumentorImage), } return a.client.ApplyResources(ctx, a.config.ConfigVersion, resources) } diff --git a/common/device_names.go b/common/device_names.go new file mode 100644 index 000000000..5972d753c --- /dev/null +++ b/common/device_names.go @@ -0,0 +1,36 @@ +package common + +type OdigosInstrumentationDevice string + +const ( + JavaDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/java" + PythonDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/python" + GoDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/go" + DotNetDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/dotnet" + JavascriptDeviceName OdigosInstrumentationDevice = "instrumentation.odigos.io/javascript" +) + +var InstrumentationDevices = []OdigosInstrumentationDevice{ + JavaDeviceName, + PythonDeviceName, + GoDeviceName, + DotNetDeviceName, + JavascriptDeviceName, +} + +func ProgrammingLanguageToInstrumentationDevice(language ProgrammingLanguage) OdigosInstrumentationDevice { + switch language { + case JavaProgrammingLanguage: + return JavaDeviceName + case PythonProgrammingLanguage: + return PythonDeviceName + case GoProgrammingLanguage: + return GoDeviceName + case DotNetProgrammingLanguage: + return DotNetDeviceName + case JavascriptProgrammingLanguage: + return JavascriptDeviceName + default: + return "" + } +} diff --git a/instrumentor/controllers/common.go b/instrumentor/controllers/common.go index d820cafdb..672ef03d7 100644 --- a/instrumentor/controllers/common.go +++ b/instrumentor/controllers/common.go @@ -9,7 +9,7 @@ import ( odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" "github.com/keyval-dev/odigos/common/consts" "github.com/keyval-dev/odigos/common/utils" - "github.com/keyval-dev/odigos/instrumentor/patch" + "github.com/keyval-dev/odigos/instrumentor/instrumentation" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -55,7 +55,7 @@ func instrument(logger logr.Logger, ctx context.Context, kubeClient client.Clien return err } - return patch.ModifyObject(podSpec, runtimeDetails) + return instrumentation.ModifyObject(podSpec, runtimeDetails) }) if err != nil { @@ -95,7 +95,7 @@ func uninstrument(logger logr.Logger, ctx context.Context, kubeClient client.Cli return err } - patch.Revert(podSpec) + instrumentation.Revert(podSpec) return nil }) diff --git a/instrumentor/instrumentation/instrumentation.go b/instrumentor/instrumentation/instrumentation.go new file mode 100644 index 000000000..7a3260760 --- /dev/null +++ b/instrumentor/instrumentation/instrumentation.go @@ -0,0 +1,62 @@ +package instrumentation + +import ( + odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" + "github.com/keyval-dev/odigos/common" + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" +) + +type CollectorInfo struct { + Hostname string + Port int +} + +func ModifyObject(original *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) error { + var modifiedContainers []v1.Container + for _, container := range original.Spec.Containers { + containerLanguage := getLanguageOfContainer(instrumentation, container.Name) + if containerLanguage == nil { + continue + } + + instrumentationDeviceName := common.ProgrammingLanguageToInstrumentationDevice(*containerLanguage) + if instrumentationDeviceName == "" { + // should not happen, only for safety + continue + } + + if container.Resources.Limits == nil { + container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity) + } + container.Resources.Limits[v1.ResourceName(instrumentationDeviceName)] = resource.MustParse("1") + + modifiedContainers = append(modifiedContainers, container) + } + + original.Spec.Containers = modifiedContainers + return nil +} + +func Revert(original *v1.PodTemplateSpec) { + for _, instrumentationDevice := range common.InstrumentationDevices { + removeDeviceFromPodSpec(instrumentationDevice, original) + } +} + +func removeDeviceFromPodSpec(deviceName common.OdigosInstrumentationDevice, podSpec *v1.PodTemplateSpec) { + for _, container := range podSpec.Spec.Containers { + delete(container.Resources.Limits, v1.ResourceName(deviceName)) + delete(container.Resources.Requests, v1.ResourceName(deviceName)) + } +} + +func getLanguageOfContainer(instrumentation *odigosv1.InstrumentedApplication, containerName string) *common.ProgrammingLanguage { + for _, l := range instrumentation.Spec.Languages { + if l.ContainerName == containerName { + return &l.Language + } + } + + return nil +} diff --git a/instrumentor/main.go b/instrumentor/main.go index 84b49064d..e1bc3f267 100644 --- a/instrumentor/main.go +++ b/instrumentor/main.go @@ -24,7 +24,6 @@ import ( metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "github.com/go-logr/zapr" - "github.com/keyval-dev/odigos/instrumentor/patch" bridge "github.com/keyval-dev/opentelemetry-zap-bridge" v1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" @@ -72,7 +71,6 @@ func main() { "Enabling this will ensure there is only one active controller manager.") flag.Var(&ignoredNameSpaces, "ignore-namespace", "The ignored namespaces") flag.BoolVar(&telemetryDisabled, "telemetry-disabled", false, "Disable telemetry") - flag.BoolVar(&patch.GolangSidecarInstrumentation, "golang-sidecar-instrumentation", false, "Instrument Go applications with sidecar") opts := ctrlzap.Options{ Development: true, diff --git a/instrumentor/patch/dotnet.go b/instrumentor/patch/dotnet.go deleted file mode 100644 index d99f76dd2..000000000 --- a/instrumentor/patch/dotnet.go +++ /dev/null @@ -1,37 +0,0 @@ -package patch - -import ( - odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" - "github.com/keyval-dev/odigos/common" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" -) - -const ( - dotNetDeviceName = "instrumentation.odigos.io/dotnet" -) - -var dotNet = &dotNetPatcher{} - -type dotNetPatcher struct{} - -func (d *dotNetPatcher) Patch(podSpec *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) { - var modifiedContainers []v1.Container - for _, container := range podSpec.Spec.Containers { - if shouldPatch(instrumentation, common.DotNetProgrammingLanguage, container.Name) { - if container.Resources.Limits == nil { - container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity) - } - - container.Resources.Limits[dotNetDeviceName] = resource.MustParse("1") - } - - modifiedContainers = append(modifiedContainers, container) - } - - podSpec.Spec.Containers = modifiedContainers -} - -func (d *dotNetPatcher) Revert(podSpec *v1.PodTemplateSpec) { - removeDeviceFromPodSpec(dotNetDeviceName, podSpec) -} diff --git a/instrumentor/patch/golang.go b/instrumentor/patch/golang.go deleted file mode 100644 index d81d05595..000000000 --- a/instrumentor/patch/golang.go +++ /dev/null @@ -1,188 +0,0 @@ -package patch - -import ( - "fmt" - - odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" - "github.com/keyval-dev/odigos/common" - "github.com/keyval-dev/odigos/common/consts" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - ctrl "sigs.k8s.io/controller-runtime" -) - -const ( - golangDeviceName = "instrumentation.odigos.io/go" - golangKernelDebugVolumeName = "kernel-debug" - golangKernelDebugHostPath = "/sys/kernel/debug" - golangExporterEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT" - golangServiceNameEnv = "OTEL_SERVICE_NAME" - golangTargetExeEnv = "OTEL_GO_AUTO_TARGET_EXE" -) - -var GolangSidecarInstrumentation bool - -var golang = &golangPatcher{} - -type golangPatcher struct{} - -func (g *golangPatcher) Patch(podSpec *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) { - if GolangSidecarInstrumentation { - g.patchWithSidecar(podSpec, instrumentation) - return - } - - var modifiedContainers []v1.Container - for _, container := range podSpec.Spec.Containers { - if shouldPatch(instrumentation, common.GoProgrammingLanguage, container.Name) { - if container.Resources.Limits == nil { - container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity) - } - - container.Resources.Limits[golangDeviceName] = resource.MustParse("1") - } - - modifiedContainers = append(modifiedContainers, container) - } - - podSpec.Spec.Containers = modifiedContainers -} - -func (g *golangPatcher) Revert(podSpec *v1.PodTemplateSpec) { - if GolangSidecarInstrumentation { - g.revertWithSidecar(podSpec) - return - } - - removeDeviceFromPodSpec(golangDeviceName, podSpec) -} - -func (g *golangPatcher) patchWithSidecar(podSpec *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) { - modifiedContainers := podSpec.Spec.Containers - - for _, l := range instrumentation.Spec.Languages { - if shouldPatch(instrumentation, common.GoProgrammingLanguage, l.ContainerName) { - if l.ProcessName == "" { - ctrl.Log.V(0).Info("could not find binary path for golang application", - "container", l.ContainerName) - continue - } - - appName := l.ContainerName - if len(instrumentation.Spec.Languages) == 1 && len(instrumentation.OwnerReferences) > 0 { - appName = instrumentation.OwnerReferences[0].Name - } - - containerName := fmt.Sprintf("%s-instrumentation", l.ContainerName) - if g.isContainerExists(podSpec, containerName) { - continue - } - - bpfContainer := v1.Container{ - Name: containerName, - Image: consts.GolangInstrumentationImage, - Env: []v1.EnvVar{ - { - Name: NodeIPEnvName, - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: "status.hostIP", - }, - }, - }, - { - Name: golangExporterEndpoint, - Value: fmt.Sprintf("http://%s:%d", HostIPEnvValue, consts.OTLPPort), - }, - { - Name: golangServiceNameEnv, - Value: appName, - }, - { - Name: golangTargetExeEnv, - Value: l.ProcessName, - }, - }, - VolumeMounts: []v1.VolumeMount{ - { - Name: golangKernelDebugVolumeName, - MountPath: golangKernelDebugHostPath, - }, - }, - SecurityContext: &v1.SecurityContext{ - Capabilities: &v1.Capabilities{ - Add: []v1.Capability{ - "SYS_PTRACE", - }, - }, - Privileged: boolPtr(true), - RunAsUser: intPtr(0), - }, - } - - modifiedContainers = append(modifiedContainers, bpfContainer) - } - } - - podSpec.Spec.Containers = modifiedContainers - podSpec.Spec.ShareProcessNamespace = boolPtr(true) - - if !g.isVolumeExists(podSpec, golangKernelDebugVolumeName) { - podSpec.Spec.Volumes = append(podSpec.Spec.Volumes, v1.Volume{ - Name: golangKernelDebugVolumeName, - VolumeSource: v1.VolumeSource{ - HostPath: &v1.HostPathVolumeSource{ - Path: golangKernelDebugHostPath, - }, - }, - }) - } -} - -func (g *golangPatcher) revertWithSidecar(podSpec *v1.PodTemplateSpec) { - for i, c := range podSpec.Spec.Containers { - if c.Image == consts.GolangInstrumentationImage { - podSpec.Spec.Containers = append(podSpec.Spec.Containers[:i], podSpec.Spec.Containers[i+1:]...) - break - } - } - - if podSpec.Spec.ShareProcessNamespace != nil && *podSpec.Spec.ShareProcessNamespace { - podSpec.Spec.ShareProcessNamespace = nil - } - - for i, v := range podSpec.Spec.Volumes { - if v.Name == golangKernelDebugVolumeName { - podSpec.Spec.Volumes = append(podSpec.Spec.Volumes[:i], podSpec.Spec.Volumes[i+1:]...) - break - } - } -} - -func (g *golangPatcher) isContainerExists(podSpec *v1.PodTemplateSpec, containerName string) bool { - for _, c := range podSpec.Spec.Containers { - if c.Name == containerName { - return true - } - } - - return false -} - -func (g *golangPatcher) isVolumeExists(podSpec *v1.PodTemplateSpec, volumeName string) bool { - for _, v := range podSpec.Spec.Volumes { - if v.Name == volumeName { - return true - } - } - - return false -} - -func boolPtr(b bool) *bool { - return &b -} - -func intPtr(n int64) *int64 { - return &n -} diff --git a/instrumentor/patch/java.go b/instrumentor/patch/java.go deleted file mode 100644 index 9f1579401..000000000 --- a/instrumentor/patch/java.go +++ /dev/null @@ -1,37 +0,0 @@ -package patch - -import ( - odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" - "github.com/keyval-dev/odigos/common" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" -) - -const ( - javaDeviceName = "instrumentation.odigos.io/java" -) - -var java = &javaPatcher{} - -type javaPatcher struct{} - -func (j *javaPatcher) Patch(podSpec *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) { - var modifiedContainers []v1.Container - for _, container := range podSpec.Spec.Containers { - if shouldPatch(instrumentation, common.JavaProgrammingLanguage, container.Name) { - if container.Resources.Limits == nil { - container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity) - } - - container.Resources.Limits[javaDeviceName] = resource.MustParse("1") - } - - modifiedContainers = append(modifiedContainers, container) - } - - podSpec.Spec.Containers = modifiedContainers -} - -func (j *javaPatcher) Revert(podSpec *v1.PodTemplateSpec) { - removeDeviceFromPodSpec(javaDeviceName, podSpec) -} diff --git a/instrumentor/patch/nodejs.go b/instrumentor/patch/nodejs.go deleted file mode 100644 index 124fb8870..000000000 --- a/instrumentor/patch/nodejs.go +++ /dev/null @@ -1,37 +0,0 @@ -package patch - -import ( - odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" - "github.com/keyval-dev/odigos/common" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" -) - -const ( - nodeJsDeviceName = "instrumentation.odigos.io/nodejs" -) - -var nodeJs = &nodeJsPatcher{} - -type nodeJsPatcher struct{} - -func (n *nodeJsPatcher) Patch(podSpec *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) { - var modifiedContainers []v1.Container - for _, container := range podSpec.Spec.Containers { - if shouldPatch(instrumentation, common.JavascriptProgrammingLanguage, container.Name) { - if container.Resources.Limits == nil { - container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity) - } - - container.Resources.Limits[nodeJsDeviceName] = resource.MustParse("1") - } - - modifiedContainers = append(modifiedContainers, container) - } - - podSpec.Spec.Containers = modifiedContainers -} - -func (n *nodeJsPatcher) Revert(podSpec *v1.PodTemplateSpec) { - removeDeviceFromPodSpec(nodeJsDeviceName, podSpec) -} diff --git a/instrumentor/patch/python.go b/instrumentor/patch/python.go deleted file mode 100644 index 7a40fab46..000000000 --- a/instrumentor/patch/python.go +++ /dev/null @@ -1,37 +0,0 @@ -package patch - -import ( - odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" - "github.com/keyval-dev/odigos/common" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" -) - -const ( - pythonDeviceName = "instrumentation.odigos.io/python" -) - -var python = &pythonPatcher{} - -type pythonPatcher struct{} - -func (p *pythonPatcher) Patch(podSpec *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) { - var modifiedContainers []v1.Container - for _, container := range podSpec.Spec.Containers { - if shouldPatch(instrumentation, common.PythonProgrammingLanguage, container.Name) { - if container.Resources.Limits == nil { - container.Resources.Limits = make(map[v1.ResourceName]resource.Quantity) - } - - container.Resources.Limits[pythonDeviceName] = resource.MustParse("1") - } - - modifiedContainers = append(modifiedContainers, container) - } - - podSpec.Spec.Containers = modifiedContainers -} - -func (p *pythonPatcher) Revert(podSpec *v1.PodTemplateSpec) { - removeDeviceFromPodSpec(pythonDeviceName, podSpec) -} diff --git a/instrumentor/patch/root.go b/instrumentor/patch/root.go deleted file mode 100644 index 1ed1653a3..000000000 --- a/instrumentor/patch/root.go +++ /dev/null @@ -1,82 +0,0 @@ -package patch - -import ( - "fmt" - odigosv1 "github.com/keyval-dev/odigos/api/odigos/v1alpha1" - "github.com/keyval-dev/odigos/common" - v1 "k8s.io/api/core/v1" -) - -const ( - NodeIPEnvName = "NODE_IP" - HostIPEnvValue = "$(NODE_IP)" -) - -type CollectorInfo struct { - Hostname string - Port int -} - -type Patcher interface { - Patch(podSpec *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) - Revert(podSpec *v1.PodTemplateSpec) -} - -var patcherMap = map[common.ProgrammingLanguage]Patcher{ - common.JavaProgrammingLanguage: java, - common.PythonProgrammingLanguage: python, - common.DotNetProgrammingLanguage: dotNet, - common.JavascriptProgrammingLanguage: nodeJs, - common.GoProgrammingLanguage: golang, -} - -func ModifyObject(original *v1.PodTemplateSpec, instrumentation *odigosv1.InstrumentedApplication) error { - for _, l := range getLangsInResult(instrumentation) { - p, exists := patcherMap[l] - if !exists { - return fmt.Errorf("unable to find patcher for lang %s", l) - } - - p.Patch(original, instrumentation) - } - - return nil -} - -func Revert(original *v1.PodTemplateSpec) { - for _, p := range patcherMap { - p.Revert(original) - } -} - -func removeDeviceFromPodSpec(deviceName v1.ResourceName, podSpec *v1.PodTemplateSpec) { - for _, container := range podSpec.Spec.Containers { - delete(container.Resources.Limits, deviceName) - delete(container.Resources.Requests, deviceName) - } -} - -func getLangsInResult(instrumentation *odigosv1.InstrumentedApplication) []common.ProgrammingLanguage { - langMap := make(map[common.ProgrammingLanguage]interface{}) - for _, c := range instrumentation.Spec.Languages { - langMap[c.Language] = nil - } - - var langs []common.ProgrammingLanguage - for l, _ := range langMap { - langs = append(langs, l) - } - - return langs -} - -func shouldPatch(instrumentation *odigosv1.InstrumentedApplication, lang common.ProgrammingLanguage, containerName string) bool { - for _, l := range instrumentation.Spec.Languages { - if l.ContainerName == containerName && l.Language == lang { - // TODO: Handle CGO - return true - } - } - - return false -}