|
|
@ -23,6 +23,7 @@ import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"k8s.io/apimachinery/pkg/types"
|
|
|
|
"k8s.io/apimachinery/pkg/types"
|
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
|
|
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/fluxcd/flux2/internal/utils"
|
|
|
|
"github.com/fluxcd/flux2/internal/utils"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -33,7 +34,15 @@ var resumeCmd = &cobra.Command{
|
|
|
|
Long: "The resume sub-commands resume a suspended resource.",
|
|
|
|
Long: "The resume sub-commands resume a suspended resource.",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type ResumeFlags struct {
|
|
|
|
|
|
|
|
all bool
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var resumeArgs ResumeFlags
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
resumeCmd.PersistentFlags().BoolVarP(&resumeArgs.all, "all", "", false,
|
|
|
|
|
|
|
|
"suspend all resources in that namespace")
|
|
|
|
rootCmd.AddCommand(resumeCmd)
|
|
|
|
rootCmd.AddCommand(resumeCmd)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -47,13 +56,18 @@ type resumable interface {
|
|
|
|
type resumeCommand struct {
|
|
|
|
type resumeCommand struct {
|
|
|
|
apiType
|
|
|
|
apiType
|
|
|
|
object resumable
|
|
|
|
object resumable
|
|
|
|
|
|
|
|
list listResumable
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type listResumable interface {
|
|
|
|
|
|
|
|
listAdapter
|
|
|
|
|
|
|
|
resumeItem(i int) resumable
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (resume resumeCommand) run(cmd *cobra.Command, args []string) error {
|
|
|
|
func (resume resumeCommand) run(cmd *cobra.Command, args []string) error {
|
|
|
|
if len(args) < 1 {
|
|
|
|
if len(args) < 1 && !resumeArgs.all {
|
|
|
|
return fmt.Errorf("%s name is required", resume.humanKind)
|
|
|
|
return fmt.Errorf("%s name is required", resume.humanKind)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
name := args[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
|
|
|
defer cancel()
|
|
|
|
defer cancel()
|
|
|
@ -63,29 +77,46 @@ func (resume resumeCommand) run(cmd *cobra.Command, args []string) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespacedName := types.NamespacedName{
|
|
|
|
var listOpts []client.ListOption
|
|
|
|
Namespace: rootArgs.namespace,
|
|
|
|
listOpts = append(listOpts, client.InNamespace(rootArgs.namespace))
|
|
|
|
Name: name,
|
|
|
|
if len(args) > 0 {
|
|
|
|
|
|
|
|
listOpts = append(listOpts, client.MatchingFields{
|
|
|
|
|
|
|
|
"metadata.name": args[0],
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err = kubeClient.Get(ctx, namespacedName, resume.object.asClientObject())
|
|
|
|
err = kubeClient.List(ctx, resume.list.asClientList(), listOpts...)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logger.Actionf("resuming %s %s in %s namespace", resume.humanKind, name, rootArgs.namespace)
|
|
|
|
if resume.list.len() == 0 {
|
|
|
|
resume.object.setUnsuspended()
|
|
|
|
logger.Failuref("no %s objects found in %s namespace", resume.kind, rootArgs.namespace)
|
|
|
|
if err := kubeClient.Update(ctx, resume.object.asClientObject()); err != nil {
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i := 0; i < resume.list.len(); i++ {
|
|
|
|
|
|
|
|
logger.Actionf("resuming %s %s in %s namespace", resume.humanKind, resume.list.resumeItem(i).asClientObject().GetName(), rootArgs.namespace)
|
|
|
|
|
|
|
|
resume.list.resumeItem(i).setUnsuspended()
|
|
|
|
|
|
|
|
if err := kubeClient.Update(ctx, resume.list.resumeItem(i).asClientObject()); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.Successf("%s resumed", resume.humanKind)
|
|
|
|
logger.Successf("%s resumed", resume.humanKind)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespacedName := types.NamespacedName{
|
|
|
|
|
|
|
|
Name: resume.list.resumeItem(i).asClientObject().GetName(),
|
|
|
|
|
|
|
|
Namespace: rootArgs.namespace,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logger.Waitingf("waiting for %s reconciliation", resume.kind)
|
|
|
|
logger.Waitingf("waiting for %s reconciliation", resume.kind)
|
|
|
|
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
|
|
|
|
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
|
|
|
|
isReady(ctx, kubeClient, namespacedName, resume.object)); err != nil {
|
|
|
|
isReady(ctx, kubeClient, namespacedName, resume.list.resumeItem(i))); err != nil {
|
|
|
|
return err
|
|
|
|
logger.Failuref(err.Error())
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logger.Successf("%s reconciliation completed", resume.kind)
|
|
|
|
logger.Successf("%s reconciliation completed", resume.kind)
|
|
|
|
logger.Successf(resume.object.successMessage())
|
|
|
|
logger.Successf(resume.list.resumeItem(i).successMessage())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|