fix: expose attachment readonly and volume_options in storage:list json

The `storage:list <app> --format json` payload conflated the
attachment's `Readonly` flag and its `VolumeOptions` field into a
single derived `volume_options` string that rendered as `ro`,
`<options>`, or `ro,<options>` depending on which fields were set on
the underlying attachment. That shape is fine for the legacy
`host:container[:options]` text view but it leaves drift-detection
tooling unable to tell whether a `ro` token came from
`Attachment.Readonly == true` or from the operator setting
`Attachment.VolumeOptions = "ro"` directly. The JSON now exposes
`readonly` (boolean) and `volume_options` (string) as separate
omitempty keys populated straight from the attachment, and
`formatStorageListEntry` combines them at format time for the colon-
form text view. `ParseMountPath` was extended in lockstep so callers
of the legacy `host:container:opts` form no longer have to special-
case the `ro` token themselves.
This commit is contained in:
Jose Diaz-Gonzalez
2026-05-30 03:00:21 -04:00
parent f4d27be7a6
commit e9160db769
7 changed files with 118 additions and 38 deletions

View File

@@ -69,16 +69,35 @@ func TestParseMountPath(t *testing.T) {
entry := ParseMountPath("/host/path:/container/path")
Expect(entry.HostPath).To(Equal("/host/path"))
Expect(entry.ContainerPath).To(Equal("/container/path"))
Expect(entry.Readonly).To(BeFalse())
Expect(entry.VolumeOptions).To(BeEmpty())
entry = ParseMountPath("/host/path:/container/path:ro")
Expect(entry.HostPath).To(Equal("/host/path"))
Expect(entry.ContainerPath).To(Equal("/container/path"))
Expect(entry.VolumeOptions).To(Equal("ro"))
Expect(entry.Readonly).To(BeTrue())
Expect(entry.VolumeOptions).To(BeEmpty())
entry = ParseMountPath("/host/path:/container/path:Z")
Expect(entry.HostPath).To(Equal("/host/path"))
Expect(entry.ContainerPath).To(Equal("/container/path"))
Expect(entry.Readonly).To(BeFalse())
Expect(entry.VolumeOptions).To(Equal("Z"))
entry = ParseMountPath("/host/path:/container/path:ro,Z")
Expect(entry.HostPath).To(Equal("/host/path"))
Expect(entry.ContainerPath).To(Equal("/container/path"))
Expect(entry.Readonly).To(BeTrue())
Expect(entry.VolumeOptions).To(Equal("Z"))
entry = ParseMountPath("/host/path:/container/path:noexec,nosuid,ro")
Expect(entry.Readonly).To(BeTrue())
Expect(entry.VolumeOptions).To(Equal("noexec,nosuid"))
entry = ParseMountPath("volume_name:/container/path")
Expect(entry.HostPath).To(Equal("volume_name"))
Expect(entry.ContainerPath).To(Equal("/container/path"))
Expect(entry.Readonly).To(BeFalse())
Expect(entry.VolumeOptions).To(BeEmpty())
}