Skip to content

Commit 5b5b572

Browse files
committed
Stabilize the current schema
There's...a variety of warts in the current API schema. In particular I really dislike `.image.image.image`. But...but...changing it now would in practice be somewhat difficult, and it's hard to say that just *that* tweak would be really useful. Let's just stabilize the existing spec as `v1` and commit to maintaining it. We've already added notes to ask callers to use `--format-version 1` to specify what they want so we can compatibly add new things in the future. Speaking of, this also makes `--format-version=1` be the same thing as `--format-version=0` so that all the versions are just "1". Closes: #518 Signed-off-by: Colin Walters <[email protected]>
1 parent 2fbda2a commit 5b5b572

File tree

11 files changed

+59
-21
lines changed

11 files changed

+59
-21
lines changed

docs/src/bootc-via-api.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@ At the current time, bootc is primarily intended to be
44
driven via a fork/exec model. The core CLI verbs
55
are stable and will not change.
66

7-
## Using `bootc edit` and `bootc status --json --format-version=0`
7+
## Using `bootc edit` and `bootc status --json`
88

99
While bootc does not depend on Kubernetes, it does currently
1010
also offere a Kubernetes *style* API, especially oriented
1111
towards the [spec and status and other conventions](https://kubernetes.io/docs/reference/using-api/api-concepts/).
1212

1313
In general, most use cases of driving bootc via API are probably
1414
most easily done by forking off `bootc upgrade` when desired,
15-
and viewing `bootc status --json --format-version=0`.
15+
and viewing `bootc status --json --format-version=1`.
1616

1717
## JSON Schema
1818

19-
The current API is classified as `org.containers.bootc/v1alpha1` but
20-
it will likely be officially stabilized mostly as is. However,
21-
you should still request the current "v0" format via an explicit
22-
`--format-version=0` as referenced above.
19+
The current API `org.containers.bootc/v1` is stable.
20+
In order to support the future introduction of a v2
21+
or newer format, please change your code now to explicitly
22+
request `--format-version=1` as referenced above. (Available
23+
since bootc 0.1.15, `--format-version=0` in bootc 0.1.14).
2324

2425
There is a [JSON schema](https://json-schema.org/) generated from
25-
the Rust source code available here: [host-v0.schema.json](host-v0.schema.json).
26+
the Rust source code available here: [host-v1.schema.json](host-v1.schema.json).
2627

2728
A common way to use this is to run a code generator such as
2829
[go-jsonschema](https://github.com/omissis/go-jsonschema) on the

docs/src/host-v0.schema.json renamed to docs/src/host-v1.schema.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@
9999
"pinned": {
100100
"description": "Whether this entry will be subject to garbage collection",
101101
"type": "boolean"
102+
},
103+
"store": {
104+
"description": "The container storage backend",
105+
"default": null,
106+
"anyOf": [
107+
{
108+
"$ref": "#/definitions/Store"
109+
},
110+
{
111+
"type": "null"
112+
}
113+
]
102114
}
103115
}
104116
},
@@ -366,6 +378,18 @@
366378
]
367379
}
368380
}
381+
},
382+
"Store": {
383+
"description": "The container storage backend",
384+
"oneOf": [
385+
{
386+
"description": "Use the ostree-container storage backend.",
387+
"type": "string",
388+
"enum": [
389+
"ostreeContainer"
390+
]
391+
}
392+
]
369393
}
370394
}
371395
}

lib/src/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ pub(crate) struct StatusOpts {
132132
pub(crate) format: Option<OutputFormat>,
133133

134134
/// The desired format version. There is currently one supported
135-
/// version, which is version `0`. Pass this option to explicitly
136-
/// request it; it is possible that multiple versions will be
137-
/// supported in the future.
135+
/// version, which is exposed as both `0` and `1`. Pass this
136+
/// option to explicitly request it; it is possible that another future
137+
/// version 2 or newer will be supported in the future.
138138
#[clap(long)]
139139
pub(crate) format_version: Option<u32>,
140140

lib/src/fixtures/spec-v1-null.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"apiVersion":"org.containers.bootc/v1","kind":"BootcHost","metadata":{"name":"host"},"spec":{"image":null,"bootOrder":"default"},"status":{"staged":null,"booted":null,"rollback":null,"rollbackQueued":false,"type":null}}
File renamed without changes.
File renamed without changes.

lib/src/spec.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
88

99
use crate::k8sapitypes;
1010

11-
const API_VERSION: &str = "org.containers.bootc/v1alpha1";
11+
const API_VERSION: &str = "org.containers.bootc/v1";
1212
const KIND: &str = "BootcHost";
1313
/// The default object name we use; there's only one.
1414
pub(crate) const OBJECT_NAME: &str = "host";
@@ -226,8 +226,15 @@ mod tests {
226226
use super::*;
227227

228228
#[test]
229-
fn test_parse_spec_v0() {
230-
const SPEC_FIXTURE: &str = include_str!("fixtures/spec.yaml");
229+
fn test_parse_spec_v1_null() {
230+
const SPEC_FIXTURE: &str = include_str!("fixtures/spec-v1-null.json");
231+
let host: Host = serde_json::from_str(SPEC_FIXTURE).unwrap();
232+
assert_eq!(host.resource.api_version, "org.containers.bootc/v1");
233+
}
234+
235+
#[test]
236+
fn test_parse_spec_v1a1_orig() {
237+
const SPEC_FIXTURE: &str = include_str!("fixtures/spec-v1a1-orig.yaml");
231238
let host: Host = serde_yaml::from_str(SPEC_FIXTURE).unwrap();
232239
assert_eq!(
233240
host.spec.image.as_ref().unwrap().image.as_str(),
@@ -236,8 +243,8 @@ mod tests {
236243
}
237244

238245
#[test]
239-
fn test_parse_spec_v1() {
240-
const SPEC_FIXTURE: &str = include_str!("fixtures/spec-v1.yaml");
246+
fn test_parse_spec_v1a1() {
247+
const SPEC_FIXTURE: &str = include_str!("fixtures/spec-v1a1.yaml");
241248
let host: Host = serde_yaml::from_str(SPEC_FIXTURE).unwrap();
242249
assert_eq!(
243250
host.spec.image.as_ref().unwrap().image.as_str(),

lib/src/status.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ pub(crate) fn get_status(
285285
#[context("Status")]
286286
pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
287287
match opts.format_version.unwrap_or_default() {
288-
0 => {}
288+
// For historical reasons, both 0 and 1 mean "v1".
289+
0 | 1 => {}
289290
o => anyhow::bail!("Unsupported format version: {o}"),
290291
};
291292
let host = if !Utf8Path::new("/run/ostree-booted").try_exists()? {

tests/booted/readonly/001-test-status.nu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use tap.nu
44
tap begin "verify bootc status output formats"
55

66
let st = bootc status --json | from json
7-
assert equal $st.apiVersion org.containers.bootc/v1alpha1
7+
assert equal $st.apiVersion org.containers.bootc/v1
88
let st = bootc status --json --format-version=0 | from json
9-
assert equal $st.apiVersion org.containers.bootc/v1alpha1
9+
assert equal $st.apiVersion org.containers.bootc/v1
1010
let st = bootc status --format=yaml | from yaml
11-
assert equal $st.apiVersion org.containers.bootc/v1alpha1
11+
assert equal $st.apiVersion org.containers.bootc/v1
1212
tap ok

tests/booted/readonly/basic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ def run(*args):
99
def test_bootc_status():
1010
o = subprocess.check_output(["bootc", "status", "--json"])
1111
st = json.loads(o)
12-
assert st['apiVersion'] == 'org.containers.bootc/v1alpha1'
12+
assert st['apiVersion'] == 'org.containers.bootc/v1'
13+
for v in [0, 1]:
14+
o = subprocess.check_output(["bootc", "status", "--json", f"--format-version={v}"])
15+
st = json.loads(o)
16+
assert st['apiVersion'] == 'org.containers.bootc/v1'
1317

1418
def test_bootc_status_invalid_version():
1519
o = subprocess.call(["bootc", "status", "--json", "--format-version=42"])

0 commit comments

Comments
 (0)