Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/v1alpha1/imagebuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ type FlashSpec struct {
// LeaseDuration is the duration for the device lease in HH:MM:SS format
// +kubebuilder:default="03:00:00"
LeaseDuration string `json:"leaseDuration,omitempty"`

// FlashCmd overrides the flash command from OperatorConfig target mappings
// +optional
FlashCmd string `json:"flashCmd,omitempty"`
}

// AIBSpec defines the automotive-image-builder configuration
Expand Down Expand Up @@ -425,6 +429,14 @@ func (s *ImageBuildSpec) GetRebuildBuilder() bool {
return false
}

// GetFlashCmd returns the user-specified flash command override, or empty string
func (s *ImageBuildSpec) GetFlashCmd() string {
if s.Flash != nil {
return s.Flash.FlashCmd
}
return ""
}

// GetFlashLeaseDuration returns the flash lease duration, or default
func (s *ImageBuildSpec) GetFlashLeaseDuration() string {
if s.Flash != nil && s.Flash.LeaseDuration != "" {
Expand Down
4 changes: 4 additions & 0 deletions cmd/caib/buildcmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Options struct {
FlashAfterBuild *bool
JumpstarterClient *string
LeaseDuration *string
FlashCmd *string

UseInternalRegistry *bool
InternalRegistryImageName *string
Expand Down Expand Up @@ -408,6 +409,7 @@ func (h *Handler) RunBuild(cmd *cobra.Command, args []string) {
req.FlashEnabled = true
req.FlashClientConfig = base64.StdEncoding.EncodeToString(clientConfigBytes)
req.FlashLeaseDuration = *h.opts.LeaseDuration
req.FlashCmd = *h.opts.FlashCmd
}

resp, err := api.CreateBuild(ctx, req)
Expand Down Expand Up @@ -524,6 +526,7 @@ func (h *Handler) RunDisk(cmd *cobra.Command, args []string) {
req.FlashEnabled = true
req.FlashClientConfig = base64.StdEncoding.EncodeToString(clientConfigBytes)
req.FlashLeaseDuration = *h.opts.LeaseDuration
req.FlashCmd = *h.opts.FlashCmd
}

resp, err := api.CreateBuild(ctx, req)
Expand Down Expand Up @@ -658,6 +661,7 @@ func (h *Handler) RunBuildDev(cmd *cobra.Command, args []string) {
req.FlashEnabled = true
req.FlashClientConfig = base64.StdEncoding.EncodeToString(clientConfigBytes)
req.FlashLeaseDuration = *h.opts.LeaseDuration
req.FlashCmd = *h.opts.FlashCmd
}

resp, err := api.CreateBuild(ctx, req)
Expand Down
2 changes: 2 additions & 0 deletions cmd/caib/flashcmd/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Options struct {
Target *string
ExporterSelector *string
LeaseDuration *string
FlashCmd *string
WaitForBuild *bool
FollowLogs *bool
InsecureSkipTLS *bool
Expand Down Expand Up @@ -116,6 +117,7 @@ func (h *Handler) RunFlash(cmd *cobra.Command, args []string) {
ExporterSelector: *h.opts.ExporterSelector,
ClientConfig: clientConfigB64,
LeaseDuration: *h.opts.LeaseDuration,
FlashCmd: *h.opts.FlashCmd,
}

resp, err := api.CreateFlash(ctx, req)
Expand Down
5 changes: 5 additions & 0 deletions cmd/caib/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Options struct {
FlashName *string
ExporterSelector *string
LeaseDuration *string
FlashCmd *string

UseInternalRegistry *bool
InternalRegistryImageName *string
Expand Down Expand Up @@ -140,6 +141,7 @@ func NewImageCmd(opts Options) *cobra.Command {
buildCmd.Flags().BoolVar(opts.FlashAfterBuild, "flash", false, "flash the image to device after build completes")
buildCmd.Flags().StringVar(opts.JumpstarterClient, "client", "", "path to Jumpstarter client config file (required for --flash)")
buildCmd.Flags().StringVar(opts.LeaseDuration, "lease", "03:00:00", "device lease duration for flash (HH:MM:SS)")
buildCmd.Flags().StringVar(opts.FlashCmd, "flash-cmd", "", "override flash command (default: from OperatorConfig target mapping)")
// Internal registry options
buildCmd.Flags().BoolVar(opts.UseInternalRegistry, "internal-registry", false, "push to OpenShift internal registry")
buildCmd.Flags().StringVar(opts.InternalRegistryImageName, "image-name", "", "override image name for internal registry (default: build name)")
Expand Down Expand Up @@ -195,6 +197,7 @@ func NewImageCmd(opts Options) *cobra.Command {
diskCmd.Flags().BoolVar(opts.FlashAfterBuild, "flash", false, "flash the image to device after build completes")
diskCmd.Flags().StringVar(opts.JumpstarterClient, "client", "", "path to Jumpstarter client config file (required for --flash)")
diskCmd.Flags().StringVar(opts.LeaseDuration, "lease", "03:00:00", "device lease duration for flash (HH:MM:SS)")
diskCmd.Flags().StringVar(opts.FlashCmd, "flash-cmd", "", "override flash command (default: from OperatorConfig target mapping)")
// Internal registry options
diskCmd.Flags().BoolVar(opts.UseInternalRegistry, "internal-registry", false, "push to OpenShift internal registry")
diskCmd.Flags().StringVar(opts.InternalRegistryImageName, "image-name", "", "override image name for internal registry (default: build name)")
Expand Down Expand Up @@ -232,6 +235,7 @@ func NewImageCmd(opts Options) *cobra.Command {
buildDevCmd.Flags().BoolVar(opts.FlashAfterBuild, "flash", false, "flash the image to device after build completes")
buildDevCmd.Flags().StringVar(opts.JumpstarterClient, "client", "", "path to Jumpstarter client config file (required for --flash)")
buildDevCmd.Flags().StringVar(opts.LeaseDuration, "lease", "03:00:00", "device lease duration for flash (HH:MM:SS)")
buildDevCmd.Flags().StringVar(opts.FlashCmd, "flash-cmd", "", "override flash command (default: from OperatorConfig target mapping)")
// Internal registry options
buildDevCmd.Flags().BoolVar(opts.UseInternalRegistry, "internal-registry", false, "push to OpenShift internal registry")
buildDevCmd.Flags().StringVar(opts.InternalRegistryImageName, "image-name", "", "override image name for internal registry (default: build name)")
Expand All @@ -255,6 +259,7 @@ func NewImageCmd(opts Options) *cobra.Command {
flashCmd.Flags().StringVarP(opts.Target, "target", "t", "", "target platform for exporter lookup")
flashCmd.Flags().StringVar(opts.ExporterSelector, "exporter", "", "direct exporter selector (alternative to --target)")
flashCmd.Flags().StringVar(opts.LeaseDuration, "lease", "03:00:00", "device lease duration (HH:MM:SS)")
flashCmd.Flags().StringVar(opts.FlashCmd, "flash-cmd", "", "override flash command (default: from OperatorConfig target mapping)")
flashCmd.Flags().BoolVarP(opts.FollowLogs, "follow", "f", false, "follow flash logs (shows full log output instead of progress bar)")
flashCmd.Flags().BoolVarP(opts.WaitForBuild, "wait", "w", true, "wait for flash to complete")
_ = flashCmd.MarkFlagRequired("client")
Expand Down
1 change: 1 addition & 0 deletions cmd/caib/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (
flashName string
exporterSelector string
leaseDuration string
flashCmdOverride string

// Internal registry options
useInternalRegistry bool
Expand Down
5 changes: 5 additions & 0 deletions cmd/caib/runtime_wiring.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type runtimeState struct {
FlashName *string
ExporterSelector *string
LeaseDuration *string
FlashCmd *string

UseInternalRegistry *bool
InternalRegistryImageName *string
Expand Down Expand Up @@ -98,6 +99,7 @@ func newRuntimeState() runtimeState {
FlashName: &flashName,
ExporterSelector: &exporterSelector,
LeaseDuration: &leaseDuration,
FlashCmd: &flashCmdOverride,

UseInternalRegistry: &useInternalRegistry,
InternalRegistryImageName: &internalRegistryImageName,
Expand Down Expand Up @@ -157,6 +159,7 @@ func (s runtimeState) newHandlers() handlerSet {
FlashAfterBuild: s.FlashAfterBuild,
JumpstarterClient: s.JumpstarterClient,
LeaseDuration: s.LeaseDuration,
FlashCmd: s.FlashCmd,
UseInternalRegistry: s.UseInternalRegistry,
InternalRegistryImageName: s.InternalRegistryImageName,
InternalRegistryTag: s.InternalRegistryTag,
Expand Down Expand Up @@ -185,6 +188,7 @@ func (s runtimeState) newHandlers() handlerSet {
Target: s.Target,
ExporterSelector: s.ExporterSelector,
LeaseDuration: s.LeaseDuration,
FlashCmd: s.FlashCmd,
WaitForBuild: s.WaitForBuild,
FollowLogs: s.FollowLogs,
InsecureSkipTLS: s.InsecureSkipTLS,
Expand Down Expand Up @@ -261,6 +265,7 @@ func (s runtimeState) imageOptions(h handlerSet) image.Options {
FlashName: s.FlashName,
ExporterSelector: s.ExporterSelector,
LeaseDuration: s.LeaseDuration,
FlashCmd: s.FlashCmd,

UseInternalRegistry: s.UseInternalRegistry,
InternalRegistryImageName: s.InternalRegistryImageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ spec:
The secret should have a key "client.yaml" with the config contents
If set, flash is enabled automatically
type: string
flashCmd:
description: FlashCmd overrides the flash command from OperatorConfig
target mappings
type: string
leaseDuration:
default: "03:00:00"
description: LeaseDuration is the duration for the device lease
Expand Down
6 changes: 5 additions & 1 deletion internal/buildapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,7 @@ func (a *APIServer) createBuild(c *gin.Context) {
flashSpec = &automotivev1alpha1.FlashSpec{
ClientConfigSecretRef: flashSecretName,
LeaseDuration: req.FlashLeaseDuration,
FlashCmd: req.FlashCmd,
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

Expand Down Expand Up @@ -1769,7 +1770,10 @@ func (a *APIServer) getBuild(c *gin.Context, name string) {
if operatorConfig.Spec.Jumpstarter != nil {
if mapping, ok := operatorConfig.Spec.Jumpstarter.TargetMappings[build.Spec.GetTarget()]; ok {
jumpstarterInfo.ExporterSelector = mapping.Selector
flashCmd := mapping.FlashCmd
flashCmd := build.Spec.GetFlashCmd()
if flashCmd == "" {
flashCmd = mapping.FlashCmd
}
// Replace placeholders in flash command using translated URLs
if flashCmd != "" {
imageURI := diskImage
Expand Down
1 change: 1 addition & 0 deletions internal/buildapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type BuildRequest struct {
FlashEnabled bool `json:"flashEnabled,omitempty"` // Enable flashing after build
FlashClientConfig string `json:"flashClientConfig,omitempty"` // Base64-encoded Jumpstarter client config
FlashLeaseDuration string `json:"flashLeaseDuration,omitempty"` // Lease duration in HH:MM:SS format
FlashCmd string `json:"flashCmd,omitempty"` // Override flash command from OperatorConfig
}

// RegistryCredentials contains authentication details for container registries.
Expand Down
8 changes: 8 additions & 0 deletions internal/controller/imagebuild/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ func (r *ImageBuildReconciler) createBuildTaskRun(
flashCmd = mapping.FlashCmd
}
}
// User-specified flash command overrides OperatorConfig
if userCmd := imageBuild.Spec.GetFlashCmd(); userCmd != "" {
flashCmd = userCmd
}
if flashExporterSelector == "" {
return fmt.Errorf("flash enabled but no Jumpstarter target mapping found for target %q; "+
"configure OperatorConfig.spec.jumpstarter.targetMappings[%q] with selector and flashCmd", target, target)
Expand Down Expand Up @@ -1282,6 +1286,10 @@ func (r *ImageBuildReconciler) createFlashTaskRun(
flashCmd = mapping.FlashCmd
}
}
// User-specified flash command overrides OperatorConfig
if userCmd := imageBuild.Spec.GetFlashCmd(); userCmd != "" {
flashCmd = userCmd
}

if exporterSelector == "" {
return fmt.Errorf("no Jumpstarter exporter mapping found for target %q in OperatorConfig", target)
Expand Down