Pass DeleteOptions down to the Reactor
Co-authored-by: Mo Khan <theenjeru@gmail.com>
This commit is contained in:
parent
afff019fbc
commit
621970476f
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
core "k8s.io/client-go/testing"
|
core "k8s.io/client-go/testing"
|
||||||
bootstrapapi "k8s.io/cluster-bootstrap/token/api"
|
bootstrapapi "k8s.io/cluster-bootstrap/token/api"
|
||||||
"k8s.io/kubernetes/pkg/apis/core/helper"
|
"k8s.io/kubernetes/pkg/apis/core/helper"
|
||||||
@ -34,6 +35,7 @@ func newTokenSecret(tokenID, tokenSecret string) *v1.Secret {
|
|||||||
Namespace: metav1.NamespaceSystem,
|
Namespace: metav1.NamespaceSystem,
|
||||||
Name: bootstrapapi.BootstrapTokenSecretPrefix + tokenID,
|
Name: bootstrapapi.BootstrapTokenSecretPrefix + tokenID,
|
||||||
ResourceVersion: "1",
|
ResourceVersion: "1",
|
||||||
|
UID: types.UID("uid" + tokenID),
|
||||||
},
|
},
|
||||||
Type: bootstrapapi.SecretTypeBootstrapToken,
|
Type: bootstrapapi.SecretTypeBootstrapToken,
|
||||||
Data: map[string][]byte{
|
Data: map[string][]byte{
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/client-go/informers"
|
"k8s.io/client-go/informers"
|
||||||
@ -76,10 +77,13 @@ func TestCleanerExpired(t *testing.T) {
|
|||||||
cleaner.evalSecret(secret)
|
cleaner.evalSecret(secret)
|
||||||
|
|
||||||
expected := []core.Action{
|
expected := []core.Action{
|
||||||
core.NewDeleteAction(
|
core.NewDeleteActionWithOptions(
|
||||||
schema.GroupVersionResource{Version: "v1", Resource: "secrets"},
|
schema.GroupVersionResource{Version: "v1", Resource: "secrets"},
|
||||||
api.NamespaceSystem,
|
api.NamespaceSystem,
|
||||||
secret.ObjectMeta.Name),
|
secret.ObjectMeta.Name,
|
||||||
|
metav1.DeleteOptions{
|
||||||
|
Preconditions: metav1.NewUIDPreconditions(string(secret.UID)),
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
verifyActions(t, expected, cl.Actions())
|
verifyActions(t, expected, cl.Actions())
|
||||||
@ -138,10 +142,13 @@ func TestCleanerExpiredAt(t *testing.T) {
|
|||||||
|
|
||||||
// secret was eventually deleted
|
// secret was eventually deleted
|
||||||
expected = []core.Action{
|
expected = []core.Action{
|
||||||
core.NewDeleteAction(
|
core.NewDeleteActionWithOptions(
|
||||||
schema.GroupVersionResource{Version: "v1", Resource: "secrets"},
|
schema.GroupVersionResource{Version: "v1", Resource: "secrets"},
|
||||||
api.NamespaceSystem,
|
api.NamespaceSystem,
|
||||||
secret.ObjectMeta.Name),
|
secret.ObjectMeta.Name,
|
||||||
|
metav1.DeleteOptions{
|
||||||
|
Preconditions: metav1.NewUIDPreconditions(string(secret.UID)),
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
verifyFunc()
|
verifyFunc()
|
||||||
}
|
}
|
||||||
|
@ -409,7 +409,10 @@ func TestTokenCreation(t *testing.T) {
|
|||||||
|
|
||||||
DeletedServiceAccount: serviceAccount(tokenSecretReferences()),
|
DeletedServiceAccount: serviceAccount(tokenSecretReferences()),
|
||||||
ExpectedActions: []core.Action{
|
ExpectedActions: []core.Action{
|
||||||
core.NewDeleteAction(schema.GroupVersionResource{Version: "v1", Resource: "secrets"}, metav1.NamespaceDefault, "token-secret-1"),
|
core.NewDeleteActionWithOptions(
|
||||||
|
schema.GroupVersionResource{Version: "v1", Resource: "secrets"},
|
||||||
|
metav1.NamespaceDefault, "token-secret-1",
|
||||||
|
*metav1.NewPreconditionDeleteOptions("23456")),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -419,7 +422,10 @@ func TestTokenCreation(t *testing.T) {
|
|||||||
AddedSecret: serviceAccountTokenSecret(),
|
AddedSecret: serviceAccountTokenSecret(),
|
||||||
ExpectedActions: []core.Action{
|
ExpectedActions: []core.Action{
|
||||||
core.NewGetAction(schema.GroupVersionResource{Version: "v1", Resource: "serviceaccounts"}, metav1.NamespaceDefault, "default"),
|
core.NewGetAction(schema.GroupVersionResource{Version: "v1", Resource: "serviceaccounts"}, metav1.NamespaceDefault, "default"),
|
||||||
core.NewDeleteAction(schema.GroupVersionResource{Version: "v1", Resource: "secrets"}, metav1.NamespaceDefault, "token-secret-1"),
|
core.NewDeleteActionWithOptions(
|
||||||
|
schema.GroupVersionResource{Version: "v1", Resource: "secrets"},
|
||||||
|
metav1.NamespaceDefault, "token-secret-1",
|
||||||
|
*metav1.NewPreconditionDeleteOptions("23456")),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"added secret with serviceaccount": {
|
"added secret with serviceaccount": {
|
||||||
@ -484,7 +490,10 @@ func TestTokenCreation(t *testing.T) {
|
|||||||
UpdatedSecret: serviceAccountTokenSecret(),
|
UpdatedSecret: serviceAccountTokenSecret(),
|
||||||
ExpectedActions: []core.Action{
|
ExpectedActions: []core.Action{
|
||||||
core.NewGetAction(schema.GroupVersionResource{Version: "v1", Resource: "serviceaccounts"}, metav1.NamespaceDefault, "default"),
|
core.NewGetAction(schema.GroupVersionResource{Version: "v1", Resource: "serviceaccounts"}, metav1.NamespaceDefault, "default"),
|
||||||
core.NewDeleteAction(schema.GroupVersionResource{Version: "v1", Resource: "secrets"}, metav1.NamespaceDefault, "token-secret-1"),
|
core.NewDeleteActionWithOptions(
|
||||||
|
schema.GroupVersionResource{Version: "v1", Resource: "secrets"},
|
||||||
|
metav1.NamespaceDefault, "token-secret-1",
|
||||||
|
*metav1.NewPreconditionDeleteOptions("23456")),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"updated secret with serviceaccount": {
|
"updated secret with serviceaccount": {
|
||||||
|
@ -222,10 +222,15 @@ func NewUpdateSubresourceAction(resource schema.GroupVersionResource, subresourc
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRootDeleteAction(resource schema.GroupVersionResource, name string) DeleteActionImpl {
|
func NewRootDeleteAction(resource schema.GroupVersionResource, name string) DeleteActionImpl {
|
||||||
|
return NewRootDeleteActionWithOptions(resource, name, metav1.DeleteOptions{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRootDeleteActionWithOptions(resource schema.GroupVersionResource, name string, opts metav1.DeleteOptions) DeleteActionImpl {
|
||||||
action := DeleteActionImpl{}
|
action := DeleteActionImpl{}
|
||||||
action.Verb = "delete"
|
action.Verb = "delete"
|
||||||
action.Resource = resource
|
action.Resource = resource
|
||||||
action.Name = name
|
action.Name = name
|
||||||
|
action.DeleteOptions = opts
|
||||||
|
|
||||||
return action
|
return action
|
||||||
}
|
}
|
||||||
@ -241,11 +246,16 @@ func NewRootDeleteSubresourceAction(resource schema.GroupVersionResource, subres
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewDeleteAction(resource schema.GroupVersionResource, namespace, name string) DeleteActionImpl {
|
func NewDeleteAction(resource schema.GroupVersionResource, namespace, name string) DeleteActionImpl {
|
||||||
|
return NewDeleteActionWithOptions(resource, namespace, name, metav1.DeleteOptions{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDeleteActionWithOptions(resource schema.GroupVersionResource, namespace, name string, opts metav1.DeleteOptions) DeleteActionImpl {
|
||||||
action := DeleteActionImpl{}
|
action := DeleteActionImpl{}
|
||||||
action.Verb = "delete"
|
action.Verb = "delete"
|
||||||
action.Resource = resource
|
action.Resource = resource
|
||||||
action.Namespace = namespace
|
action.Namespace = namespace
|
||||||
action.Name = name
|
action.Name = name
|
||||||
|
action.DeleteOptions = opts
|
||||||
|
|
||||||
return action
|
return action
|
||||||
}
|
}
|
||||||
@ -391,6 +401,7 @@ type UpdateAction interface {
|
|||||||
type DeleteAction interface {
|
type DeleteAction interface {
|
||||||
Action
|
Action
|
||||||
GetName() string
|
GetName() string
|
||||||
|
GetDeleteOptions() metav1.DeleteOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteCollectionAction interface {
|
type DeleteCollectionAction interface {
|
||||||
@ -583,17 +594,23 @@ func (a PatchActionImpl) DeepCopy() Action {
|
|||||||
|
|
||||||
type DeleteActionImpl struct {
|
type DeleteActionImpl struct {
|
||||||
ActionImpl
|
ActionImpl
|
||||||
Name string
|
Name string
|
||||||
|
DeleteOptions metav1.DeleteOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a DeleteActionImpl) GetName() string {
|
func (a DeleteActionImpl) GetName() string {
|
||||||
return a.Name
|
return a.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a DeleteActionImpl) GetDeleteOptions() metav1.DeleteOptions {
|
||||||
|
return a.DeleteOptions
|
||||||
|
}
|
||||||
|
|
||||||
func (a DeleteActionImpl) DeepCopy() Action {
|
func (a DeleteActionImpl) DeepCopy() Action {
|
||||||
return DeleteActionImpl{
|
return DeleteActionImpl{
|
||||||
ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
|
ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
|
||||||
Name: a.Name,
|
Name: a.Name,
|
||||||
|
DeleteOptions: *a.DeleteOptions.DeepCopy(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,9 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
|
|||||||
"NewRootGetAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootGetAction"}),
|
"NewRootGetAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootGetAction"}),
|
||||||
"NewGetAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewGetAction"}),
|
"NewGetAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewGetAction"}),
|
||||||
"NewRootDeleteAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteAction"}),
|
"NewRootDeleteAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteAction"}),
|
||||||
|
"NewRootDeleteActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteActionWithOptions"}),
|
||||||
"NewDeleteAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteAction"}),
|
"NewDeleteAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteAction"}),
|
||||||
|
"NewDeleteActionWithOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteActionWithOptions"}),
|
||||||
"NewRootDeleteCollectionAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteCollectionAction"}),
|
"NewRootDeleteCollectionAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteCollectionAction"}),
|
||||||
"NewDeleteCollectionAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteCollectionAction"}),
|
"NewDeleteCollectionAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteCollectionAction"}),
|
||||||
"NewRootUpdateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootUpdateAction"}),
|
"NewRootUpdateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootUpdateAction"}),
|
||||||
@ -412,8 +414,8 @@ var deleteTemplate = `
|
|||||||
// Delete takes name of the $.type|private$ and deletes it. Returns an error if one occurs.
|
// Delete takes name of the $.type|private$ and deletes it. Returns an error if one occurs.
|
||||||
func (c *Fake$.type|publicPlural$) Delete(ctx context.Context, name string, opts $.DeleteOptions|raw$) error {
|
func (c *Fake$.type|publicPlural$) Delete(ctx context.Context, name string, opts $.DeleteOptions|raw$) error {
|
||||||
_, err := c.Fake.
|
_, err := c.Fake.
|
||||||
$if .namespaced$Invokes($.NewDeleteAction|raw$($.type|allLowercasePlural$Resource, c.ns, name), &$.type|raw${})
|
$if .namespaced$Invokes($.NewDeleteActionWithOptions|raw$($.type|allLowercasePlural$Resource, c.ns, name, opts), &$.type|raw${})
|
||||||
$else$Invokes($.NewRootDeleteAction|raw$($.type|allLowercasePlural$Resource, name), &$.type|raw${})$end$
|
$else$Invokes($.NewRootDeleteActionWithOptions|raw$($.type|allLowercasePlural$Resource, name, opts), &$.type|raw${})$end$
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user