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

Add additional core functions #48

Conversation

ChristianZaccaria
Copy link
Contributor

@ChristianZaccaria ChristianZaccaria commented May 21, 2024

Issue link

Jira: https://issues.redhat.com/browse/RHOAIENG-7487

What changes have been made

Added several core functions that are being used in this PR: project-codeflare/codeflare-operator#549

Verification steps

Tests should pass.

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • Testing is not required for this change

support/core.go Outdated
Comment on lines 188 to 196
func GetContainerName(t Test, container corev1.Container) string {
t.T().Helper()
t.Expect(container.Name).Should(gomega.Not(gomega.BeEmpty()))
return container.Name
}

func GetVolumeName(t Test, volume corev1.Volume) string {
t.T().Helper()
t.Expect(volume.Name).Should(gomega.Not(gomega.BeEmpty()))
return volume.Name
}

func GetServiceAccountName(t Test, serviceAccount corev1.ServiceAccount) string {
t.T().Helper()
t.Expect(serviceAccount.Name).Should(gomega.Not(gomega.BeEmpty()))
return serviceAccount.Name
}

func GetVolumeMountName(t Test, volumeMount corev1.VolumeMount) string {
t.T().Helper()
t.Expect(volumeMount.Name).Should(gomega.Not(gomega.BeEmpty()))
return volumeMount.Name
}

func GetEnvVarName(t Test, envVar corev1.EnvVar) string {
t.T().Helper()
t.Expect(envVar.Name).Should(gomega.Not(gomega.BeEmpty()))
return envVar.Name
}
Copy link
Contributor

@sutaakar sutaakar May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of it can be replaced by:

func ResourceName(meta metav1.Object) string {
	return meta.GetName()
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note - for such helper functions I usually don't put Get prefix as the function doesn't query Kubernetes to get the object, just retrieving internal value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand how all those functions can be replaced by the func ResourceName(meta metav1.Object). They are of different type where we would be getting the name of the top-level resource such as a pod, as opposed to the embedded resources.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I didn't check that before. Unfortunately it seems they can't be replaced.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can attempt to replace all functions for:

func ResourceName(t Test, obj any) string {
	t.T().Helper()
	t.Expect(reflect.ValueOf(obj).Kind()).Should(gomega.Equal(reflect.Struct), "input must be a struct")
	nameField := reflect.ValueOf(obj).FieldByName("Name")
	return nameField.String()
}

support/core.go Outdated Show resolved Hide resolved
support/core.go Outdated
@@ -184,3 +185,10 @@ func GetNodeInternalIP(t Test, node corev1.Node) (IP string) {

return
}

func ResourceName(t Test, obj any) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the function can have just one argument - the struct used to retrieve its field from.
Otherwise it can't be used in WithTransform function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! Thanks Karel - Fixed.

Copy link

openshift-ci bot commented May 28, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ChristianZaccaria, sutaakar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [ChristianZaccaria,sutaakar]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 68eadc2 into project-codeflare:main May 28, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants