feat: add image_pinned to skip registry rewrite for custom images#425
feat: add image_pinned to skip registry rewrite for custom images#425zeroasterisk wants to merge 2 commits into
Conversation
Templates that specify a fully-qualified custom image (e.g. ghcr.io/myorg/scion-myimage:latest) currently get their registry prefix rewritten by the broker's image_registry setting. This makes it impossible to use custom scion-* images hosted in external registries without push access to the broker's registry. Add an `image_pinned` field to ScionConfig. When set to true in a template's scion-agent.yaml, the image is used as-is without registry rewriting.
There was a problem hiding this comment.
Code Review
This pull request introduces an ImagePinned configuration option to ScionConfig to allow skipping the image registry rewrite process when resolving agent images. The review feedback suggests formatting the struct fields in pkg/api/types.go to align with standard gofmt style, and simplifying the conditional logic in pkg/agent/run.go to eliminate a single-use variable and prevent misleading debug logs when no image is resolved.
| Image string `json:"image,omitempty" yaml:"image,omitempty"` | ||
| ImagePinned bool `json:"image_pinned,omitempty" yaml:"image_pinned,omitempty"` | ||
| Services []ServiceSpec `json:"services,omitempty" yaml:"services,omitempty"` |
There was a problem hiding this comment.
The newly added and modified struct fields are not aligned with the existing fields in ScionConfig. In Go, struct fields (types and tags) should be aligned consistently using tabs and spaces as per standard gofmt formatting.
| Image string `json:"image,omitempty" yaml:"image,omitempty"` | |
| ImagePinned bool `json:"image_pinned,omitempty" yaml:"image_pinned,omitempty"` | |
| Services []ServiceSpec `json:"services,omitempty" yaml:"services,omitempty"` | |
| Image string `json:"image,omitempty" yaml:"image,omitempty"` | |
| ImagePinned bool `json:"image_pinned,omitempty" yaml:"image_pinned,omitempty"` | |
| Services []ServiceSpec `json:"services,omitempty" yaml:"services,omitempty"` |
There was a problem hiding this comment.
Fixed — ran gofmt -w pkg/api/types.go to align the struct fields consistently.
| imagePinned := finalScionCfg != nil && finalScionCfg.ImagePinned | ||
| if imagePinned { | ||
| util.Debugf("image resolution: image_pinned=true, skipping registry rewrite") | ||
| } else if settings != nil && resolvedImage != "" { |
There was a problem hiding this comment.
We can make this more idiomatic Go by eliminating the single-use local variable imagePinned and combining the check directly into the if statement. Additionally, adding a guard for resolvedImage != "" prevents printing a misleading debug log about skipping registry rewrite when no image was actually resolved.
| imagePinned := finalScionCfg != nil && finalScionCfg.ImagePinned | |
| if imagePinned { | |
| util.Debugf("image resolution: image_pinned=true, skipping registry rewrite") | |
| } else if settings != nil && resolvedImage != "" { | |
| if finalScionCfg != nil && finalScionCfg.ImagePinned && resolvedImage != "" { | |
| util.Debugf("image resolution: image_pinned=true, skipping registry rewrite") | |
| } else if settings != nil && resolvedImage != "" { |
There was a problem hiding this comment.
Fixed — inlined the imagePinned variable directly into the if condition.
62f2abb to
ef8c3e8
Compare
Summary
image_pinnedfield toScionConfig(scion-agent.yaml)image_pinned: true, theimage_registryrewrite is skipped, preserving the exact image reference from the templateMotivation
Templates that specify a fully-qualified custom
scion-*image (e.g.ghcr.io/myorg/scion-elixir-image:latest) get their registry prefix rewritten byRewriteImageRegistry()to match the broker'simage_registrysetting. This makes it impossible to use custom images hosted in external registries without push access to the broker's registry.The
image_pinnedflag lets template authors signal that their image reference is intentional and should not be rewritten.Usage
In a template's
scion-agent.yaml:Changes
pkg/api/types.go: AddImagePinned boolfield toScionConfigpkg/agent/run.go: CheckImagePinnedbefore applying registry rewriteTest plan
go build ./...passesgo test ./pkg/agent/... ./pkg/api/... ./pkg/config/...— all image-related tests passimage_pinned: trueand custom image, verify no rewrite in debug logs