Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Add svcat unbind --abandon command #2579

Merged
merged 4 commits into from
Mar 29, 2019

Conversation

taragu
Copy link
Contributor

@taragu taragu commented Mar 10, 2019

This PR is a

  • Feature Implementation
  • Bug Fix
  • Documentation

What this PR does / why we need it: Add --abandon and --yes flags for svcat unbind

Which issue(s) this PR fixes

#2268

Please leave this checklist in the PR comment so that maintainers can ensure a good PR.

Merge Checklist:

  • New feature
    • Tests
    • Documentation
  • SVCat CLI flag

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 10, 2019
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 10, 2019
@taragu
Copy link
Contributor Author

taragu commented Mar 10, 2019

/assign @carolynvs
/cc @jberkhahn

@k8s-ci-robot k8s-ci-robot requested a review from jberkhahn March 10, 2019 16:58
@taragu taragu force-pushed the svcat-abandon branch 3 times, most recently from 9db404a to 61ec955 Compare March 10, 2019 23:27
@@ -35,6 +41,9 @@ type unbindCmd struct {

instanceName string
bindingNames []string
abandon bool
stdin io.Reader
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 understand why this is defined as a field on the command struct. Does COBRA do something special to populate this for you? where is it getting instantiated?

if err != nil {
return err
}
for _, binding := range instanceBindings {
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 it's a good idea to reach in and do this sort of stuff in the command layer. I think I would add some sort of RemoveFinalizers() method to the interface in pkg/svcat/service-catalog, and implement this there, like the rest of the methods like RetrieveBindingsByInstance or Unbind

}
}

if c.instanceName == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's actually possible for there to be multiple bindings to remove, see the bit on line 145 where it calls Unbind or DeleteBindings based on whether instanceName is set or not. I think we also need to handle both cases.

@jberkhahn
Copy link
Contributor

In addition to the comments on the code, I also think your commit message could be a bit more descriptive. "Add --abandon flag to svcat unbind command" or something.

@k8s-ci-robot k8s-ci-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 16, 2019
@taragu taragu changed the title Unbind abandon Add svcat unbind --abandon command Mar 16, 2019
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 16, 2019
@taragu
Copy link
Contributor Author

taragu commented Mar 16, 2019

@jberkhahn thanks for the feedback! I've updated the PR and it's ready to be reviewed again

@taragu taragu force-pushed the svcat-abandon branch 2 times, most recently from 1ed102d to f896543 Compare March 16, 2019 14:33
@taragu
Copy link
Contributor Author

taragu commented Mar 16, 2019

/test pull-service-catalog-integration

