-
Notifications
You must be signed in to change notification settings - Fork 345
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
Scan deployments for agent injection #454
Conversation
9fb00b9
to
875263a
Compare
pkg/inject/sidecar.go
Outdated
if Needed(dep) { | ||
if belongsToJaegerInstance(dep, jaeger, len(pods.Items) == 1) { | ||
// a suitable jaeger instance was found! let's inject a sidecar pointing to it then | ||
log.WithFields(log.Fields{ |
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 think you can call logger on jaeger instance jager.Log()
pkg/inject/sidecar.go
Outdated
@@ -177,3 +177,34 @@ func hasEnv(name string, vars []corev1.EnvVar) bool { | |||
} | |||
return false | |||
} | |||
|
|||
// RequireInjections deployments |
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.
a better comment?
return nil | ||
} | ||
|
||
func (r *ReconcileJaeger) scanDeployments(jaeger v1.Jaeger) 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.
What does the func do? Does it scan for something or does it add sidecars?
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.
The name is wrong, not intuitive at all, sorry
It suppose to add the sidecar for deployments that require that. But I think I found a better way for do this.
@rubenvp8510, are you still interested in working on this one? We might change in the future to use the webhook approach, which would render this one here obsolete, but this is indeed fixing a bug we have right now, IIRC. |
We now have an auto-detect package ( |
@jpkrohling Yes I want to update this PR, I'll check the autodetect stuff and update this. Thanks! |
3adaea1
to
03ee9fb
Compare
@jpkrohling I'm not totally convinced of using auto-detect feature on this, I updated the code, now the actual code uses that feature. but I need to get all deployments and scan for updates/injections. Not sure if it's a better way to do it, I have the problem that I cannot query on annotations. |
075fee2
to
f79e48c
Compare
@rubenvp8510, wasn't this implemented in another PR? Should this one be closed? |
@jpkrohling this is another issue, I think you are confusing this PR with #453, which is the opposite. This is about to inject the agent on existing deployments, the other is about deletion. Not sure what is the decision regarding of this PR, Do we want to proceed in this way ?or are we going to work more on webhook admission controller? |
f79e48c
to
983680d
Compare
Signed-off-by: Ruben Vargas <[email protected]>
983680d
to
72d05d8
Compare
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.
Had a comment about reusing some code. Other than that, LGTM.
@@ -77,6 +77,54 @@ func (b *Background) Stop() { | |||
b.ticker.Stop() | |||
} | |||
|
|||
func (b *Background) requireUpdates(deps *appsv1.DeploymentList) []*appsv1.Deployment { | |||
instances := &v1.JaegerList{} |
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.
Could you leave a comment in the func, saying that this is related to the Deployment
controller, but that this here exists only because the Jaeger Operator might not be up and running when the deployment was created/updated/annotated?
return nil | ||
} | ||
requireUpdates := make([]*appsv1.Deployment, 0) | ||
for i := 0; i < len(deps.Items); i++ { |
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.
The code within this loop is pretty much the same as the existing controller, isn't it:
jaeger-operator/pkg/controller/deployment/deployment_controller.go
Lines 84 to 111 in b6211a4
if inject.Needed(instance) { | |
pods := &v1.JaegerList{} | |
opts := []client.ListOption{} | |
err := r.client.List(context.Background(), pods, opts...) | |
if err != nil { | |
log.WithError(err).Error("failed to get the available Jaeger pods") | |
return reconcile.Result{}, err | |
} | |
jaeger := inject.Select(instance, pods) | |
if jaeger != nil && jaeger.GetDeletionTimestamp() == nil { | |
// a suitable jaeger instance was found! let's inject a sidecar pointing to it then | |
// Verified that jaeger instance was found and is not marked for deletion. | |
log.WithFields(log.Fields{ | |
"deployment": instance.Name, | |
"namespace": instance.Namespace, | |
"jaeger": jaeger.Name, | |
"jaeger-namespace": jaeger.Namespace, | |
}).Info("Injecting Jaeger Agent sidecar") | |
instance = inject.Sidecar(jaeger, instance) | |
if err := r.client.Update(context.Background(), instance); err != nil { | |
log.WithField("deployment", instance).WithError(err).Error("failed to update") | |
return reconcile.Result{}, err | |
} | |
} else { | |
log.WithField("deployment", instance.Name).Info("No suitable Jaeger instances found to inject a sidecar") | |
} | |
} |
In that case, it would probably make sense to externalize that into its own func, and call it from both places (this here and the controller shown above)
@@ -62,6 +62,17 @@ func Sidecar(jaeger *v1.Jaeger, dep *appsv1.Deployment) *appsv1.Deployment { | |||
return dep | |||
} | |||
|
|||
// UpdateSideCar modify the deployment side car with the latest parameters if it's required. | |||
func UpdateSideCar(jaeger *v1.Jaeger, dep *appsv1.Deployment) bool { |
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.
s/SideCar/Sidecar
@rubenvp8510 do you want to merge this, and address the remaining comments in a follow-up PR? |
Yes please! :) |
Merged. Please, create an issue to track the remaining points. |
No description provided.