mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Add --endpoint flag to remove command
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/greenled/portainer-stack-utils/client"
|
||||||
"github.com/greenled/portainer-stack-utils/common"
|
"github.com/greenled/portainer-stack-utils/common"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -16,6 +17,39 @@ var stackRemoveCmd = &cobra.Command{
|
|||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
stackName := args[0]
|
stackName := args[0]
|
||||||
|
endpointId := viper.GetUint32("stack.remove.endpoint")
|
||||||
|
var endpointSwarmClusterId string
|
||||||
|
var stack client.Stack
|
||||||
|
if endpointId == 0 {
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"flag": "--endpoint",
|
||||||
|
}).Fatal("Provide required flag")
|
||||||
|
} else {
|
||||||
|
var selectionErr, stackRetrievalErr error
|
||||||
|
endpointSwarmClusterId, selectionErr = common.GetEndpointSwarmClusterId(endpointId)
|
||||||
|
switch selectionErr.(type) {
|
||||||
|
case nil:
|
||||||
|
// It's a swarm cluster
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"stack": stackName,
|
||||||
|
"endpoint": endpointId,
|
||||||
|
"swarm": endpointSwarmClusterId,
|
||||||
|
}).Debug("Getting stack")
|
||||||
|
stack, stackRetrievalErr = common.GetStackByName(stackName, endpointSwarmClusterId, endpointId)
|
||||||
|
common.CheckError(stackRetrievalErr)
|
||||||
|
case *common.StackClusterNotFoundError:
|
||||||
|
// It's not a swarm cluster
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"stack": stackName,
|
||||||
|
"endpoint": endpointId,
|
||||||
|
}).Debug("Getting stack")
|
||||||
|
stack, stackRetrievalErr = common.GetStackByName(stackName, "", endpointId)
|
||||||
|
common.CheckError(stackRetrievalErr)
|
||||||
|
default:
|
||||||
|
// Something else happened
|
||||||
|
common.CheckError(selectionErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"stack": stackName,
|
"stack": stackName,
|
||||||
}).Debug("Getting stack")
|
}).Debug("Getting stack")
|
||||||
@ -55,5 +89,7 @@ func init() {
|
|||||||
stackCmd.AddCommand(stackRemoveCmd)
|
stackCmd.AddCommand(stackRemoveCmd)
|
||||||
|
|
||||||
stackRemoveCmd.Flags().Bool("strict", false, "Fail if stack does not exist.")
|
stackRemoveCmd.Flags().Bool("strict", false, "Fail if stack does not exist.")
|
||||||
|
stackRemoveCmd.Flags().Uint32("endpoint", 0, "Endpoint ID.")
|
||||||
viper.BindPFlag("stack.remove.strict", stackRemoveCmd.Flags().Lookup("strict"))
|
viper.BindPFlag("stack.remove.strict", stackRemoveCmd.Flags().Lookup("strict"))
|
||||||
|
viper.BindPFlag("stack.remove.endpoint", stackRemoveCmd.Flags().Lookup("endpoint"))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user