many: pipeline mounts#2458
Conversation
Allow adding default mounts to a pipeline. If defaults mounts are set then they will be used for all stages. If a stage carries its own additional mounts they will be appended to the default mounts. Signed-off-by: Simon de Vlieger <cmdr@supakeen.com>
In the ostree deployment pipeline generator use the default mount points. During this I realize that there are still some stages that opt out. I don't particularly like the idiom so I''ll probably do a commit later that passes an additional boolean or such to skip default mounts for `AddStage(s)`. Signed-off-by: Simon de Vlieger <cmdr@supakeen.com>
Allow adding default devices to a pipeline. If default devices are set then they will be used for all stages. If a stage carries its own additional devices they will be appended to the default devices. Signed-off-by: Simon de Vlieger <cmdr@supakeen.com>
Set up default mounts for the raw_bootc pipeline generator instead of repeating them for every stage. A few stages still opt out as they don't need or want the mounts. Signed-off-by: Simon de Vlieger <cmdr@supakeen.com>
Not the topic here, but I'm not fully onboard with this just yet. The current order has some benefits, like exporting the OS pipeline result for inspection. And there's also the potential future benefit of reproducibility with |
achilleas-k
left a comment
There was a problem hiding this comment.
Generally a good idea. Some comments below about naming and behaviour details.
I initially missed that the way to opt out of adding stages without applying the defaults is to append to the pipeline's stages directly. That's a bit messy. Not a huge problem, we do similar things when we want to prepend stages, but it might be nicer to make the Pipeline API more useful by having methods that do these things (appending stages, prepending stages, adding with or without defaults, etc) in a consistent way with sanity checking so that we don't have to be appending elements to slices directly.
I'd be curious to see how many stages need opting out and how much trouble/code this saves us in the end. It might be interesting to consider alternatives, like a little closure at the top of the pipeline generator that does the same work, e.g.:
func (p *SomePipeline) serialize() (osbuild.Pipeline, error) {
...
mounts := ... // make pipeline mounts
devices := ... // make pipeline devices
func addStageWithDefaults(stage *Stage) {
stage.Mounts = mounts
stage.Devices = devices
pipeline.AddStage(stage)
}
...
addStageWithDefaults(osbuild.NewWhateverStage(...))
}or adding an extra method to the pipeline for adding stages with mounts and devices:
func (p *SomePipeline) serialize() (osbuild.Pipeline, error) {
...
mounts := ... // make pipeline mounts
devices := ... // make pipeline devices
pipeline.AddStageWithMounts(osbuild.NewWhateverStage(...), mounts, devices)
}| // payload of the produced image. | ||
| Stages []*Stage `json:"stages,omitempty"` | ||
|
|
||
| defaultMounts []Mount |
There was a problem hiding this comment.
Given the description of the behaviour in the commit message, I think the term default doesn't work here. Perhaps base or just mounts? I was thinking piplineMounts, but since they're a field of the pipeline struct, just pipeline.mounts will do.
My thinking is that the term defaultMounts could imply that defining any other set of mounts on a stage overrides them, instead of appending to them. But that's not the case. They're global pipeline mounts, for all stages, unconditionally.
There was a problem hiding this comment.
Just mounts / devices is probably the better name here.
|
|
||
| defaultMounts []Mount | ||
| defaultMounts []Mount | ||
| defaultDevices map[string]Device |
| if _, exists := stage.Devices[k]; !exists { | ||
| stage.Devices[k] = v | ||
| } |
There was a problem hiding this comment.
I'm not sure this is the correct behaviour here. I think if a stage defines a device with the same name as the global pipeline devices, it might make sense for that to be an error. If we really want the ability to override the device configuration for a stage by adding a device with the same name, we should document it in the docstrings, both here and in the method where the pipeline devices are defined.
There was a problem hiding this comment.
Let's make it error now. If we get a use case where we would need this we can cross the bridge then.
I think the little closure mostly makes sense because there currently aren't any other functions provided to add with/without mounts/devices. I was quite unsure about doing those because it's a bit opinionated and there was a good opt out possibility by appending to stages directly. I'll do an |
Provide machinery to set default mounts and devices on pipelines. Any stage added through
.AddStage(s)will be given these options.This mostly saves (currently) in cases where we need to pass mounts every time.
Perhaps we want to be stricter?
In the future I might want to use this in the
ospipeline; or a new pipeline, to invert the order of operation so that we first create the image and then write to it; similar to what we currently do for thebootcpipeline(s) but that's for later, it does give some background.