-
Notifications
You must be signed in to change notification settings - Fork 452
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
Inject otelcol sidecar into any namespace #1395
Inject otelcol sidecar into any namespace #1395
Conversation
b162b23
to
d208aee
Compare
func ReplaceConfig(params Params) (string, error) { | ||
if !params.Instance.Spec.TargetAllocator.Enabled { | ||
return params.Instance.Spec.Config, nil | ||
func ReplaceConfig(instance v1alpha1.OpenTelemetryCollector) (string, 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.
Changing the API bc the function uses only the otelcol instance
pkg/sidecar/pod.go
Outdated
otelColCfgStr := base64.StdEncoding.EncodeToString([]byte(otelColCfg)) | ||
|
||
// add the container | ||
pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{ |
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.
@jaronoff97 @Aneurysm9 could you please take a look and give me 👍🏼 on the approach?
The approach was chosen to avoid copying otelcol config map to the namespace where the injection is enabled and as well avoid issues with cleaning the config map.
My notes:
- owner reference cannot reference objects from a different namespace
- when a pod is created directly it does not have any owner references
Once we agree I will make the init container image configurable via a flag on the operator (if needed expose it in the CR as well).
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.
Can you expand on the concerns with using config maps? While the proposed system appears to work, it's got more moving parts than I like.
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.
Basically I have nothing against the initcontainer solution, but I would prefer a uniform solution for internal and external namespaces. Otherwise there is the possibility that the implementations drift apart.
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.
Can you expand on the concerns with using config maps?
Correctly implementing the config map approach for the sidecar is tricky:
- The sidecar config map would have to be created in the target namespace.
- A custom cleaning would have to be implemented. An owner reference to
otelcol
cannot be used (it's a cross namespace) nor owner reference to a pod (a pod UID is not known in the admission webhook).
The init container approach is a cleaner approach because no cleaning is required and the exact sidecar configuration is known (via the OTEL_CONFIG
env var and cat config.yaml
in the initContainer
). In the current implementation in the main
branch it is hard to figure out what is the already injected sidecar configuration if the otelcol
CR changes.
but I would prefer a uniform solution for internal and external namespaces. Otherwise there is the possibility that the implementations drift apart.
The init container approach that this PR introduces is used for both internal and external namespaces. There are as well tests (unit+e2e) to ensure the solution works. The deployment/statefulset/daemonset deployment modes keep using the mounted configmap as before - which makes perfect sense bc there is only a single version of the "instance".
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.
Discussed with @pavolloffay OOB and I recommend setting the configuration in an environment variable on the collector container and using the config from there by setting the argument --config=env:OTEL_CONFIG
. This avoids the need for an init container simply to copy the config and leaves nothing additional to clean up.
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.
It was a great suggestion, I didn't know that --config=env:OTEL_CONFIG
is supported.
I have changed the PR to use this approach without the init container.
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.
I just had two questions/concerns, otherwise I think this approach makes sense.
dc27064
to
270c833
Compare
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
49f9c5f
to
9facb62
Compare
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay <[email protected]>
* Inject otelcol sidecar into any namespace Signed-off-by: Pavol Loffay <[email protected]> * review comments Signed-off-by: Pavol Loffay <[email protected]> * review comments Signed-off-by: Pavol Loffay <[email protected]> * Consume otelcol config directly from env var Signed-off-by: Pavol Loffay <[email protected]> * Fix lint Signed-off-by: Pavol Loffay <[email protected]> * revert Signed-off-by: Pavol Loffay <[email protected]> * revert init prepper image Signed-off-by: Pavol Loffay <[email protected]> * Change order Signed-off-by: Pavol Loffay <[email protected]> --------- Signed-off-by: Pavol Loffay <[email protected]>
Signed-off-by: Pavol Loffay [email protected]
Resolves #199
otelcol
sidecar into any namespace - currently the sidecar can be injected into workloads that are in the same namespace as theotelcol
CR.sidecar.opentelemetry.io/inject: "default/simplest"
(default
is the namespace)Tested on with:
Result: