-
Notifications
You must be signed in to change notification settings - Fork 104
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
Delete options removed by controller runtime intermediary client #254
Comments
@ryanmcnamara Oh thanks for noticing this one. I believe you are right. I think the following should take care of the necessary configuration. (I still have to test this out, but this should take care of the issue you are talking about) func (r *Resources) Delete(ctx context.Context, obj k8s.Object, opts ...DeleteOption) error {
deleteOptions := &metav1.DeleteOptions{}
for _, fn := range opts {
fn(deleteOptions)
}
o := &cr.DeleteOptions{
Raw: deleteOptions,
GracePeriodSeconds: deleteOptions.GracePeriodSeconds,
Preconditions: deleteOptions.Preconditions,
PropagationPolicy: deleteOptions.PropagationPolicy,
DryRun: deleteOptions.DryRun,
}
return r.client.Delete(ctx, obj, o)
} |
Or we could just turn the type DeleteOption func(*cr.DeleteOptions)
func (r *Resources) Delete(ctx context.Context, obj k8s.Object, opts ...DeleteOption) error {
deleteOptions := &cr.DeleteOptions{}
for _, fn := range opts {
fn(deleteOptions)
}
return r.client.Delete(ctx, obj, deleteOptions)
}
func WithGracePeriod(gpt time.Duration) DeleteOption {
t := gpt.Milliseconds()
return func(do *cr.DeleteOptions) { do.GracePeriodSeconds = &t }
}
func WithDeletePropagation(prop string) DeleteOption {
p := metav1.DeletionPropagation(prop)
return func(do *cr.DeleteOptions) { do.PropagationPolicy = &p }
} I hope doing this will not break some backward compatibility of the framework. |
cc @vladimirvivien which one do you think is the best way to get this one fixed ? |
FWIW I just hit the same thing with |
Thanks @ryanmcnamara for the comprehensive explanation of this issue. @harshanarayana I think your second proposal is closer to how other operations are done in the package. |
I will open a PR with these modified.. We can discuss further in that if we want to change something |
@harshanarayana I am taking a closer look. Using the cr.DeleteOption will be a one-of and will break backward compatibility. Let's do the first one. |
Sorry for confusion. |
No worries.. But it looks like PatchOption needs a fix too. |
Expected: Delete options passed into
Resources.Delete
are used by controller-runtimeActual: Delete options passed into
Resources.Delete
are removed by controller-runtimeCalling like
The cr delete options are set so that all fields are empty except for
Raw
.See
e2e-framework/klient/k8s/resources/resources.go
Line 139 in ce6e190
Controller runtime constructs its own DeleteOptions from these options here https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/client/typed_client.go#L80
This ends up calling https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/client/options.go#L300 which will result in still only
Raw
being setthen
AsDeleteOptions
is called at the end oftypedClient.Delete
which sets the fields ofRaw
directly from the member fields of theDeleteOptions
https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/client/options.go#L273, those fields are not set so it ends up zeroing out the fields ofRaw
.It seems like controller runtime does not expect
Raw
to be set and overrides all fields set in it.Confirmed the following workaround works:
The text was updated successfully, but these errors were encountered: