mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Add log message after stack deployment or removal
This commit is contained in:
parent
5506b625b4
commit
d4956584a1
@ -36,10 +36,10 @@ type PortainerClient interface {
|
||||
GetStacks(swarmId string, endpointId uint32) ([]Stack, error)
|
||||
|
||||
// Create swarm stack
|
||||
CreateSwarmStack(stackName string, environmentVariables []StackEnv, stackFileContent string, swarmClusterId string, endpointId uint32) error
|
||||
CreateSwarmStack(stackName string, environmentVariables []StackEnv, stackFileContent string, swarmClusterId string, endpointId uint32) (stack Stack, err error)
|
||||
|
||||
// Create compose stack
|
||||
CreateComposeStack(stackName string, environmentVariables []StackEnv, stackFileContent string, endpointId uint32) error
|
||||
CreateComposeStack(stackName string, environmentVariables []StackEnv, stackFileContent string, endpointId uint32) (stack Stack, err error)
|
||||
|
||||
// Update stack
|
||||
UpdateStack(stack Stack, environmentVariables []StackEnv, stackFileContent string, prune bool, endpointId uint32) error
|
||||
@ -231,7 +231,7 @@ func (n *portainerClientImp) GetStacks(swarmId string, endpointId uint32) (stack
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) CreateSwarmStack(stackName string, environmentVariables []StackEnv, stackFileContent string, swarmClusterId string, endpointId uint32) (err error) {
|
||||
func (n *portainerClientImp) CreateSwarmStack(stackName string, environmentVariables []StackEnv, stackFileContent string, swarmClusterId string, endpointId uint32) (stack Stack, err error) {
|
||||
reqBody := StackCreateRequest{
|
||||
Name: stackName,
|
||||
Env: environmentVariables,
|
||||
@ -239,18 +239,18 @@ func (n *portainerClientImp) CreateSwarmStack(stackName string, environmentVaria
|
||||
StackFileContent: stackFileContent,
|
||||
}
|
||||
|
||||
err = n.doJSON(fmt.Sprintf("stacks?type=%v&method=%s&endpointId=%v", 1, "string", endpointId), http.MethodPost, &reqBody, nil)
|
||||
err = n.doJSON(fmt.Sprintf("stacks?type=%v&method=%s&endpointId=%v", 1, "string", endpointId), http.MethodPost, &reqBody, &stack)
|
||||
return
|
||||
}
|
||||
|
||||
func (n *portainerClientImp) CreateComposeStack(stackName string, environmentVariables []StackEnv, stackFileContent string, endpointId uint32) (err error) {
|
||||
func (n *portainerClientImp) CreateComposeStack(stackName string, environmentVariables []StackEnv, stackFileContent string, endpointId uint32) (stack Stack, err error) {
|
||||
reqBody := StackCreateRequest{
|
||||
Name: stackName,
|
||||
Env: environmentVariables,
|
||||
StackFileContent: stackFileContent,
|
||||
}
|
||||
|
||||
err = n.doJSON(fmt.Sprintf("stacks?type=%v&method=%s&endpointId=%v", 2, "string", endpointId), http.MethodPost, &reqBody, nil)
|
||||
err = n.doJSON(fmt.Sprintf("stacks?type=%v&method=%s&endpointId=%v", 2, "string", endpointId), http.MethodPost, &reqBody, &stack)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -129,16 +129,27 @@ var stackDeployCmd = &cobra.Command{
|
||||
"endpoint": endpointId,
|
||||
"cluster": endpointSwarmClusterId,
|
||||
}).Info("Creating stack")
|
||||
deploymentErr := portainerClient.CreateSwarmStack(stackName, loadedEnvironmentVariables, stackFileContent, endpointSwarmClusterId, uint32(endpointId))
|
||||
stack, deploymentErr := portainerClient.CreateSwarmStack(stackName, loadedEnvironmentVariables, stackFileContent, endpointSwarmClusterId, uint32(endpointId))
|
||||
common.CheckError(deploymentErr)
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"stack": stack.Name,
|
||||
"endpoint": stack.EndpointID,
|
||||
"cluster": stack.SwarmID,
|
||||
"id": stack.Id,
|
||||
}).Info("Stack created")
|
||||
} else {
|
||||
// It's not a swarm cluster
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"stack": stackName,
|
||||
"endpoint": endpointId,
|
||||
}).Info("Creating stack")
|
||||
deploymentErr := portainerClient.CreateComposeStack(stackName, loadedEnvironmentVariables, stackFileContent, uint32(endpointId))
|
||||
stack, deploymentErr := portainerClient.CreateComposeStack(stackName, loadedEnvironmentVariables, stackFileContent, uint32(endpointId))
|
||||
common.CheckError(deploymentErr)
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"stack": stack.Name,
|
||||
"endpoint": stack.EndpointID,
|
||||
"id": stack.Id,
|
||||
}).Info("Stack created")
|
||||
}
|
||||
default:
|
||||
// Something else happened
|
||||
|
@ -74,6 +74,10 @@ var stackRemoveCmd = &cobra.Command{
|
||||
}).Info("Removing stack")
|
||||
err = portainerClient.DeleteStack(stackId)
|
||||
common.CheckError(err)
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"stack": stack.Name,
|
||||
"endpoint": stack.EndpointID,
|
||||
}).Info("Stack removed")
|
||||
case *common.StackNotFoundError:
|
||||
// The stack does not exist
|
||||
logrus.WithFields(logrus.Fields{
|
||||
|
Loading…
Reference in New Issue
Block a user