Skip to content
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

feat: helper function and constants for each component #50

Open
scottd018 opened this issue Jul 18, 2022 · 0 comments
Open

feat: helper function and constants for each component #50

scottd018 opened this issue Jul 18, 2022 · 0 comments
Labels
good first issue Good for newcomers

Comments

@scottd018
Copy link
Contributor

scottd018 commented Jul 18, 2022

We should export the Kind as a constant, also in the apis/<VERSION>/<COMPONENT>_types.go file. This will allow you to use the Kind without hard-coding the kind as a string.

const CertificatesComponentKind = "CertificatesComponent"

Additionally, it would be helpful to create helper methods to create a new object, in memory for each component that we generate in the apis/<VERSION>/<COMPONENT>_types.go file.

Consider the following:

	certComponent := &platformv1alpha1.CertificatesComponent{
		TypeMeta: metav1.TypeMeta{
			Kind: "CertificatesComponent",
			APIVersion: platformv1alpha1.GroupVersion.String(),
		},
		ObjectMeta: metav1.ObjectMeta{
			Name: destination.Name,
		},
	}

Could be a helper function (NOTE: Kind logic assumes the above constant has been implemented):

func NewCertificatesComponent(name, namespace string) *CertificatesComponent {
	return &CertificatesComponent{
		TypeMeta: metav1.TypeMeta{
			Kind: CertificatesComponentKind,
			APIVersion: platformv1alpha1.GroupVersion.String(),
		},
		ObjectMeta: metav1.ObjectMeta{
			Name: destination.Name,
		},
	}
}

Which could be consumed with:

certComponent := v1alpha1.NewCertificatesComponent("my-cert", "")
@scottd018 scottd018 added the good first issue Good for newcomers label Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant