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

ERB template rendering code review: rename old bosh v1 names to v2 #2479

Merged
merged 5 commits into from
Jan 11, 2024

Conversation

bgandon
Copy link
Contributor

@bgandon bgandon commented Nov 28, 2023

What is this change about?

Here, I’ve reviewed the ERB template rendering code in order to document it in the cloudfoundry/docs-bosh#813 PR.

In that part of the Director’s code, I’ve noticed many misleading use of the term “template”, used instead of “job”. And this makes the code very confusing because “template” could also refer to “ERB template”.

So, I’ve started chasing these names that had not been migrated back in 2017 (when Bosh v1→v2 refactoring effort had been conducted), and I’ve looked for more suitable names. Don’t hesitate to challenge these, by the way.

Then I’ve updated the unit tests. Here also I’ve tried to clarify some ambiguous namings.

In that process, I’ve noticed that when rendering ERB templates, the job name was read from job.MF, freshly extracted from the job blob, whereas the name already persisted in database. I’ve removed the unnecessary unmarshalling of job.MF and added a name verification at release-upload time.

The modifications in this PR are quite large overall, but I’ve paid great attention in separating this into smaller chunks of work in to the individual commits.

Please provide contextual information.

This work was done in order to gather information for authoring cloudfoundry/docs-bosh#813.

What tests have you run against this PR?

Successful run of these test suites:

bundle exec rake spec:unit:parallel

DB=sqlite     bundle exec rake spec:unit:director
DB=postgresql bundle exec rake spec:unit:director
DB=mysql      bundle exec rake spec:unit:director

How should this change be described in bosh release notes?

This change brings no new feature, and only more clarity in the ERB rendering code.

Does this PR introduce a breaking change?

Definitely not.

Tag your pair, your PM, and/or team!

I’m a poor lonesome cowboy 😄

@bgandon bgandon marked this pull request as draft November 28, 2023 10:23
@bgandon bgandon marked this pull request as ready for review November 28, 2023 11:22
@jpalermo jpalermo requested review from a team, ragaskar and mvach and removed request for a team November 30, 2023 15:41
@rkoster
Copy link
Contributor

rkoster commented Dec 14, 2023

@bgandon did you get a change yet to look at the changes requested by Aram?

@bgandon
Copy link
Contributor Author

bgandon commented Dec 21, 2023

Sorry for the delay @rkoster, I’ve answered the comments indeed.

Thank you @aramprice for the very valuable review. You’ve pointed out choices that definitely needed some details indeed 👍

I’ve updated the typos, modified the names for fake jobs, and rebased the code on top of the main branch.

Please tell me what you think of the choices that I’ve detailed in my answers to your comments, thank you!

@bgandon bgandon force-pushed the rename-old-bosh-v1-names-to-v2 branch from 653f007 to 7d8218d Compare December 21, 2023 17:07
- Rename job_template(s) [Bosh v1] -> instance_job(s) [Bosh v2]
- Rename spec [ambiguous] -> spec_object [clarified: related to ERB-templates]
- Rename remove_unused_properties [double-negative] -> pick_job_properties [affirmative]
- Rename hash [imprecise] -> renderers_hash [clarified contents]
- Ensure that (job_name_from_manifest == instance_job.name) while we re-read
  the job manifest (though there is actually no reason to re-read it)
- Reword "Cannot unpack job template" [incorrect] -> "Cannot unpack job blob" [correct]
- Rename @name [imprecise] -> @job_name [precised]
- Remove duplicate @template_name [Bosh v1] identical to @job_name [Bosh v2]
- Rename template_name [Bosh v1] -> job_name [Bosh v2]
- Rename template_spec_properties [incorrect] -> instance_group_properties [correct]
- Rename instance_name [incorrect] -> instance_group_name [correct]
- Rename acc [accessory?] -> accu [accumulator!]
- Alias instance_plan.templates [Bosh v1] -> instance_jobs [Bosh v2]
- Don't rename fields in the 'template' model (don't touch models)
- Favor using spec['name'] over spec['job']['name'] (Bosh v1 naming) for
  obtaining the instance group name.
…g ERBs

Indeed we already know the job name and template list, as these data are
persisted when a release is uploaded to the director.

This makes unnecessary to verify that the job name is consistent at ERB
rendering time.

And this consistency check is more relevant when done at the time a release
job is uploaded to the director.
@bgandon bgandon force-pushed the rename-old-bosh-v1-names-to-v2 branch from 7d8218d to ce48af2 Compare December 21, 2023 17:13
Copy link
Member

@aramprice aramprice left a comment

Choose a reason for hiding this comment

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

thanks for the improvements!

@bgandon
Copy link
Contributor Author

bgandon commented Jan 4, 2024

Due to the large diff, we are waiting for a second review, thanks for anyone that can do it!

Copy link
Member

@jpalermo jpalermo left a comment

Choose a reason for hiding this comment

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

👍

A lot of changes, but functionally seems to be the same. A lot of great cleanup though.

Thanks!

@rkoster
Copy link
Contributor

rkoster commented Jan 11, 2024

Thanks! @bgandon

@rkoster rkoster merged commit f92cef4 into main Jan 11, 2024
4 checks passed
@rkoster rkoster deleted the rename-old-bosh-v1-names-to-v2 branch January 11, 2024 15:37
@aramprice
Copy link
Member

aramprice commented Jan 12, 2024

NOTE: leaving this comment here as a breadcrumb for folks who might encounter similar breakage in the future.

This change appears to have exposed a problem with src/spec/assets/valid_release.tgz.

Integration tests which attempt to deploy this release using a command similar to:

bosh [redacted args] upload-release src/spec/assets/valid_release.tgz

Fail with the following error:

Using environment 'https://127.0.0.1:62404' as client 'test'
[-----------------------------------------------------------------] 100.00%   0s
Task 6

Task 6 | 17:40:22 | Extracting release: Extracting release (00:00:00)
Task 6 | 17:40:22 | Verifying manifest: Verifying manifest (00:00:00)
Task 6 | 17:40:22 | Resolving package dependencies: Resolving package dependencies (00:00:00)
Task 6 | 17:40:22 | Creating new packages: stuff/0.1.17 (00:00:01)
Task 6 | 17:40:23 | Creating new packages: mutator/2.99.7 (00:00:00)
Task 6 | 17:40:23 | Creating new jobs: cacher/1a (00:00:00)
                 L Error: Inconsistent name for job 'cacher'(exptected: 'cacher', got: '')
Task 6 | 17:40:23 | Error: Inconsistent name for job 'cacher'(exptected: 'cacher', got: '')

Task 6 Started  Thu Jan 11 17:40:22 UTC 2024
Task 6 Finished Thu Jan 11 17:40:23 UTC 2024
Task 6 Duration 00:00:01
Task 6 error

This is being run from spec/integration/release/export_release_spec.rb:222

@beyhan
Copy link
Member

beyhan commented Jan 12, 2024

I didn't have time to get to the bottom of this but it looks like there is a new validation now

def validate_name(job_manifest)
unless name == job_manifest['name']
raise JobInvalidName, "Inconsistent name for job '#{name}'" +
"(exptected: '#{name}', got: '#{job_manifest['name']}')"
end
end

Actually this change shouldn't have any behaviour changes. @bgandon why that check was added?

@aramprice
Copy link
Member

aramprice commented Jan 12, 2024

@beyhan - nice find! No need to dig in I only figured this out at the end of my yesterday.

It's likely that src/spec/assets/valid_release.tgz is making some "bosh v1" assumptions.

aramprice added a commit that referenced this pull request Jan 12, 2024
The pr #2479 introduced a
validation which asserts that the `name` key in `job.MF` must match the
Job's name. The test fixture `valid_release.tgz` did not have an `name`
key it any of the `job.MF` files.
This commit updates the contents of `valid_release.tgz` so that the
`name` key is present in `job.MF`. In addition to the required elements,
the `.tgz` contians the un-archived job directories with the contents of
the various $JOB.tgz files which are included in the release.

Without these fixes on is likely to see the following error when running
the integration suite:
```
Task 6 | 04:43:18 | Creating new jobs: cacher/1a (00:00:00)
                 L Error: Inconsistent name for job 'cacher'(exptected: 'cacher', got: '')
Task 6 | 04:43:18 | Error: Inconsistent name for job 'cacher'(exptected: 'cacher', got: '')
```

See
#2479 (comment)
for more context.
@aramprice
Copy link
Member

Hopefully fixed with e42f767

@beyhan
Copy link
Member

beyhan commented Jan 15, 2024

@aramprice thanks for the heads-up. I also saw that the last update of that release was way back in 2015 and had an old structure. Is the support for "bosh v1" removed with this refactoring or it was already the case and the validation here just shows it? If it is with this pr I would suggest to have this in the release notes. FYI @rkoster, @jpalermo

@jpalermo
Copy link
Member

I think v1 manifests should still work, I don't think release job spec file structure changed much between v1 and v2, and I would have thought it was "required" that jobs in v1 also had a name that matched their actual name.

I kinda bet something blows up at some point if this isn't true, so I don't think this is really a change in behavior, probably just surfaces the error sooner. (could be wrong about all of this though)

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

Successfully merging this pull request may close these issues.

5 participants