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

cosalib/meta.py: support sub schemas #1084

Merged
merged 2 commits into from
Feb 3, 2020
Merged

cosalib/meta.py: support sub schemas #1084

merged 2 commits into from
Feb 3, 2020

Conversation

darkmuggle
Copy link
Contributor

This adds support for discerning whether or not a sub-schema should
exist based on the name in 'meta.json' to support variants.

The new behavior to treat the main schema file as a basename. Any schema
that is found in the same directory with the basename is loaded. The
"name" field is then used to find any sub schemas. For example, given
"v1.json" with a build name of "fedora-coreos", a schema named
"fedora-coreos-v1.json" in the same directory will be applied.

fixtures/fcos.json: defined test JSON for Fedora CoreOS

src/schema/{fedora-coreos,rhcos}-v1.json: stub out for the different
schemas. This is to support the FCOS use of:
"fedora-coreos.parent-version" and
"fedora-coreos.parent-commit" keys.

tests/test_cosalib_meta.py: support testing both FCOS and RHCOS schemas

  • looks for all schemas in fixtures directory
  • validated the required items against both.

Makefile: set the directory for the test JSON.

@darkmuggle
Copy link
Contributor Author

In #1062 @jlebon asked for two "fedora-coreos" keys. This addresses that need while giving both Fedora CoreOS and RHCOS the ability to define "schema" extensions.

for k, v in self._validator.items():
if k in ("main", self.get("name")):
log.debug(f"validating against {k} schema")
v.validate(dict(self))
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, so this is just doing a sequential check of the various schemas, right? But I think one other really valuable part of validating against a schema is erroring/warning against unknown keys. Otherwise, e.g. it would not have prevented #1045 really.

Briefly looking through https://python-jsonschema.readthedocs.io/en/stable/, I couldn't find an option to specify multiple schemas to "overlay", which I think is understandable.

How about something like this:

  • we read in the OS-specific schema file, and add the properties items to the properties of the base schema
  • we turn on additionalProperties: false in the base schema

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Take another look :)

@darkmuggle
Copy link
Contributor Author

I need to fix the tests, but the latest push:

  • uses a strict schema (no more extra's allowed)
  • uses an enum to determine what is required.

@darkmuggle
Copy link
Contributor Author

@jlebon can I bother you for another review? I think this accomplishes what you suggested, while doing strict schema enforcement.

@darkmuggle
Copy link
Contributor Author

I need to fix the tests, but the latest push:

  • uses a strict schema (no more extra's allowed)
  • uses an enum to determine what is required.

Fixed up. The Schema is now:

  1. only allows "fedora-coreos" or "rhcos" as the name
  2. based on the name, it uses "anyOf" to enumerate the required elements.

I dropped the sub-schemas and the code around ingesting them

Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

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

Yeah, I think this is a good next step for sure! 👍

I feel a little uneasy about having to repeat the common properties between rhcos and fedora-coreos, but I think we can fix that up in a follow-up by defining them as a top-level named schema and then extending the RHCOS/FCOS-specific schemas using allOf within the anyOfs? (I'm looking at https://json-schema.org/understanding-json-schema/structuring.html#reuse and https://json-schema.org/understanding-json-schema/structuring.html#extending).

Leaving it open for a bit in case anyone else wants to take a look.

Copy link
Contributor

@arithx arithx left a comment

Choose a reason for hiding this comment

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

Seems sane to me

"fedora-coreos.parent-commit",
"fedora-coreos.parent-version",
"images",
"name",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't name be dropped from the anyOf of both rhcos & fedora-coreos because it's in the outer level required (line 8)?

],
"pattern":"^(.*)$"
"enum": [
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this is exhaustive? The whole idea is to support people doing custom builds, let's not force name to be one of those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to support hack builds by defining a "core" schema with the expected outputs for RHCOS and FCOS.

@jlebon
Copy link
Member

jlebon commented Jan 31, 2020

Looks like this needs a rebase now.

@jlebon
Copy link
Member

jlebon commented Jan 31, 2020

@petr-muller Any idea why the bot is being spammy here?

@darkmuggle
Copy link
Contributor Author

@cgwalters @arithx can you gentleman take another look? The schema is conditionalized so that unsupported builds (e.g. non-CoreOS) won't be broken.

@arithx
Copy link
Contributor

arithx commented Feb 3, 2020

Don't know if it's just github showing the commits wrong but all of the content is in the first commit (OWNERS: add OWNERS file for PROW integration)

Copy link
Contributor

@arithx arithx left a comment

Choose a reason for hiding this comment

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

LGTM

"examples": [
"fedora/x86_64/coreos/testing-devel"
],
"pattern":"^(?!\\s*$).+"
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: single quoting regex patterns to avoid having to escape backslashes can be nice

{
"if": {
"properties": {
"name": { "pattern": "^(rhcos|fedora-coreos)" }
Copy link
Member

Choose a reason for hiding this comment

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

Many of these are core properties emitted by coreos-assembler; I don't see why e.g. if someone is doing a custom build they shouldn't have coreos-assembler.basearch.

"coreos-assembler.config-dirty",
"coreos-assembler.config-gitrev",
"coreos-assembler.container-config-git",
"coreos-assembler.container-image-git",
Copy link
Member

Choose a reason for hiding this comment

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

Let's not make these required again please? I don't see a connection between "custom coreos-like builds" and "custom coreos-assembler builds inside an existing development container".

IOW, I want to be able to test patches to coreos-assembler and rpm-ostree inside my dev container, targeting all of fcos/rhcos and e.g. FCOSB.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that they are required for RHCOS and the purpose of the schema is to validate the results from builds. I am sympathetic towards your pain @cgwalters -- I am -- but your argument is a required production schema should be weakened for you as a developer based on your workflow.

#1089 was targeted at helping you out with this.

But the larger problem, IMO, is that we have developers who run their own pet container, while COSA expects certain things; that's the tension here. I'm open to ideas

Copy link
Member

Choose a reason for hiding this comment

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

I think delivering coreos-assembler as a container image has been very successful; I often tell people about that.

BUT I don't think we should entirely rule out e.g. shipping it as an RPM too.

And conceptually, these keys only cover the container build path.

And further, they duplicate metadata already available in the container metadata (OpenShift builds e.g. inject the git commit); unfortunately quay.io's build system is more primitive.

So I'm not sure I'd agree these keys are "required for RHCOS".

I guess I can just set the environment variable for now, it'll just be annoying.

Copy link
Member

Choose a reason for hiding this comment

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

I'll also chime in as a developer who hacks on cosa from his pet container. 🐕 I think it's important to cover that use-case. Not just for rpm-ostree/$util, but just overall I think it yields a faster edit-build-test feedback loop which makes hacking more pleasant. I've documented it in the README too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropped in the last push.

After(if) this merged I'll through up one that allows for per-recipe overrides.

This changes the v1.json schema is be aware of "fedora-coreos" and
"rhcos" builds. Using the "name" key, the schema is conditionally
applied.

fixtures/fcos.json: defined test JSON for Fedora CoreOS

tests/test_cosalib_meta.py: support testing both FCOS and RHCOS schemas

Makefile: set the directory for the test JSON.
@cgwalters
Copy link
Member

The other aspect to this debate is; maybe we want to drive down into coreos-assembler the concept of an "official" build; we can be more strict in that case. So it'd be e.g. the pipelines which do cosa build --official or something and that adds in the config git schemas rather than triggering off the name.

"coreos-assembler.config-gitrev",
"coreos-assembler.image-config-checksum",
"coreos-assembler.image-genver",
"coreos-assembler.image-input-checksum"
Copy link
Member

Choose a reason for hiding this comment

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

I think it's OK for all of these to be required too?

Unless we're trying to be compatible with older builds (whole rat's nest there)?

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 was going for the lowest common denominator here. The new schema is strict enough that having these as optional should be good enough IMHO.

Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

One optional comment, otherwise LGTM

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: arithx, cgwalters, darkmuggle, jlebon

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 [arithx,cgwalters,darkmuggle,jlebon]

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

@darkmuggle
Copy link
Contributor Author

The other aspect to this debate is; maybe we want to drive down into coreos-assembler the concept of an "official" build; we can be more strict in that case. So it'd be e.g. the pipelines which do cosa build --official or something and that adds in the config git schemas rather than triggering off the name.

I'll look into it.

@darkmuggle darkmuggle merged commit b19cdea into coreos:master Feb 3, 2020
@darkmuggle darkmuggle deleted the feature/sub-schemas branch February 18, 2020 21:48
jcajka pushed a commit to jcajka/coreos-assembler that referenced this pull request Mar 24, 2020
kola: Change distro default to fcos, drop cl
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.

5 participants