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

Improve uninstall command #29

Merged

Conversation

varshaprasad96
Copy link
Member

Refactor uninstall command to clean up all the resources,
and report whether package existed correctly.

Co-authored by: Eric Stroczynski ericstroczynski@gmail.com

Comment on lines 143 to 144
// If csvObj is nil and crds is not present, it means the package was not found
if subObj == nil && len(crds) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If csvObj is nil and crds is not present, it means the package was not found
if subObj == nil && len(crds) == 0 {
// If no objects were cleaned up, it means the package was not found
if subObj == nil && csvObj == nil && len(crds) == 0 {

Comment on lines +71 to +90
subObj = sub
// CSV name may either be the installed or current name in a subscription's status,
// depending on installation state.
csvKey := types.NamespacedName{
Name: sub.Status.InstalledCSV,
Namespace: u.config.Namespace,
}
if csvKey.Name == "" {
csvKey.Name = sub.Status.CurrentCSV
}

// This value can be empty which will cause errors.
if csvKey.Name != "" {
csv := &v1alpha1.ClusterServiceVersion{}
if err := u.config.Client.Get(ctx, csvKey, csv); err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("error getting installed CSV %q: %v", csvKey.Name, err)
} else if err == nil {
crds = getCRDs(csv)
}
csvObj = csv
Copy link
Member

Choose a reason for hiding this comment

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

(optional) you could move all of this into OperatorUninstall.getInstalledCSV().

Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

One addition to "no package found" condition then LGTM

Refactor uninstall command to clean up all the resources,
and report whether package existed correctly.

Co-authored by: Eric Stroczynski <ericstroczynski@gmail.com>
Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 16, 2020
@varshaprasad96 varshaprasad96 merged commit fdca85f into operator-framework:main Dec 17, 2020
Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

Apologies for the late review, but a few more comments and suggestions.

Since this is merged already, I don't mind taking a stab at any other tweaks that come from my comments.

return fmt.Errorf("get installed CSV %q: %v", sub.Status.InstalledCSV, err)
var subObj, csvObj controllerutil.Object
var crds []controllerutil.Object
if sub != nil {
Copy link
Member

Choose a reason for hiding this comment

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

By this point, we know that sub is non-nil because we checked it and returned early in lines 64-66, so IIUC there's no need for this conditional, and also therefore no need for the subObj variable.

Copy link
Member

Choose a reason for hiding this comment

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

You're correct, this condition can be removed due to the above check. This PR is a port of operator-framework/operator-sdk#4303 so there might be some incongruities that should be resolved. subObj was necessary due to some strange nil comparison behavior I experienced when writing the linked PR, and made the code a little cleaner. It might not make sense here given your comments below.

@@ -107,6 +140,11 @@ func (u *OperatorUninstall) Run(ctx context.Context) error {
}
}

// If no objects were cleaned up, it means the package was not found
if subObj == nil && csvObj == nil && len(crds) == 0 {
return &ErrPackageNotFound{u.Package}
Copy link
Member

Choose a reason for hiding this comment

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

Since we know subObj is never nil by this point (right?), I think we can completely remove this conditional block and use ErrPackageNotFound in line 65.

@@ -81,7 +114,7 @@ func (u *OperatorUninstall) Run(ctx context.Context) error {
// OLM puts an ownerref on every namespaced resource to the CSV,
// and an owner label on every cluster scoped resource. When CSV is deleted
// kube and olm gc will remove all the referenced resources.
if err := u.deleteObjects(ctx, csv); err != nil {
if err := u.deleteObjects(ctx, csvObj); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

If we come out of the CSV fetching with a nil csvObj, that means we will have a nil CSV and no CRDs to delete (since we find the CRDs from the CSV), right?

Do we need to check to see if the CSV is nil before trying to delete it here?

If it is nil, I think that means we'll only be deleting the subscription and possibly the operator group and NOT erroring out on a missing CSV? Seems reasonable since its possible there's a problem with the subscription that prevented the CSV from being created.

Copy link
Member

Choose a reason for hiding this comment

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

A nil check should be performed in deleteObjects() like in operator-framework/operator-sdk#4303.

@joelanford
Copy link
Member

I finally got around to submitting PR #31 that makes these changes based on my suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants