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

Cronjob migration #1856

Merged
merged 15 commits into from
May 3, 2022
Merged

Conversation

kevinearls
Copy link
Contributor

Signed-off-by: Kevin Earls [email protected]

Which problem is this PR solving?

Short description of the changes

  • The function detectCronjobsVersion has been added to pkg/autodetect/main to determine what version of the API is available. To simplify migration CronJobs are passed as runtime.Object and cast where needed.

@codecov
Copy link

codecov bot commented Apr 13, 2022

Codecov Report

Merging #1856 (0a6f84d) into main (c09b71e) will decrease coverage by 1.47%.
The diff coverage is 67.45%.

@@            Coverage Diff             @@
##             main    #1856      +/-   ##
==========================================
- Coverage   89.44%   87.96%   -1.48%     
==========================================
  Files         100      100              
  Lines        6128     6274     +146     
==========================================
+ Hits         5481     5519      +38     
- Misses        471      558      +87     
- Partials      176      197      +21     
Impacted Files Coverage Δ
apis/v1/jaeger_types.go 87.50% <ø> (ø)
pkg/controller/jaeger/cronjob.go 47.45% <38.29%> (-30.33%) ⬇️
pkg/strategy/production.go 92.77% <53.84%> (-7.23%) ⬇️
pkg/strategy/streaming.go 94.48% <53.84%> (-4.07%) ⬇️
pkg/cronjob/es_rollover.go 78.75% <66.21%> (-17.19%) ⬇️
pkg/inventory/cronjob.go 71.42% <68.00%> (-28.58%) ⬇️
pkg/cronjob/spark_dependencies.go 83.20% <78.33%> (-9.40%) ⬇️
pkg/autodetect/main.go 86.51% <78.57%> (-0.68%) ⬇️
pkg/cronjob/es_index_cleaner.go 84.09% <80.64%> (-13.14%) ⬇️
pkg/strategy/all_in_one.go 95.74% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c09b71e...0a6f84d. Read the comment docs.

@kevinearls kevinearls marked this pull request as ready for review April 26, 2022 12:26
@kevinearls
Copy link
Contributor Author

@rubenvp8510 @pavolloffay Please review. I realize this reduces code coverage slightly, but updating the tests to cover both batch/v1 and batch/v1beta1 would reuire lots of cut and paste or code changes that would be difficult to back out when we no longer need to support batch/v1beta1

Copy link
Member

@frzifus frzifus left a comment

Choose a reason for hiding this comment

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

Looks good, i just have some formal questions :)

for _, apiGroupVersion := range apiGroupVersions {
groupAPIList, err := b.dcl.ServerResourcesForGroupVersion(apiGroupVersion)
if err != nil {
log.Errorf("Error getting %s api list: %v", apiGroupVersion, err)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to get a logger form context?

iam asking because of this #1817

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, there might be, but I don't know how to do that.

Copy link
Member

@frzifus frzifus Apr 27, 2022

Choose a reason for hiding this comment

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

I think its something like

import "sigs.k8s.io/controller-runtime/pkg/log"
...
logger := log.FromContext(ctx)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Can we do that as part of #1817 though?

Copy link
Member

Choose a reason for hiding this comment

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

ok 👍

Schedule: jaeger.Spec.Storage.EsRollover.Schedule,
SuccessfulJobsHistoryLimit: jaeger.Spec.Storage.EsRollover.SuccessfulJobsHistoryLimit,
JobTemplate: batchv1beta1.JobTemplateSpec{
Spec: batchv1.JobSpec{
Copy link
Member

Choose a reason for hiding this comment

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

Does it need to be a batchv1beta1.JobSpec here?

Another thing, i wonder if we could get rid of this huge if else thing. while scrolling up and down i noticed it a few times. From my point of view, its easy to make mistakes in case of adaption. On the other hand, if we want to support a 3rd version in future releases, it feels be hard to extend too.

if cronjobsVersion == v1.CronJobsVersionBatchV1Beta1 { .. } else { .. }
// replaced by
func newCronJob(cronJobVer, ObjectMeta, ...opts) (interface{}, error) 
// or a structure that can be converted into both?
type ourCronJob struct {}
func (ourCronJob) convert(cronJobVer) (any, bool)

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually batchv1.JobSpec is available as in k8s 1.19 (See https://github.com/kubernetes/api/blob/release-1.19/batch/v1beta1/types.go#L53) I have extracted the JobSpec definition to make things a bit shorter.

I would love to get rid of the big if/else statements, and tried to do so as much as possible. However, I guess I tried to balance the amount of work vs. benefits. We're hopefully not going to be supporting two versions of the same API in one image for very long. Once 1.21 is the oldest API we have to support we can just rip all of this stuff out.

I'll take another look in the morning though and see if I can get anything working

return tracing.HandleError(err, span)
}
}
} else {
Copy link
Member

Choose a reason for hiding this comment

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

same here

@@ -17,6 +17,12 @@ type JaegerPhase string
type JaegerStorageType string

const (
// CronJobsVersionBatchV1 represents the batch/v1 version of the kubernetes CronJob api, available as of 1.21
CronJobsVersionBatchV1 = "batch/v1"
Copy link
Member

Choose a reason for hiding this comment

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

These (and the one below) env vars do not belong here.

This file/package should contain types are used in the CRD.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pavolloffay where should I define these?

Copy link
Member

Choose a reason for hiding this comment

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

Actually FlagPlatformOpenShift is defined in this file as well so for consistency we can keep it here.

It the batch version is exposed as flag (similar to platform) then I would suggest aligning the name to Flag as well.

@kevinearls
Copy link
Contributor Author

@rubenvp8510 @pavolloffay Please review

Copy link
Member

@frzifus frzifus left a comment

Choose a reason for hiding this comment

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

up to the others :)

@kevinearls
Copy link
Contributor Author

@rubenvp8510 Thanks for the approval. Can you merge this?

@rubenvp8510 rubenvp8510 merged commit 32e6ca7 into jaegertracing:main May 3, 2022
@kevinearls kevinearls deleted the cronjob-migration branch May 3, 2022 15:16
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.

Migrate CronJob from batch/v1beta1 to batch/v1
4 participants