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

[GEN-2267] chore: move limit device injection into webhook #2307

Open
wants to merge 247 commits into
base: main
Choose a base branch
from

Conversation

alonkeyval
Copy link
Collaborator

No description provided.

Copy link


pl, otelsdk, found := containerutils.GetLanguageAndOtelSdk(container)
otelSdk, found := sdks.GetDefaultSDKs()[pl]
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

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 {
Copy link
Collaborator

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)
Copy link
Collaborator

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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)
Copy link
Collaborator

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())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants