-
Notifications
You must be signed in to change notification settings - Fork 545
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
fix(deployment): Clean up orphaned deployments #759
fix(deployment): Clean up orphaned deployments #759
Conversation
/test e2e-aws-olm |
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.
This is a great start! See comments inline - this is a good opportunity to improve our deployment strategy installer, so I made some suggestions around moving this there.
for _, d := range existingDeployments { | ||
if _, exists := depNames[d.GetName()]; !exists { | ||
logger.Infof("found an orphaned deployment %s in namespace %s", d.GetName(), csv.GetNamespace()) | ||
if err := a.OpClient.DeleteDeployment(csv.GetNamespace(), d.GetName(), &metav1.DeleteOptions{}); err != nil { |
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.
before deleting anything, we should probably check the ownerreferences to be extra safe. it there is an orphaned deployment, it should have an ownerreference to this CSV
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 owner check has already been done in line #1399 above:
The existingDeployments
should only contain deployments that belong to to a specific CSV out
based on the labels.selector
filter.
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.
That does query by the labels which we use for finding the objects, but for these objects (since they're in the same namespace) we add "real" owner references as well. It's better to be extra safe when GCing
864db09
to
ab96410
Compare
15f4c15
to
c824d05
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.
It's looking great! I think we can clean up some older stuff now that this is here, so I made some comments about that.
@@ -906,6 +906,10 @@ func (a *Operator) transitionCSVState(in v1alpha1.ClusterServiceVersion) (out *v | |||
} | |||
} | |||
|
|||
// Clean up deployments in case some become orphaned | |||
if cleanupErr := a.cleanupOrphanedDeployments(logger, out); cleanupErr == nil { |
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.
This part can be removed now right?
@@ -118,3 +120,13 @@ func (c *InstallStrategyDeploymentClientForNamespace) FindAnyDeploymentsMatching | |||
} | |||
return deployments, nil | |||
} | |||
|
|||
func (c *InstallStrategyDeploymentClientForNamespace) FindAnyDeploymentsMatchingLabelSelector(label labels.Selector) ([]*appsv1.Deployment, 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.
Can you add a unit test for this?
c824d05
to
183db79
Compare
9ee716a
to
bd3aab2
Compare
bd3aab2
to
421a594
Compare
421a594
to
1c7777e
Compare
ca3f528
to
56ac5cf
Compare
/test e2e-aws |
c05a32d
to
f4e03f3
Compare
Looks great, thanks for wrapping this up! /lgtm |
/retest |
2 similar comments
/retest |
/retest |
f4e03f3
to
b0f605e
Compare
2590afa
to
f4e03f3
Compare
Signed-off-by: Vu Dinh <[email protected]>
Signed-off-by: Vu Dinh <[email protected]>
Signed-off-by: Vu Dinh <[email protected]>
f4e03f3
to
a52214c
Compare
/retest |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dinhxuanvu, ecordell The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Vu Dinh [email protected]