-
Notifications
You must be signed in to change notification settings - Fork 208
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
[GEN-2267] chore: move limit device injection into webhook #2307
base: main
Are you sure you want to change the base?
[GEN-2267] chore: move limit device injection into webhook #2307
Conversation
…ntainer Task 149 sources container
…play-source-manage-list
…urces-card Task 107 overview sources card
…rce-manage-list Task 142 display source manage list
…rce-btn Task 143 add new source btn
…sources-connection Task 145 handle new sources connection
|
||
pl, otelsdk, found := containerutils.GetLanguageAndOtelSdk(container) | ||
otelSdk, found := sdks.GetDefaultSDKs()[pl] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to also address instrumentationrules.
if !found { | ||
fmt.Println("No default SDK found for language", pl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no fmt.Println
continue | ||
} | ||
|
||
webhookenvinjector.InjectOdigosAgentEnvVars(ctx, p.Client, logger, *podWorkload, container, pl, otelsdk) | ||
webhookdeviceinjector.InjectOdigosInstrumentationDevice(ctx, p.Client, logger, *podWorkload, container, pl, otelSdk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function name is injectOdigosEnvVars
.
consider moving this logic to a different function with good name
var workloadInstrumentationConfig odigosv1.InstrumentationConfig | ||
instrumentationConfigName := workload.CalculateWorkloadRuntimeObjectName(podWorkload.Name, podWorkload.Kind) | ||
|
||
if err := p.Get(ctx, client.ObjectKey{Namespace: podWorkload.Namespace, Name: instrumentationConfigName}, &workloadInstrumentationConfig); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are already getting the instrumentation config for the service name.
could be nice to do it only once and use the same object in both places
func getLibCTypeOfContainer(ctx context.Context, p client.Client, logger logr.Logger, podWorkload workload.PodWorkload, containerName string) *common.LibCType { | ||
|
||
var instConfig v1alpha1.InstrumentationConfig | ||
err := p.Get(ctx, client.ObjectKey{Namespace: podWorkload.Namespace, Name: workload.CalculateWorkloadRuntimeObjectName(podWorkload.Name, podWorkload.Kind)}, &instConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the instrumentation config that we already "get" before
} | ||
|
||
// Find the matching container runtime details | ||
for _, rd := range instConfig.Status.RuntimeDetailsByContainer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider merging this one with getLanguageOfContainer
// devicePartiallyApplied is used to indicate that the instrumentation device was partially applied for some of the containers. | ||
devicePartiallyApplied := false | ||
deviceNotAppliedDueToPresenceOfAnotherAgent := false | ||
func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.Client, instConfig *odigosv1.InstrumentationConfig) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider giving this function a better name now that it's no longer addressing instrumentation device
instrumentation.SetInjectInstrumentationLabel(podSpec) | ||
} | ||
// add odigos.io/inject-instrumentation label to enable the webhook | ||
instrumentation.SetInjectInstrumentationLabel(podSpec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if device is skipped, we must not inject the instrumentation label
} | ||
|
||
if err != nil { | ||
return err, false | ||
return err | ||
} | ||
|
||
modified := result != controllerutil.OperationResultNone | ||
if modified { | ||
logger.V(0).Info("added instrumentation device to workload", "name", obj.GetName(), "namespace", obj.GetNamespace()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.V(0).Info("added instrumentation device to workload", "name", obj.GetName(), "namespace", obj.GetNamespace()) | |
logger.V(0).Info("added inject instrumentation label to workload pod template", "name", obj.GetName(), "namespace", obj.GetNamespace()) |
No description provided.