if c.abandon {
fmt.Fprintln(c.Output, "This action is not reversible and may cause you to be charged for the broker resources that are abandoned.")
if !c.skipPrompt {
fmt.Fprintln(c.Output, "Are you sure? [y|N]: ")
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't these both be upper or lower case?

si := &v1beta1.ServiceInstance{ObjectMeta: metav1.ObjectMeta{Name: c.instanceName, Namespace: c.Namespace}}
removedBindings, err = c.App.RemoveFinalizersByInstance(si)
} else {
retrievedBindings, err := c.App.RetrieveBindings(c.Namespace)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will remove the finalizers on all the bindings in the whole namespace, which I don't think is what we want. I think you could replace this with a call to getBindingsToDelete(), like the part that actually delete the bindings does. Then you would have to either turn that array of names into an array of v1beta1 binding objects, or refactor the pkg methods to take names/namespaces instead of v1beta1.bindings. I think I would do the second, but you could make the case for either.

actions := svcCatClient.Actions()
Expect(actions[0].Matches("update", "servicebindings")).To(BeTrue())
Expect(actions[0].(testing.UpdateActionImpl).Object.(*v1beta1.ServiceBinding).ObjectMeta.Name).To(Equal(sb.ObjectMeta.Name))
Expect(actions[0].(testing.UpdateActionImpl).Object.(*v1beta1.ServiceBinding).ObjectMeta.Namespace).To(Equal(sb.ObjectMeta.Namespace))
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests are great! Only other thing I could ask for us somehow asserting that the update action is removing the finalizers, but I don't actually know how to do that.

@@ -81,6 +81,10 @@ type SvcatClient interface {
RetrieveSecretByBinding(*apiv1beta1.ServiceBinding) (*apicorev1.Secret, error)

ServerVersion() (*version.Info, error)

RemoveFinalizersByInstance(*apiv1beta1.ServiceInstance) ([]types.NamespacedName, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

these should be in the block at the top with the other methods for bindings

@carolynvs carolynvs removed their assignment Mar 19, 2019
return err
}
for _, binding := range removedBindings {
fmt.Fprintln(c.Output, fmt.Sprintf("deleted %s", binding.Name))
Copy link
Contributor

Choose a reason for hiding this comment

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

its possible for both these to print, but the removing finalizers is an if/else, so shouldn't this be as well?

Copy link
Contributor

@jberkhahn jberkhahn Mar 25, 2019

Choose a reason for hiding this comment

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

actually, looking further, neither of these print statements is needed, we say "deleted foobar" down below

if c.instanceName != "" {
fmt.Fprintln(c.Output, fmt.Sprintf("deleted %s", c.instanceName))
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

this return statement needs to be removed - otherwise we just remove the finalizers and don't actually delete the binding

@jberkhahn
Copy link
Contributor

@taragu just a few more small changes, and then this LGTM

@taragu
Copy link
Contributor Author

taragu commented Mar 29, 2019

/test pull-service-catalog-xbuild

@jberkhahn
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 29, 2019
Copy link
Contributor

@jboyd01 jboyd01 left a comment

Choose a reason for hiding this comment

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

The code is right on, lgtm. Some comments and function names are misleading (all finalizers) and in one case, it sounds like removing the finalizer from an instance (RemoveFinalizersByInstance)

@@ -264,3 +265,69 @@ func (sdk *SDK) bindingHasStatus(binding *v1beta1.ServiceBinding, status v1beta1

return false
}

// RemoveFinalizersForBinding removes all finalizers for a single binding
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: RemoveFinalizerForBinding (singular finalizer)
here and other places: "all finalizers" but we're actually only deleting the v1beta1.FinalizerServiceCatalog finalizer (not all finalizers). Code is correct.

return deleted, bindErr.ErrorOrNil()
}

// RemoveFinalizersByInstance removes all finalizers for an instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove v1beta1.FinalizerServiceCatalog from all bindings for the specified instance

}

// RemoveFinalizersByInstance removes all finalizers for an instance.
func (sdk *SDK) RemoveFinalizersByInstance(instance *v1beta1.ServiceInstance) ([]types.NamespacedName, error) {
Copy link
Contributor

@jboyd01 jboyd01 Mar 29, 2019

Choose a reason for hiding this comment

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

nit: I'd prefer to call it RemoveBindingFinalizerByInstance
(its the only the service catalog finalizer for all bindings that are for a specific instance)

}

// RemoveFinalizersForBindings removes all finalizers for the provided list of bindings
func (sdk *SDK) RemoveFinalizersForBindings(bindings []types.NamespacedName) ([]types.NamespacedName, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: RemoveFinalizerForBindings (singular on the finalizer)

@jboyd01
Copy link
Contributor

jboyd01 commented Mar 29, 2019

@taragu - I neglected to say thanks for the PR!! Great job on what I believe to be your first SIG Catalog contribution!

@k8s-ci-robot k8s-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 29, 2019
@jberkhahn
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 29, 2019
@jboyd01
Copy link
Contributor

jboyd01 commented Mar 29, 2019

Thanks @taragu
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jboyd01

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 29, 2019
@taragu
Copy link
Contributor Author

taragu commented Mar 29, 2019

Thanks @jberkhahn @jboyd01 !

@jberkhahn
Copy link
Contributor

/test pull-service-catalog-xbuild

@k8s-ci-robot k8s-ci-robot merged commit 05181ac into kubernetes-retired:master Mar 29, 2019
@taragu taragu deleted the svcat-abandon branch March 30, 2019 20:30
@cforce
Copy link

cforce commented Apr 13, 2019

Still can not remove abandon bindings.

C:\Users\user\Downloads>svcat get bindings -ndev
NAME NAMESPACE INSTANCE STATUS
+------------------------------+-----------+------------------------------+-------------------------------+
push-adapter-db.dev.db dev push-adapter-db.dev.db ReferencesNonexistentInstance

C:\Users\user\Downloads>svcatc unbind push-adapter-db.dev.db -ndev --abandon
This action is not reversible and may cause you to be charged for the broker resources that are abandoned.
Are you sure? [y|n]:
y

unable to get instance 'dev.push-adapter-db.dev.db' (serviceinstances.servicecatalog.k8s.io "push-adapter-db.dev.db" not found)
Error: could not remove all bindings

C:\Users\user\Downloads>svcatc unbind push-adapter-db.dev.db -ndev --abandon --yes
This action is not reversible and may cause you to be charged for the broker resources that are abandoned.
unable to get instance 'dev.push-adapter-db.dev.db' (serviceinstances.servicecatalog.k8s.io "push-adapter-db.dev.db" not found)
Error: could not remove all bindings

@taragu
Copy link
Contributor Author

taragu commented Apr 13, 2019

@cforce thank you for reporting this problem. I created #2610 to track this.

viviyww pushed a commit to viviyww/service-catalog that referenced this pull request May 10, 2019
* Add --abandon flag to svcat unbind command; add remove finalizer methods

* Add tests for svcat remove finalizer methods

* Update yaml file for svcat unbind --abandon command

* Generate fake client methods for remove finalizer methods
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants