Skip to content

Commit

Permalink
Merge pull request #13168 from ycliuhw/fix/lp-1936253
Browse files Browse the repository at this point in the history
#13168

*Fix Preconditions for cluster role binding deletion;*

## Checklist

 - [ ] ~Requires a [pylibjuju](https://github.com/juju/python-libjuju) change~
 - [ ] ~Added [integration tests](https://github.com/juju/juju/tree/develop/tests) for the PR~
 - [ ] ~Added or updated [doc.go](https://discourse.jujucharms.com/t/readme-in-packages/451) related to packages changed~
 - [x] Comments answer the question of why design decisions were made

## QA steps


```console
$ juju deploy snappass-test

$ juju remove-application snappass-test --destroy-storage --force
removing application snappass-test

```

## Documentation changes

No

## Bug reference

https://bugs.launchpad.net/juju/+bug/1936262
  • Loading branch information
jujubot committed Jul 15, 2021
2 parents 7a2ecbc + 40dca1a commit e797352
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion caas/kubernetes/provider/resources/clusterrolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"k8s.io/utils/pointer"

k8sconstants "github.com/juju/juju/caas/kubernetes/provider/constants"
"github.com/juju/juju/caas/kubernetes/provider/utils"
"github.com/juju/juju/core/status"
)

Expand Down Expand Up @@ -88,7 +89,7 @@ func (rb *ClusterRoleBinding) Delete(ctx context.Context, client kubernetes.Inte
err := api.Delete(ctx, rb.Name, metav1.DeleteOptions{
PropagationPolicy: k8sconstants.DeletePropagationBackground(),
GracePeriodSeconds: pointer.Int64Ptr(0),
Preconditions: &metav1.Preconditions{UID: &rb.UID},
Preconditions: utils.NewUIDPreconditions(rb.UID),
})
if k8serrors.IsNotFound(err) {
return nil
Expand Down
24 changes: 24 additions & 0 deletions caas/kubernetes/provider/resources/clusterrolebinding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,30 @@ func (s *clusterRoleBindingSuite) TestDelete(c *gc.C) {
c.Assert(err, jc.Satisfies, k8serrors.IsNotFound)
}

func (s *clusterRoleBindingSuite) TestDeleteWithoutPreconditions(c *gc.C) {
roleBinding := rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "roleBinding1",
},
}
_, err := s.client.RbacV1().ClusterRoleBindings().Create(context.TODO(), &roleBinding, metav1.CreateOptions{})
c.Assert(err, jc.ErrorIsNil)

result, err := s.client.RbacV1().ClusterRoleBindings().Get(context.TODO(), "roleBinding1", metav1.GetOptions{})
c.Assert(err, jc.ErrorIsNil)
c.Assert(result.GetName(), gc.Equals, `roleBinding1`)

rbResource := resources.NewClusterRoleBinding("roleBinding1", nil)
err = rbResource.Delete(context.TODO(), s.client)
c.Assert(err, jc.ErrorIsNil)

err = rbResource.Get(context.TODO(), s.client)
c.Assert(err, jc.Satisfies, errors.IsNotFound)

_, err = s.client.RbacV1().ClusterRoleBindings().Get(context.TODO(), "roleBinding1", metav1.GetOptions{})
c.Assert(err, jc.Satisfies, k8serrors.IsNotFound)
}

// This test ensures that there has not been a regression with ensure cluster
// role where it can not update roles that have a labels change.
// https://bugs.launchpad.net/juju/+bug/1929909
Expand Down

0 comments on commit e797352

Please sign in to comment.