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

Reuse inject function from deployment controller into autodetect #792

Closed
wants to merge 1 commit into from

Conversation

rubenvp8510
Copy link
Collaborator

Signed-off-by: Ruben Vargas [email protected]

Fixes #774

@jpkrohling
Copy link
Contributor

Looks like the unit tests are failing.

@rubenvp8510 rubenvp8510 force-pushed the Issue-774 branch 3 times, most recently from bbf9640 to 384bb3c Compare December 3, 2019 03:31
pkg/inject/sidecar.go Outdated Show resolved Hide resolved
@rubenvp8510 rubenvp8510 force-pushed the Issue-774 branch 13 times, most recently from 36ad1c2 to 5c89c92 Compare December 4, 2019 13:36
@jpkrohling
Copy link
Contributor

This needs a rebase and will conflict due to #814

@rubenvp8510
Copy link
Collaborator Author

This needs a rebase and will conflict due to #814

😢

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.

Did you just do a rebase, or have you changed the code significantly? Looks like new code to me :-)

// the reason for this is because the operator might not be running when the deployment is created or updated.
func (b *Background) detectDeploymentUpdates() error {
deps := &appsv1.DeploymentList{}
if err := b.clReader.List(context.Background(), deps); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment based on an error we've seen recently: shouldn't we list it only from the namespaces we are watching?

instances := &v1.JaegerList{}
if err := b.clReader.List(context.Background(), instances); err != nil {
log.WithError(err).Info("failed to retrieve the list of Jaeger instances")
return nil
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above: should probably be limited to the value of WATCH_NAMESPACES

},
},
}
dep.Name = "my-business-container"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not set on the statement above?

require.NoError(t, err)

err = cl.Create(context.TODO(), dep2)

Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting seems a bit odd... Can you get the require.NoError close to the err it's testing?

err = cl.Create(context.TODO(), jaeger2)
require.NoError(t, err)

dep.Annotations = map[string]string{inject.Annotation: jaeger1.Name}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be part of the definition of dep.

Name: dep.Name,
}, persisted)

reporterEndpoint := fmt.Sprintf("--reporter.grpc.host-port=dns:///%s.%s:14250", service.GetNameForHeadlessCollectorService(jaeger2), jaeger2.Namespace)
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep this assertion, but the official way to inform what's the Jaeger instance being used is via the annotation. So, add an assertion for the annotation that was persisted.

@@ -3,6 +3,10 @@ package deployment
import (
"context"

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Import formatting seems odd.

@@ -80,33 +81,18 @@ func (r *ReconcileDeployment) Reconcile(request reconcile.Request) (reconcile.Re
// Error reading the object - requeue the request.
return reconcile.Result{}, err
}
pods := &v1.JaegerList{}
err = r.client.List(context.Background(), pods)
Copy link
Contributor

Choose a reason for hiding this comment

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

Limit it to the namespaces being watched.

} else {
log.WithField("deployment", instance.Name).Info("No suitable Jaeger instances found to inject a sidecar")
if injected != nil {
if err := r.client.Update(context.Background(), injected); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would probably be better to create a context at the beginning of the reconcile method, and use the same context everywhere down the stream. It will make it easier once we decide to add tracing to this controller, like we added to the other controller.

@@ -251,3 +251,22 @@ func CleanSidecar(deployment *appsv1.Deployment) {
}
}
}

// IfNeeded inject the sidecar on deployment only if it is required
func IfNeeded(instance *appsv1.Deployment, pods *v1.JaegerList) *appsv1.Deployment {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this function name is appropriate. I had to check it twice while doing this review, as I would expect it to return an instance (not nil): either the original instance, or a changed instance, but not nil. The func documentation also doesn't tell that this might return nil, and what it means.

I think it would be better to change the IfNeeded consumers to check Needed instead.

@rubenvp8510
Copy link
Collaborator Author

Did you just do a rebase, or have you changed the code significantly? Looks like new code to me :-)

I didn't change anything :) may be this is an old PR and need some updates

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.

Reuse inject update loop from deployment controller into autodetect.
2 participants