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

Sidecar not removed #1508

Merged
merged 7 commits into from
Jul 27, 2021
Merged

Conversation

mfz85
Copy link
Contributor

@mfz85 mfz85 commented Jul 14, 2021

Which problem is this PR solving?

Short description of the changes

  • validates annotation with "false" value on the deployment in the needed method, and adds a method for removing the sidecar on the deployment controller if it exists and is not needed

@mfz85 mfz85 force-pushed the sidecar_not_removed branch 2 times, most recently from 384439a to fab19c1 Compare July 14, 2021 01:49
…false

Signed-off-by: Marco Freyre <marco.fz85@gmail.com>
… is set to false, added method for remove sidecar when is not needed in deploy controller

Signed-off-by: Marco Freyre <marco.fz85@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.

Thank you for the PR! I'll ask @rubenvp8510 to review it as well, but I believe there are a couple of changes necessary. In particular, we should account for the fact that annotations might be at the namespace level.

pkg/controller/deployment/deployment_controller.go Outdated Show resolved Hide resolved
pkg/controller/deployment/deployment_controller.go Outdated Show resolved Hide resolved
pkg/controller/deployment/deployment_controller.go Outdated Show resolved Hide resolved
_, nsExist := ns.Annotations[Annotation]

if depExist {
if depExist && !strings.EqualFold(annotationValue, "false") {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the annotation is at the namespace level? Isn't this logic already present in the inject.Desired?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

inject.Desired just test if the annotation is present, but if the annotation exists with a "false" value it still returns "true".

Should i validate the same condition for the namespace?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confident we have a logic somewhere that determines whether a deployment should have a sidecar based on annotations from both the deployment itself and the namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's present in "inject.select", but doesn't it make more sense for this to be validated in "inject.desired" ?, it is a bit confusing that desired returns "true" when it is not really desired.

Copy link
Contributor

Choose a reason for hiding this comment

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

True. Would you be able to create an issue to refactor that? Also, it would be great to have an e2e test to assert the behavior of this PR here. It doesn't have to be done as part of this PR, though.

I'd still like to get @rubenvp8510's review before merging, but looks good to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. Would you be able to create an issue to refactor that? Also, it would be great to have an e2e test to assert the behavior of this PR here. It doesn't have to be done as part of this PR, though.

count on it

Copy link
Collaborator

@rubenvp8510 rubenvp8510 Jul 22, 2021

Choose a reason for hiding this comment

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

This covers both cases, because inject.Needed is used when we modify the namespace to determine if the deployments that belongs to namespace needs an injection. Same case for individual deployments.

Except that we already have the cleaning logic on namespace but not on individual deployments, this is what this PR is adding.,

I think this modification to the desired behaviour makes sense , but it is a little bit confusing the difference between needed and desired, Indeed inject.Needed calls inject.Desired. so I think is enough to expose Needed and use it on the controllers. Desired could be renamed to desired (lowercase so don't expose outside package) and use only Needed on the contgrollers.

Copy link
Collaborator

@rubenvp8510 rubenvp8510 Jul 22, 2021

Choose a reason for hiding this comment

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

BTW, I think we shouldn't use inject.Select for validating these cases, inject.Select is just when we are make sure we need to inject something but we need to find which instance we need to inject (and if it exists)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the refactor is done, can you review @rubenvp8510 ?

@codecov
Copy link

codecov bot commented Jul 21, 2021

Codecov Report

Merging #1508 (70af62e) into master (4823277) will decrease coverage by 0.28%.
The diff coverage is 14.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1508      +/-   ##
==========================================
- Coverage   87.97%   87.68%   -0.29%     
==========================================
  Files          93       93              
  Lines        5811     5830      +19     
==========================================
  Hits         5112     5112              
- Misses        533      552      +19     
  Partials      166      166              
Impacted Files Coverage Δ
pkg/controller/deployment/deployment_controller.go 30.06% <0.00%> (-4.61%) ⬇️
pkg/inject/sidecar.go 97.46% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4823277...70af62e. Read the comment docs.

@@ -116,7 +116,15 @@ func (r *ReconcileDeployment) Reconcile(request reconcile.Request) (reconcile.Re
}

if !inject.Desired(dep, ns) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add this cleaning logic on the else statement of the if inject.Needed(dep, ns) {

Here: https://github.com/jaegertracing/jaeger-operator/pull/1508/files#diff-c553184997fa4c9f63e697af2f39eb2e6fb43eeff64a0ef66c9e955f61347b02R172

@@ -170,6 +178,23 @@ func (r *ReconcileDeployment) Reconcile(request reconcile.Request) (reconcile.Re
return reconcile.Result{}, nil
}

func (r *ReconcileDeployment) removeSidecar(ctx context.Context, dep *appsv1.Deployment) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the same logic that we used for the namespace case?

Is there a way to do a single function and reuse it for both case? Not need to be part of this PR, but we can have another PR with a re-factoring of this logic.

@rubenvp8510
Copy link
Collaborator

rubenvp8510 commented Jul 22, 2021

A couple of comments and one change, I would try to use inject.Needed for all the logic on the controller.

This is the logic I think both controllers should have (this is pseudo-code):

If inject.Needed(dep, ns) {
  jaeger = inject.Select(....) 
  if jaeger != nil {
   <inject logic> 
  } else {
     log("No suitable instance found...")
  }
} else {
  agent = hasAgent(dep)
 // it has an agent but is not needed, so we need to clean it.
  if (agent) {
      cleanSideCar()
  }
}

We might want to have this logic in one place and reuse it for both controllers, but that could be part of a refactor PR.

Signed-off-by: Marco Freyre <marco.fz85@gmail.com>
@mfz85 mfz85 requested a review from rubenvp8510 July 24, 2021 03:33
Copy link
Collaborator

@rubenvp8510 rubenvp8510 left a comment

Choose a reason for hiding this comment

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

LGTM!

@jpkrohling jpkrohling enabled auto-merge (squash) July 27, 2021 12:47
@jpkrohling jpkrohling merged commit 279b933 into jaegertracing:master Jul 27, 2021
@mfz85 mfz85 deleted the sidecar_not_removed branch August 19, 2021 17:41
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.

Sidecar is not removed when annotation is changed to false
3 participants