Skip to content

Common interface for SetControllerReference #666

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

Closed
Adirio opened this issue Oct 30, 2019 · 1 comment
Closed

Common interface for SetControllerReference #666

Adirio opened this issue Oct 30, 2019 · 1 comment

Comments

@Adirio
Copy link
Contributor

Adirio commented Oct 30, 2019

Is there any reason not to combine metav1.Object and runtime.Object into a single MetaV1RuntimeObject interface?

type MetaV1RuntimeObject interface {
	metav1.Object
	runtime.Object
}

SetControllerReference is casting a metav1.Object into a runtime.Object which means that if this fails it will fail at run time instead of compile time.

https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/controller/controllerutil/controllerutil.go#L57-L89

func SetControllerReference(owner, object metav1.Object, scheme *runtime.Scheme) error {
	ro, ok := owner.(runtime.Object)
	if !ok {
		return fmt.Errorf("%T is not a runtime.Object, cannot call SetControllerReference", owner)
	}

	// ...
}

would be turned into

func SetControllerReference(owner MetaV1RuntimeObject, object metav1.Object, scheme *runtime.Scheme) error {
	// ...
}
@alexeldeib
Copy link
Contributor

#594

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants