-
Notifications
You must be signed in to change notification settings - Fork 382
Conversation
/assign @carolynvs |
9db404a
to
61ec955
Compare
cmd/svcat/binding/unbind_cmd.go
Outdated
@@ -35,6 +41,9 @@ type unbindCmd struct { | |||
|
|||
instanceName string | |||
bindingNames []string | |||
abandon bool | |||
stdin io.Reader |
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.
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?
cmd/svcat/binding/unbind_cmd.go
Outdated
if err != nil { | ||
return err | ||
} | ||
for _, binding := range instanceBindings { |
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.
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
cmd/svcat/binding/unbind_cmd.go
Outdated
} | ||
} | ||
|
||
if c.instanceName == "" { |
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 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.
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. |
@jberkhahn thanks for the feedback! I've updated the PR and it's ready to be reviewed again |
1ed102d
to
f896543
Compare
/test pull-service-catalog-integration |
cmd/svcat/binding/unbind_cmd.go
Outdated
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]: ") |
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.
shouldn't these both be upper or lower case?
cmd/svcat/binding/unbind_cmd.go
Outdated
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) |
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 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)) |
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.
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.
pkg/svcat/service-catalog/sdk.go
Outdated
@@ -81,6 +81,10 @@ type SvcatClient interface { | |||
RetrieveSecretByBinding(*apiv1beta1.ServiceBinding) (*apicorev1.Secret, error) | |||
|
|||
ServerVersion() (*version.Info, error) | |||
|
|||
RemoveFinalizersByInstance(*apiv1beta1.ServiceInstance) ([]types.NamespacedName, 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.
these should be in the block at the top with the other methods for bindings
cmd/svcat/binding/unbind_cmd.go
Outdated
return err | ||
} | ||
for _, binding := range removedBindings { | ||
fmt.Fprintln(c.Output, fmt.Sprintf("deleted %s", binding.Name)) |
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.
its possible for both these to print, but the removing finalizers is an if/else, so shouldn't this be as well?
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.
actually, looking further, neither of these print statements is needed, we say "deleted foobar" down below
cmd/svcat/binding/unbind_cmd.go
Outdated
if c.instanceName != "" { | ||
fmt.Fprintln(c.Output, fmt.Sprintf("deleted %s", c.instanceName)) | ||
} | ||
return 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 return statement needs to be removed - otherwise we just remove the finalizers and don't actually delete the binding
@taragu just a few more small changes, and then this LGTM |
/test pull-service-catalog-xbuild |
/lgtm |
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 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)
pkg/svcat/service-catalog/binding.go
Outdated
@@ -264,3 +265,69 @@ func (sdk *SDK) bindingHasStatus(binding *v1beta1.ServiceBinding, status v1beta1 | |||
|
|||
return false | |||
} | |||
|
|||
// RemoveFinalizersForBinding removes all finalizers for a single binding |
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.
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.
pkg/svcat/service-catalog/binding.go
Outdated
return deleted, bindErr.ErrorOrNil() | ||
} | ||
|
||
// RemoveFinalizersByInstance removes all finalizers for an instance. |
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.
Remove v1beta1.FinalizerServiceCatalog from all bindings for the specified instance
pkg/svcat/service-catalog/binding.go
Outdated
} | ||
|
||
// RemoveFinalizersByInstance removes all finalizers for an instance. | ||
func (sdk *SDK) RemoveFinalizersByInstance(instance *v1beta1.ServiceInstance) ([]types.NamespacedName, 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.
nit: I'd prefer to call it RemoveBindingFinalizerByInstance
(its the only the service catalog finalizer for all bindings that are for a specific instance)
pkg/svcat/service-catalog/binding.go
Outdated
} | ||
|
||
// RemoveFinalizersForBindings removes all finalizers for the provided list of bindings | ||
func (sdk *SDK) RemoveFinalizersForBindings(bindings []types.NamespacedName) ([]types.NamespacedName, 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.
nit: RemoveFinalizerForBindings (singular on the finalizer)
@taragu - I neglected to say thanks for the PR!! Great job on what I believe to be your first SIG Catalog contribution! |
/lgtm |
Thanks @taragu |
[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 |
Thanks @jberkhahn @jboyd01 ! |
/test pull-service-catalog-xbuild |
Still can not remove abandon bindings.C:\Users\user\Downloads>svcat get bindings -ndev C:\Users\user\Downloads>svcatc unbind push-adapter-db.dev.db -ndev --abandon C:\Users\user\Downloads>svcatc unbind push-adapter-db.dev.db -ndev --abandon --yes |
* 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
This PR is a
What this PR does / why we need it: Add
--abandon
and--yes
flags for svcat unbindWhich issue(s) this PR fixes
#2268
Please leave this checklist in the PR comment so that maintainers can ensure a good PR.
Merge Checklist: