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

Fix Pod Mutation loop #953

Merged
merged 10 commits into from
Jul 4, 2022

Conversation

mat-rumian
Copy link
Contributor

Functionality changes:

  • added check if Pod is already instrumented (check if auto-instrumentation initContainer exists)
  • added check for instrumentation volume mount to the container
  • added check for instrumentation specific environment variable value

PR fixes #940

@mat-rumian mat-rumian requested a review from a team June 27, 2022 21:15
internal/webhookhandler/helper.go Outdated Show resolved Hide resolved
internal/webhookhandler/helper.go Outdated Show resolved Hide resolved
pkg/instrumentation/helper.go Outdated Show resolved Hide resolved
internal/webhookhandler/webhookhandler.go Outdated Show resolved Hide resolved
internal/webhookhandler/helper.go Outdated Show resolved Hide resolved
Copy link
Contributor

@yuriolisa yuriolisa left a comment

Choose a reason for hiding this comment

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

LGTM.

pkg/instrumentation/helper.go Outdated Show resolved Hide resolved
pkg/instrumentation/helper.go Outdated Show resolved Hide resolved
pkg/instrumentation/javaagent.go Outdated Show resolved Hide resolved
}
}

if IsOtAIVolumeMissing(container.VolumeMounts) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this check needed?

The IsAutoInstrumentationInjected is not enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So IsOtAIVolumeMissing and IsEnvVarValueInstrumentationMissing were applied before I've added check for pod mutation. When Pod was mutated few times k8s was throwing errors like duplicated volume name. In case of env var it happened that e.g. javaJVMArgument was added few times to JAVA_TOOL_OPTIONS. So I left this checks for safety for other unexpected mutations.

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to remove this and IsEnvVarValueInstrumentationMissing as well and rely only on the init container for simplicity.

We should keep it here only if there is a known scenario which the init container does not cover

for _, initContainer := range pod.Spec.InitContainers {
if initContainer.Name == initContainerName {
return false
}
}
return true
}

// Checks if Pod is already instrumented by checking Instrumentation InitContainer presence.
func isAutoInstrumentationInjected(pod corev1.Pod) bool {
Copy link
Member

Choose a reason for hiding this comment

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

nit: this function is almost the same as isInitContainerMissing

@pavolloffay pavolloffay merged commit 4c96e3f into open-telemetry:main Jul 4, 2022
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
* chore(webhookhandler): check if pod already instrumented

* chore(instrumentations): add check for volume and instrumentation env var value

* chore(webhookhandler): add helper tests

* chore(instrumentation): add helper tests

* chore(instrumentation): update volume checking method

* chore(lint): fix

* chore(webhookhandler): move out pod instrumentation check

* chore(instrumentation): add pod instrumentation inject check

* chore(instrumentation): clean up
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.

Auto-instrumentation - never ending pod mutation
3 participants