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)
|
GetStacks(swarmId string, endpointId uint32) ([]Stack, error)
|
||||||
|
|
||||||
// Create swarm stack
|
// 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
|
// 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
|
// Update stack
|
||||||
UpdateStack(stack Stack, environmentVariables []StackEnv, stackFileContent string, prune bool, endpointId uint32) error
|
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
|
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{
|
reqBody := StackCreateRequest{
|
||||||
Name: stackName,
|
Name: stackName,
|
||||||
Env: environmentVariables,
|
Env: environmentVariables,
|
||||||
@ -239,18 +239,18 @@ func (n *portainerClientImp) CreateSwarmStack(stackName string, environmentVaria
|
|||||||
StackFileContent: stackFileContent,
|
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
|
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{
|
reqBody := StackCreateRequest{
|
||||||
Name: stackName,
|
Name: stackName,
|
||||||
Env: environmentVariables,
|
Env: environmentVariables,
|
||||||
StackFileContent: stackFileContent,
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,16 +129,27 @@ var stackDeployCmd = &cobra.Command{
|
|||||||
"endpoint": endpointId,
|
"endpoint": endpointId,
|
||||||
"cluster": endpointSwarmClusterId,
|
"cluster": endpointSwarmClusterId,
|
||||||
}).Info("Creating stack")
|
}).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)
|
common.CheckError(deploymentErr)
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"stack": stack.Name,
|
||||||
|
"endpoint": stack.EndpointID,
|
||||||
|
"cluster": stack.SwarmID,
|
||||||
|
"id": stack.Id,
|
||||||
|
}).Info("Stack created")
|
||||||
} else {
|
} else {
|
||||||
// It's not a swarm cluster
|
// It's not a swarm cluster
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"stack": stackName,
|
"stack": stackName,
|
||||||
"endpoint": endpointId,
|
"endpoint": endpointId,
|
||||||
}).Info("Creating stack")
|
}).Info("Creating stack")
|
||||||
deploymentErr := portainerClient.CreateComposeStack(stackName, loadedEnvironmentVariables, stackFileContent, uint32(endpointId))
|
stack, deploymentErr := portainerClient.CreateComposeStack(stackName, loadedEnvironmentVariables, stackFileContent, uint32(endpointId))
|
||||||
common.CheckError(deploymentErr)
|
common.CheckError(deploymentErr)
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"stack": stack.Name,
|
||||||
|
"endpoint": stack.EndpointID,
|
||||||
|
"id": stack.Id,
|
||||||
|
}).Info("Stack created")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
// Something else happened
|
// Something else happened
|
||||||
|
@ -74,6 +74,10 @@ var stackRemoveCmd = &cobra.Command{
|
|||||||
}).Info("Removing stack")
|
}).Info("Removing stack")
|
||||||
err = portainerClient.DeleteStack(stackId)
|
err = portainerClient.DeleteStack(stackId)
|
||||||
common.CheckError(err)
|
common.CheckError(err)
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"stack": stack.Name,
|
||||||
|
"endpoint": stack.EndpointID,
|
||||||
|
}).Info("Stack removed")
|
||||||
case *common.StackNotFoundError:
|
case *common.StackNotFoundError:
|
||||||
// The stack does not exist
|
// The stack does not exist
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
|
Loading…
Reference in New Issue
Block a user