diff --git a/internal/cli/kraft/cloud/deploy/deploy.go b/internal/cli/kraft/cloud/deploy/deploy.go index 2123d169c..9d79e795f 100644 --- a/internal/cli/kraft/cloud/deploy/deploy.go +++ b/internal/cli/kraft/cloud/deploy/deploy.go @@ -26,6 +26,7 @@ import ( "kraftkit.sh/unikraft/app" kraftcloud "sdk.kraft.cloud" + kcinstances "sdk.kraft.cloud/instances" ) type DeployOptions struct { @@ -55,6 +56,7 @@ type DeployOptions struct { Ports []string `local:"true" long:"port" short:"p" usage:"Specify the port mapping between external to internal"` Project app.Application `noattribute:"true"` Replicas int `local:"true" long:"replicas" short:"R" usage:"Number of replicas of the instance" default:"0"` + RestartPolicy kcinstances.RestartPolicy `noattribute:"true"` Rollout create.RolloutStrategy `noattribute:"true"` RolloutQualifier create.RolloutQualifier `noattribute:"true"` RolloutWait time.Duration `local:"true" long:"rollout-wait" usage:"Time to wait before performing rolling out action" default:"10s"` @@ -93,6 +95,15 @@ func NewCmd() *cobra.Command { panic(err) } + cmd.Flags().Var( + cmdfactory.NewEnumFlag[kcinstances.RestartPolicy]( + kcinstances.RestartPolicies(), + kcinstances.RestartPolicyNever, + ), + "restart", + "Set the restart policy for the instance (never/always/on-failure)", + ) + cmd.Flags().Var( cmdfactory.NewEnumFlag[create.RolloutStrategy]( append(create.RolloutStrategies(), create.StrategyPrompt), @@ -129,6 +140,7 @@ func (opts *DeployOptions) Pre(cmd *cobra.Command, _ []string) error { return fmt.Errorf("could not populate metro and token: %w", err) } + opts.RestartPolicy = kcinstances.RestartPolicy(cmd.Flag("restart").Value.String()) opts.Rollout = create.RolloutStrategy(cmd.Flag("rollout").Value.String()) opts.RolloutQualifier = create.RolloutQualifier(cmd.Flag("rollout-qualifier").Value.String()) opts.Strategy = packmanager.MergeStrategy(cmd.Flag("strategy").Value.String()) diff --git a/internal/cli/kraft/cloud/deploy/deployer_image_name.go b/internal/cli/kraft/cloud/deploy/deployer_image_name.go index 06162dd78..a4b015da5 100644 --- a/internal/cli/kraft/cloud/deploy/deployer_image_name.go +++ b/internal/cli/kraft/cloud/deploy/deployer_image_name.go @@ -102,6 +102,7 @@ func (deployer *deployerImageName) Deploy(ctx context.Context, opts *DeployOptio Name: opts.Name, Ports: opts.Ports, Replicas: opts.Replicas, + RestartPolicy: opts.RestartPolicy, ScaleToZero: opts.ScaleToZero, ServiceGroupNameOrUUID: opts.ServiceGroupNameOrUUID, Rollout: opts.Rollout, diff --git a/internal/cli/kraft/cloud/deploy/deployer_kraftfile_runtime.go b/internal/cli/kraft/cloud/deploy/deployer_kraftfile_runtime.go index a8391e712..6a888d22a 100644 --- a/internal/cli/kraft/cloud/deploy/deployer_kraftfile_runtime.go +++ b/internal/cli/kraft/cloud/deploy/deployer_kraftfile_runtime.go @@ -123,6 +123,7 @@ func (deployer *deployerKraftfileRuntime) Deploy(ctx context.Context, opts *Depl Name: opts.Name, Ports: opts.Ports, Replicas: opts.Replicas, + RestartPolicy: opts.RestartPolicy, Rollout: opts.Rollout, RolloutQualifier: opts.RolloutQualifier, RolloutWait: opts.RolloutWait, diff --git a/internal/cli/kraft/cloud/instance/create/create.go b/internal/cli/kraft/cloud/instance/create/create.go index cfa4a99a8..094e0c9e7 100644 --- a/internal/cli/kraft/cloud/instance/create/create.go +++ b/internal/cli/kraft/cloud/instance/create/create.go @@ -636,6 +636,7 @@ func (opts *CreateOptions) Pre(cmd *cobra.Command, _ []string) error { return fmt.Errorf("could not populate metro and token: %w", err) } + opts.RestartPolicy = kcinstances.RestartPolicy(cmd.Flag("restart").Value.String()) opts.Rollout = RolloutStrategy(cmd.Flag("rollout").Value.String()) opts.RolloutQualifier = RolloutQualifier(cmd.Flag("rollout-qualifier").Value.String())