Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support to run ops forcibly #289

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions pkg/action/template/cluster_operations_template.cue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ options: {
cfgTemplateName: string
cfgFile: string
forceRestart: bool
force: bool
services: [
...{
name: string
Expand Down Expand Up @@ -81,6 +82,7 @@ content: {
clusterRef: options.name
type: options.type
ttlSecondsAfterSucceed: options.ttlSecondsAfterSucceed
force: options.force
if options.type == "Upgrade" {
upgrade: #upgrade
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/action/template/opsrequest_template.cue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ options: {
opsType: string
backupSpec: {}
restoreSpec: {}
force: bool
}

// required, k8s api resource content
Expand All @@ -36,6 +37,7 @@ content: {
spec: {
clusterRef: options.clusterRef
type: options.opsType
force: options.force
if options.opsType == "Backup" {
backupSpec: options.backupSpec
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/cluster/dataprotection.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type CreateBackupOptions struct {
ClusterRef string `json:"clusterRef"`
OpsType string `json:"opsType"`
OpsRequestName string `json:"opsRequestName"`
Force bool `json:"force"`

action.CreateOptions `json:"-"`
}
Expand Down Expand Up @@ -501,6 +502,7 @@ type CreateRestoreOptions struct {
ClusterRef string `json:"clusterRef"`
OpsType string `json:"opsType"`
OpsRequestName string `json:"opsRequestName"`
Force bool `json:"force"`

action.CreateOptions `json:"-"`
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/cmd/cluster/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type OperationsOptions struct {
ComponentNames []string `json:"componentNames,omitempty"`
OpsRequestName string `json:"opsRequestName"`
TTLSecondsAfterSucceed int `json:"ttlSecondsAfterSucceed"`
Force bool `json:"force"`

// OpsType operation type
OpsType appsv1alpha1.OpsType `json:"type"`
Expand Down Expand Up @@ -108,7 +109,6 @@ type OperationsOptions struct {
Component string `json:"component"`
Instance string `json:"instance"`
Primary string `json:"-"`
Force bool `json:"-"`
CharacterType string `json:"-"`
LorryHAEnabled bool `json:"-"`
ExecPod *corev1.Pod `json:"-"`
Expand Down Expand Up @@ -148,8 +148,8 @@ func newBaseOperationsOptions(f cmdutil.Factory, streams genericiooptions.IOStre
func (o *OperationsOptions) addCommonFlags(cmd *cobra.Command, f cmdutil.Factory) {
// add print flags
printer.AddOutputFlagForCreate(cmd, &o.Format, false)

cmd.Flags().StringVar(&o.OpsRequestName, "name", "", "OpsRequest name. if not specified, it will be randomly generated ")
cmd.Flags().BoolVar(&o.Force, "force", false, " skip the pre-checks of the opsRequest to run the opsRequest forcibly")
cmd.Flags().StringVar(&o.OpsRequestName, "name", "", "OpsRequest name. if not specified, it will be randomly generated")
cmd.Flags().IntVar(&o.TTLSecondsAfterSucceed, "ttlSecondsAfterSucceed", 0, "Time to live after the OpsRequest succeed")
cmd.Flags().StringVar(&o.DryRun, "dry-run", "none", `Must be "client", or "server". If with client strategy, only print the object that would be sent, and no data is actually sent. If with server strategy, submit the server-side request, but no data is persistent.`)
cmd.Flags().Lookup("dry-run").NoOptDefVal = "unchanged"
Expand Down Expand Up @@ -1034,7 +1034,6 @@ func NewPromoteCmd(f cmdutil.Factory, streams genericiooptions.IOStreams) *cobra
flags.AddComponentFlag(f, cmd, &o.Component, "Specify the component name of the cluster, if the cluster has multiple components, you need to specify a component")
cmd.Flags().StringVar(&o.Instance, "instance", "", "Specify the instance name as the new primary or leader of the cluster, you can get the instance name by running \"kbcli cluster list-instances\"")
cmd.Flags().BoolVar(&o.AutoApprove, "auto-approve", false, "Skip interactive approval before promote the instance")
cmd.Flags().BoolVar(&o.Force, "force", false, "force switchover if failed")
o.addCommonFlags(cmd, f)
return cmd
}
Expand Down
Loading