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

Scan deployments for agent injection #454

Merged
merged 1 commit into from
Nov 15, 2019

Conversation

rubenvp8510
Copy link
Collaborator

No description provided.

@rubenvp8510 rubenvp8510 force-pushed the Issue-442 branch 2 times, most recently from 9fb00b9 to 875263a Compare May 30, 2019 17:16
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{
Copy link
Member

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

@@ -177,3 +177,34 @@ func hasEnv(name string, vars []corev1.EnvVar) bool {
}
return false
}

// RequireInjections deployments
Copy link
Member

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

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?

Copy link
Collaborator Author

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.

@jpkrohling
Copy link
Contributor

@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.

@jpkrohling
Copy link
Contributor

We now have an auto-detect package (pkg/autodetect) with a process that runs periodically in the background. If you decide to continue working on this one, it would be good to use that feature.

@rubenvp8510
Copy link
Collaborator Author

@jpkrohling Yes I want to update this PR, I'll check the autodetect stuff and update this.

Thanks!

@rubenvp8510
Copy link
Collaborator Author

@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.

@rubenvp8510 rubenvp8510 force-pushed the Issue-442 branch 2 times, most recently from 075fee2 to f79e48c Compare July 31, 2019 20:38
@jpkrohling
Copy link
Contributor

@rubenvp8510, wasn't this implemented in another PR? Should this one be closed?

@rubenvp8510
Copy link
Collaborator Author

@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?

Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
Copy link
Contributor

@jpkrohling jpkrohling left a 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{}
Copy link
Contributor

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++ {
Copy link
Contributor

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:

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

Choose a reason for hiding this comment

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

s/SideCar/Sidecar

@jpkrohling
Copy link
Contributor

@rubenvp8510 do you want to merge this, and address the remaining comments in a follow-up PR?

@rubenvp8510
Copy link
Collaborator Author

@rubenvp8510 do you want to merge this, and address the remaining comments in a follow-up PR?

Yes please! :)

@jpkrohling jpkrohling merged commit 89c439e into jaegertracing:master Nov 15, 2019
@jpkrohling
Copy link
Contributor

Merged. Please, create an issue to track the remaining points.

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