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 'envFrom' generic configuration for backend spec #657

Merged
merged 1 commit into from
May 17, 2022

Conversation

sashokbg
Copy link

@sashokbg sashokbg commented May 9, 2022

Summary

Added envFrom configuration for backends
EnvFrom can be used to add arbitrary env variables 'in bulk' to the job container template.
This feature can be useful in implementing some generic authentication

Signed-off-by: Alexander KIRILOV aleksandar.kirilov@proxym.fr

Checklist

  • Keep pull requests small so they can be easily reviewed.
  • Categorize the PR by setting a good title and adding one of the labels:
    bug, enhancement, documentation, change, breaking,
    as they show up in the changelog
  • Update the documentation.
  • Update tests.
  • Link this PR to related issues.

@sashokbg sashokbg requested a review from a team as a code owner May 9, 2022 21:48
@sashokbg sashokbg requested review from simu and Kidswiss and removed request for a team May 9, 2022 21:48
@ccremer ccremer added the enhancement New feature or request label May 10, 2022
@ccremer ccremer requested review from ccremer and removed request for simu May 10, 2022 07:36
@Kidswiss
Copy link
Contributor

Hi @sashokbg

Thanks for your contribution! I'm having a look at this right now.

Copy link
Contributor

@Kidswiss Kidswiss left a comment

Choose a reason for hiding this comment

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

Overall LGTM.

Just one minor thing, so that it works as intended.

EDIT: just had a look at the failing test, there seems to be some nil pointer problem.

operator/executor/backup.go Outdated Show resolved Hide resolved
@Kidswiss
Copy link
Contributor

@sashokbg there should probably be a check for a nil backend before accessing the EnvFrom. Otherwise, a backup or schedule definition without a backend crashes the operator.

@sashokbg
Copy link
Author

@Kidswiss I am really sorry for the question but since it is my first time writing Go code - how should I implement the null check ?
A simple will work ?

if restore.Spec.Backend.EnvFrom != nil {
	j.Spec.Template.Spec.Containers[0].EnvFrom = restore.Spec.Backend.EnvFrom
}

@Kidswiss
Copy link
Contributor

@sashokbg No need to apologize :)

You'll need to check the backend itself for nil:

if restore.Spec.Backend!= nil {
	j.Spec.Template.Spec.Containers[0].EnvFrom = restore.Spec.Backend.EnvFrom
}

The problem arises because you want to access a field of backend. The actual envFrom being nil should be fine.

@sashokbg
Copy link
Author

@Kidswiss thank you for your feedback - I have updated the PR to reflect the requested changes. I have tested the integration tests locally and everything passes

Copy link
Contributor

@ccremer ccremer left a comment

Choose a reason for hiding this comment

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

Hi.
Thanks for this high-quality PR! I was rather surprised to see a tutorial page :)

A few styling suggestions in the documentation, and some overlooked nil checks.

Additionally, I would love to see unit tests added that verify this nil check. Mainly to ensure that a later refactoring or code doesn't introduce a regression later on.

api/v1/backend.go Outdated Show resolved Hide resolved
operator/executor/archive.go Outdated Show resolved Hide resolved
operator/executor/prune.go Outdated Show resolved Hide resolved
@sashokbg
Copy link
Author

Hello @ccremer I will try to add a couple of unit tests to cover the null exception. Being a total novice in go this will probably take me a some time :)

Copy link
Contributor

@ccremer ccremer left a comment

Choose a reason for hiding this comment

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

I had a look at it again and I figured we could optimize the code a bit.
Instead of doing a nil check in every occurrence, we add a function to the spec struct that accepts a container spec and adds the env vars. That way this should be easier to unit test and the logic is in a single place only.

type RunnableSpec struct {

func (in *RunnableSpec) AppendEnvFromToContainer(containerSpec *corev1.ContainerSpec) {
  if in.Backend != nil {
    containerSpec.EnvFrom = append(containerSpec.EnvFrom, in.Backend.EnvFrom...)
  }
}

then in each executor instead of the nil check call the function like this:

  b.backup.Spec.AppendEnvFromToContainer(&backupJob.Spec.Template.Spec.Containers[0])

WDYT?

@sashokbg
Copy link
Author

Hello @ccremer thank you for your time and helpful feedback. I think what you proposed is a good idea and went ahead and implemented it as you specified. I have also included a unit test that tests the new function

Copy link
Contributor

@ccremer ccremer left a comment

Choose a reason for hiding this comment

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

Actually I've found something to be missing

@ccremer ccremer changed the title Enhancement - Added envFrom configuration for backends Add 'envFrom' generic configuration for backend spec May 13, 2022
Copy link
Contributor

@ccremer ccremer left a comment

Choose a reason for hiding this comment

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

I think you need to amend your commits for the DCO checks, other than that it's LGTM

Copy link
Contributor

@Kidswiss Kidswiss left a comment

Choose a reason for hiding this comment

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

I like the idea of moving it to it's own method.

LGTM

@sashokbg sashokbg force-pushed the feat/envFrom branch 2 times, most recently from 76c7a7d to 8c7f8bc Compare May 16, 2022 19:47
EnvFrom can be used to add arbitrary env varibles 'in bulk' to the job container template

This feature can be useful in implementing some generic authentication

Signed-off-by: Alexander KIRILOV <aleksandar.kirilov@proxym.fr>

Co-authored-by: Chris <github.account@chrigel.net>
@ccremer ccremer merged commit 52bd1a7 into k8up-io:master May 17, 2022
@ccremer
Copy link
Contributor

ccremer commented May 17, 2022

@sashokbg thank you for your contribution 🎉

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

Successfully merging this pull request may close these issues.

None yet

3 participants