-
Notifications
You must be signed in to change notification settings - Fork 22
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
Stop reconciliation and clustering #578
Changes from all commits
6d4d510
ba86499
e894f6a
e37a743
b8c4320
01e545a
c66aa84
3546244
37b282d
0265cf4
d407371
6ee01df
34ba8ed
fb35e36
4107682
75572b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2" | ||
"github.com/cybozu-go/moco/pkg/constants" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/api/equality" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(startCmd) | ||
startCmd.AddCommand(startClusteringCmd) | ||
startCmd.AddCommand(startReconciliationCmd) | ||
} | ||
|
||
var startCmd = &cobra.Command{ | ||
Use: "start", | ||
Short: "Starts the MySQLCluster reconciliation or clustering", | ||
Long: "The start command is used to start the reconciliation or clustering of MySQLCluster", | ||
} | ||
|
||
var startClusteringCmd = &cobra.Command{ | ||
Use: "clustering CLUSTER_NAME", | ||
Short: "Start the specified MySQLCluster's clustering", | ||
Long: "start clustering is a command to start the clustering of the specified MySQLCluster. It requires the cluster name as the parameter.", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return startClustering(cmd.Context(), args[0]) | ||
}, | ||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return mysqlClusterCandidates(cmd.Context(), cmd, args, toComplete) | ||
}, | ||
} | ||
|
||
func startClustering(ctx context.Context, name string) error { | ||
cluster := &mocov1beta2.MySQLCluster{} | ||
if err := kubeClient.Get(ctx, types.NamespacedName{Namespace: namespace, Name: name}, cluster); err != nil { | ||
return err | ||
} | ||
|
||
orig := cluster.DeepCopy() | ||
|
||
if ann, ok := cluster.Annotations[constants.AnnClusteringStopped]; ok && ann == "true" { | ||
delete(cluster.Annotations, constants.AnnClusteringStopped) | ||
} | ||
|
||
if equality.Semantic.DeepEqual(orig, cluster) { | ||
fmt.Fprintf(os.Stdout, "The clustering is already running.") | ||
return nil | ||
} | ||
|
||
if err := kubeClient.Update(ctx, cluster); err != nil { | ||
return fmt.Errorf("failed to start clustering of MySQLCluster: %w", err) | ||
} | ||
|
||
fmt.Fprintf(os.Stdout, "started clustering of MySQLCluster %q\n", fmt.Sprintf("%s/%s", namespace, name)) | ||
|
||
return nil | ||
} | ||
|
||
var startReconciliationCmd = &cobra.Command{ | ||
Use: "reconciliation CLUSTER_NAME", | ||
Short: "Start the specified MySQLCluster's reconciliation", | ||
Long: "start reconciliation is a command to start the reconciliation process for the specified MySQLCluster. This requires the cluster name as the parameter.", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return startReconciliation(cmd.Context(), args[0]) | ||
}, | ||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return mysqlClusterCandidates(cmd.Context(), cmd, args, toComplete) | ||
}, | ||
} | ||
|
||
func startReconciliation(ctx context.Context, name string) error { | ||
cluster := &mocov1beta2.MySQLCluster{} | ||
if err := kubeClient.Get(ctx, types.NamespacedName{Namespace: namespace, Name: name}, cluster); err != nil { | ||
return err | ||
} | ||
|
||
orig := cluster.DeepCopy() | ||
|
||
if ann, ok := cluster.Annotations[constants.AnnReconciliationStopped]; ok && ann == "true" { | ||
delete(cluster.Annotations, constants.AnnReconciliationStopped) | ||
} | ||
|
||
if equality.Semantic.DeepEqual(orig, cluster) { | ||
fmt.Fprintf(os.Stdout, "The reconciliation is already running.") | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. |
||
} | ||
|
||
if err := kubeClient.Update(ctx, cluster); err != nil { | ||
return fmt.Errorf("failed to start reconciliation of MySQLCluster: %w", err) | ||
} | ||
|
||
fmt.Fprintf(os.Stdout, "started reconciliation of MySQLCluster %q\n", fmt.Sprintf("%s/%s", namespace, name)) | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
mocov1beta2 "github.com/cybozu-go/moco/api/v1beta2" | ||
"github.com/cybozu-go/moco/pkg/constants" | ||
"github.com/spf13/cobra" | ||
"k8s.io/apimachinery/pkg/api/equality" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(stopCmd) | ||
stopCmd.AddCommand(stopClusteringCmd) | ||
stopCmd.AddCommand(stopReconciliationCmd) | ||
} | ||
|
||
var stopCmd = &cobra.Command{ | ||
Use: "stop", | ||
Short: "Stops the MySQLCluster reconciliation or clustering", | ||
Long: "The stop command is used to halt the reconciliation or clustering of MySQLCluster", | ||
} | ||
|
||
var stopClusteringCmd = &cobra.Command{ | ||
Use: "clustering CLUSTER_NAME", | ||
Short: "Stop the specified MySQLCluster's clustering", | ||
Long: "stop clustering is a command to stop the clustering of the specified MySQLCluster. It requires the cluster name as the parameter.", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return stopClustering(cmd.Context(), args[0]) | ||
}, | ||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return mysqlClusterCandidates(cmd.Context(), cmd, args, toComplete) | ||
}, | ||
} | ||
|
||
func stopClustering(ctx context.Context, name string) error { | ||
cluster := &mocov1beta2.MySQLCluster{} | ||
if err := kubeClient.Get(ctx, types.NamespacedName{Namespace: namespace, Name: name}, cluster); err != nil { | ||
return err | ||
} | ||
|
||
orig := cluster.DeepCopy() | ||
|
||
if cluster.Annotations == nil { | ||
cluster.Annotations = make(map[string]string) | ||
} | ||
cluster.Annotations[constants.AnnClusteringStopped] = "true" | ||
|
||
if equality.Semantic.DeepEqual(orig, cluster) { | ||
fmt.Fprintf(os.Stdout, "The clustering is already stopped.") | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
|
||
if err := kubeClient.Update(ctx, cluster); err != nil { | ||
return fmt.Errorf("failed to stop clustering of MySQLCluster: %w", err) | ||
} | ||
|
||
fmt.Fprintf(os.Stdout, "stopped clustering of MySQLCluster %q\n", fmt.Sprintf("%s/%s", namespace, name)) | ||
|
||
return nil | ||
} | ||
|
||
var stopReconciliationCmd = &cobra.Command{ | ||
Use: "reconciliation CLUSTER_NAME", | ||
Short: "Stop the specified MySQLCluster's reconciliation", | ||
Long: "stop reconciliation is a command to stop the reconciliation process for the specified MySQLCluster. This requires the cluster name as the parameter.", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return stopReconciliation(cmd.Context(), args[0]) | ||
}, | ||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return mysqlClusterCandidates(cmd.Context(), cmd, args, toComplete) | ||
}, | ||
} | ||
|
||
func stopReconciliation(ctx context.Context, name string) error { | ||
cluster := &mocov1beta2.MySQLCluster{} | ||
if err := kubeClient.Get(ctx, types.NamespacedName{Namespace: namespace, Name: name}, cluster); err != nil { | ||
return err | ||
} | ||
|
||
orig := cluster.DeepCopy() | ||
|
||
if cluster.Annotations == nil { | ||
cluster.Annotations = make(map[string]string) | ||
} | ||
cluster.Annotations[constants.AnnReconciliationStopped] = "true" | ||
|
||
if equality.Semantic.DeepEqual(orig, cluster) { | ||
fmt.Fprintf(os.Stdout, "The reconciliation is already stopped.") | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
|
||
if err := kubeClient.Update(ctx, cluster); err != nil { | ||
return fmt.Errorf("failed to stop reconciliation of MySQLCluster: %w", err) | ||
} | ||
|
||
fmt.Fprintf(os.Stdout, "stopped reconciliation of MySQLCluster %q\n", fmt.Sprintf("%s/%s", namespace, name)) | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want a message like "The clustering is already running."