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: Adds Workload interface to access PodSpec for all workload types #25

Merged
merged 3 commits into from
Sep 21, 2022

Conversation

hessjcg
Copy link
Collaborator

@hessjcg hessjcg commented Sep 21, 2022

Provide a consistent interface Workload and implementations that can access the PodSpec and other common k8s data structure for Pod, Deployment, StatefulSet, DaemonSet, Job, and CronJob.

…types

Provide a consistent interface Workload and implementations that can
access the PodSpec and other common k8s data structure for Pod,
Deployment, StatefulSet, DaemonSet, Job, and CronJob.
@hessjcg hessjcg requested a review from a team September 21, 2022 17:59
"sigs.k8s.io/controller-runtime/pkg/client"
)

// Workload interface a standard way to access the pod definition for the
Copy link
Member

Choose a reason for hiding this comment

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

Workload is a standard way...?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

// necessary configuration and other details before it starts, or if the
// configuration changes.
type Workload interface {
GetPodSpec() corev1.PodSpec
Copy link
Member

Choose a reason for hiding this comment

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

This should just be PodSpec. Cf. https://go.dev/doc/effective_go#Getters

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

type Workload interface {
GetPodSpec() corev1.PodSpec
SetPodSpec(spec corev1.PodSpec)
GetObject() client.Object
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here: Object will do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed.

},
}

t.Parallel()
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary until we have tests that aren't running fast.

}

// mustMakeWorkload is shorthand to create workload test inputs
func mustMakeWorkload(kind string, ns string, name string, l ...string) Workload {
Copy link
Member

Choose a reason for hiding this comment

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

This should take a *testing.T so you can fail the test rather than kill the process.

desc: "match kind, namespace, and labels",
sel: cloudsqlapi.WorkloadSelectorSpec{
Kind: "Pod",
Name: "",
Copy link
Member

Choose a reason for hiding this comment

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

Remember the zero value is already an empty string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

{
desc: "match namespace, and labels",
sel: cloudsqlapi.WorkloadSelectorSpec{
Kind: "",
Copy link
Member

Choose a reason for hiding this comment

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

Ditto here and below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

{
desc: "match namespace, and label expression",
sel: cloudsqlapi.WorkloadSelectorSpec{
Kind: "",
Copy link
Member

Choose a reason for hiding this comment

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

and here too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

case "DaemonSet":
v = &DaemonSetWorkload{DaemonSet: &appsv1.DaemonSet{TypeMeta: metav1.TypeMeta{Kind: "DaemonSet"}}}
default:
log.Fatalf("Workload kind %s not supported", kind)
Copy link
Member

Choose a reason for hiding this comment

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

This should be t.Fatalf.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

t is not in this context.

Copy link
Member

Choose a reason for hiding this comment

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

But it should be ;-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

v.GetObject().SetName(name)
if len(l) > 0 {
if len(l)%2 != 0 {
log.Fatalf("labels list must have an even number of elements")
Copy link
Member

Choose a reason for hiding this comment

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

t.Fatalf

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@hessjcg hessjcg requested a review from enocom September 21, 2022 19:01
@hessjcg hessjcg merged commit c6706ec into main Sep 21, 2022
@hessjcg hessjcg deleted the internal-workload-iface branch September 21, 2022 19:52
This was referenced Dec 7, 2022
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

Successfully merging this pull request may close these issues.

2 participants