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

enterprise instrumentor adjustments #2464

Merged
merged 10 commits into from
Feb 21, 2025
4 changes: 3 additions & 1 deletion api/k8sconsts/instrumentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package k8sconsts
const (
InstrumentorOtelServiceName = "instrumentor"
InstrumentorDeploymentName = "odigos-instrumentor"
InstrumentorImage = "odigos-instrumentor"
InstrumentorEnterpriseImage = "odigos-enterprise-instrumentor"
InstrumentorImageUBI9 = "odigos-instrumentor-ubi9"
InstrumentorImageName = "odigos-instrumentor"
InstrumentorEnterpriseImageUBI9 = "odigos-enterprise-instrumentor-ubi9"
InstrumentorAppLabelValue = InstrumentorDeploymentName
InstrumentorServiceName = InstrumentorDeploymentName
InstrumentorServiceAccountName = InstrumentorDeploymentName
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func init() {
installCmd.Flags().BoolVar(&openshiftEnabled, "openshift", false, "configure requirements for OpenShift: required selinux settings, RBAC roles, and will use OpenShift certified images (if --image-prefix is not set)")
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", k8sconsts.InstrumentorImageName, "instrumentor container image name")
installCmd.Flags().StringVar(&instrumentorImage, "instrumentor-image", k8sconsts.InstrumentorImage, "instrumentor container image name")
installCmd.Flags().StringVar(&autoScalerImage, "autoscaler-image", k8sconsts.AutoScalerImageName, "autoscaler container image name")
installCmd.Flags().StringVar(&imagePrefix, "image-prefix", "registry.odigos.io", "prefix for all container images.")
installCmd.Flags().BoolVar(&psp, "psp", false, "enable pod security policy")
Expand Down
39 changes: 33 additions & 6 deletions cli/cmd/resources/instrumentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/odigos-io/odigos/api/k8sconsts"
"github.com/odigos-io/odigos/cli/cmd/resources/odigospro"
"github.com/odigos-io/odigos/cli/cmd/resources/resourcemanager"
"github.com/odigos-io/odigos/cli/pkg/containers"
"github.com/odigos-io/odigos/cli/pkg/crypto"
Expand Down Expand Up @@ -471,7 +472,7 @@ func NewInstrumentorTLSSecret(ns string, cert *crypto.Certificate) *corev1.Secre
}
}

func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool, imagePrefix string, imageName string) *appsv1.Deployment {
func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool, imagePrefix string, imageName string, tier common.OdigosTier) *appsv1.Deployment {
args := []string{
"--health-probe-bind-address=:8081",
"--metrics-bind-address=127.0.0.1:8080",
Expand All @@ -482,6 +483,13 @@ func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool,
args = append(args, "--telemetry-disabled")
}

dynamicEnv := []corev1.EnvVar{}
if tier == common.CloudOdigosTier {
dynamicEnv = append(dynamicEnv, odigospro.CloudTokenAsEnvVar())
} else if tier == common.OnPremOdigosTier {
dynamicEnv = append(dynamicEnv, odigospro.OnPremTokenAsEnvVar())
}

dep := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
Expand Down Expand Up @@ -536,7 +544,7 @@ func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool,
"/app",
},
Args: args,
Env: []corev1.EnvVar{
Env: append([]corev1.EnvVar{
{
Name: "OTEL_SERVICE_NAME",
Value: k8sconsts.InstrumentorOtelServiceName,
Expand All @@ -549,6 +557,8 @@ func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool,
},
},
},
// TODO: this tier env var should be removed once we complete the transition to
// enterprise and community images, and the webhook code won't rely on this env var
{
Name: consts.OdigosTierEnvVarName,
ValueFrom: &corev1.EnvVarSource{
Expand All @@ -560,7 +570,7 @@ func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool,
},
},
},
},
}, dynamicEnv...),
EnvFrom: []corev1.EnvFromSource{
{
ConfigMapRef: &corev1.ConfigMapEnvSource{
Expand Down Expand Up @@ -620,7 +630,7 @@ func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool,
},
},
},
PeriodSeconds: 10,
PeriodSeconds: 10,
},
SecurityContext: &corev1.SecurityContext{},
},
Expand Down Expand Up @@ -668,28 +678,45 @@ type instrumentorResourceManager struct {
ns string
config *common.OdigosConfiguration
odigosVersion string
tier common.OdigosTier
}

func NewInstrumentorResourceManager(client *kube.Client, ns string, config *common.OdigosConfiguration, odigosVersion string) resourcemanager.ResourceManager {
func NewInstrumentorResourceManager(client *kube.Client, ns string, config *common.OdigosConfiguration, tier common.OdigosTier, odigosVersion string) resourcemanager.ResourceManager {
return &instrumentorResourceManager{
client: client,
ns: ns,
config: config,
odigosVersion: odigosVersion,
tier: tier,
}
}

func (a *instrumentorResourceManager) Name() string { return "Instrumentor" }

func (a *instrumentorResourceManager) InstallFromScratch(ctx context.Context) error {
imageName := a.config.InstrumentorImage
if imageName == "" || imageName == k8sconsts.InstrumentorImage || imageName == k8sconsts.InstrumentorImageUBI9 {
if a.tier == common.CommunityOdigosTier {
if imageName != k8sconsts.InstrumentorImageUBI9 {
imageName = k8sconsts.InstrumentorImage
}
} else {
if imageName == k8sconsts.InstrumentorImageUBI9 {
imageName = k8sconsts.InstrumentorEnterpriseImageUBI9
} else {
imageName = k8sconsts.InstrumentorEnterpriseImage
}
}
}

resources := []kube.Object{
NewInstrumentorServiceAccount(a.ns),
NewInstrumentorLeaderElectionRoleBinding(a.ns),
NewInstrumentorRole(a.ns),
NewInstrumentorRoleBinding(a.ns),
NewInstrumentorClusterRole(a.config.OpenshiftEnabled),
NewInstrumentorClusterRoleBinding(a.ns),
NewInstrumentorDeployment(a.ns, a.odigosVersion, a.config.TelemetryEnabled, a.config.ImagePrefix, a.config.InstrumentorImage),
NewInstrumentorDeployment(a.ns, a.odigosVersion, a.config.TelemetryEnabled, a.config.ImagePrefix, a.config.InstrumentorImage, a.tier),
NewInstrumentorService(a.ns),
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/resources/managers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func CreateResourceManagers(client *kube.Client, odigosNs string, odigosTier com
resourceManagers = append(resourceManagers, []resourcemanager.ResourceManager{
NewOwnTelemetryResourceManager(client, odigosNs, config, odigosTier, odigosVersion),
NewDataCollectionResourceManager(client, odigosNs, config),
NewInstrumentorResourceManager(client, odigosNs, config, odigosVersion),
NewInstrumentorResourceManager(client, odigosNs, config, odigosTier, odigosVersion),
NewSchedulerResourceManager(client, odigosNs, config, odigosVersion),
NewOdigletResourceManager(client, odigosNs, config, odigosTier, odigosVersion),
NewAutoScalerResourceManager(client, odigosNs, config, odigosVersion),
Expand Down
31 changes: 6 additions & 25 deletions distros/oteldistributions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@ type communityDefaulter struct{}

var _ Defaulter = &communityDefaulter{}

// TODO: remove/rename this once we have an enterprise instrumentor
func NewCommunityDefaulter() *communityDefaulter {
func NewCommunityDefaulter() Defaulter {
return &communityDefaulter{}
}

// TODO: remove this once we have an enterprise instrumentor
func NewOnPremDefaulter() *onPremDefaulter {
return &onPremDefaulter{}
func NewCommunityGetter() (*Getter, error) {
return NewGetterFromFS(yamls.GetFS())
}

// TODO: once we split the distros package this should be renamed
func NewGetter() (*Getter, error) {
func NewGetterFromFS(fs embed.FS) (*Getter, error) {
g := Getter{}

distrosByName, err := getDistrosMap(yamls.GetFS())
distrosByName, err := GetDistrosMap(fs)
if err != nil {
return nil, err
}
Expand All @@ -54,22 +51,6 @@ func (c *communityDefaulter) GetDefaultDistroNames() map[common.ProgrammingLangu
}
}

// TODO: remove this once we have an enterprise instrumentor
type onPremDefaulter struct{}

var _ Defaulter = &onPremDefaulter{}

func (o *onPremDefaulter) GetDefaultDistroNames() map[common.ProgrammingLanguage]string {
return map[common.ProgrammingLanguage]string{
common.JavascriptProgrammingLanguage: "nodejs-enterprise",
common.PythonProgrammingLanguage: "python-enterprise",
common.DotNetProgrammingLanguage: "dotnet-community",
common.JavaProgrammingLanguage: "java-enterprise",
common.GoProgrammingLanguage: "golang-enterprise",
common.MySQLProgrammingLanguage: "mysql-enterprise",
}
}

type Getter struct {
distrosByName map[string]*distro.OtelDistro
}
Expand Down Expand Up @@ -125,7 +106,7 @@ type distroResource struct {
Spec distro.OtelDistro `json:"spec"`
}

func getDistrosMap(fs embed.FS) (map[string]*distro.OtelDistro, error) {
func GetDistrosMap(fs embed.FS) (map[string]*distro.OtelDistro, error) {
files, err := fs.ReadDir(".")
if err != nil {
return nil, err
Expand Down
13 changes: 12 additions & 1 deletion helm/odigos/templates/instrumentor/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ spec:
command:
- /app
{{ $imageTag := .Values.image.tag | default .Chart.AppVersion }}
{{- if .Values.onPremToken }}
image: {{ template "utils.imageName" (dict "Values" .Values "Component" "enterprise-instrumentor" "Tag" $imageTag) }}
{{- else }}
image: {{ template "utils.imageName" (dict "Values" .Values "Component" "instrumentor" "Tag" $imageTag) }}
{{- end }}
ports:
- containerPort: 9443
name: webhook-server
Expand All @@ -50,7 +54,14 @@ spec:
valueFrom:
configMapKeyRef:
key: ODIGOS_TIER
name: odigos-deployment
name: odigos-deployment
{{- if .Values.onPremToken }}
- name: ODIGOS_ONPREM_TOKEN
valueFrom:
secretKeyRef:
name: odigos-pro
key: odigos-onprem-token
{{- end }}
volumeMounts:
- name: webhook-cert
mountPath: /tmp/k8s-webhook-server/serving-certs
Expand Down
19 changes: 2 additions & 17 deletions instrumentor/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ import (
"flag"
"os"

"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/distros"

"github.com/odigos-io/odigos/instrumentor/controllers"
"github.com/odigos-io/odigos/instrumentor/sdks"
"github.com/odigos-io/odigos/k8sutils/pkg/env"

"sigs.k8s.io/controller-runtime/pkg/manager/signals"

Expand Down Expand Up @@ -70,25 +68,12 @@ func main() {
// TODO: remove once the webhook stops using the default SDKs from the sdks package
sdks.SetDefaultSDKs()

// TODO: remove once we create an enterprise instrumentor
tier := env.GetOdigosTierFromEnv()
var defaulter distros.Defaulter
switch tier {
case common.CommunityOdigosTier:
defaulter = distros.NewCommunityDefaulter()
case common.OnPremOdigosTier:
defaulter = distros.NewOnPremDefaulter()
default:
setupLog.Error(nil, "Invalid tier", "tier", tier)
os.Exit(1)
}

distrosGetter, err := distros.NewGetter()
distrosGetter, err := distros.NewCommunityGetter()
if err != nil {
setupLog.Error(err, "Failed to initialize distro getter")
os.Exit(1)
}
dp, err := distros.NewProvider(defaulter, distrosGetter)
dp, err := distros.NewProvider(distros.NewCommunityDefaulter(), distrosGetter)
if err != nil {
setupLog.Error(err, "Failed to initialize distro provider")
os.Exit(1)
Expand Down
Loading