diff --git a/client/client.go b/client/client.go index c0b194e..68f78bb 100644 --- a/client/client.go +++ b/client/client.go @@ -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 } diff --git a/cmd/stackDeploy.go b/cmd/stackDeploy.go index d056bfb..e6a63ab 100644 --- a/cmd/stackDeploy.go +++ b/cmd/stackDeploy.go @@ -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 diff --git a/cmd/stackRemove.go b/cmd/stackRemove.go index 2ea323b..3ad0f7b 100644 --- a/cmd/stackRemove.go +++ b/cmd/stackRemove.go @@ -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{