1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-21 22:39:41 +02:00

Revert "only update file after deployment succeded"

This reverts commit b94bd2e96f.
This commit is contained in:
ArrisLee 2021-09-01 16:34:03 +12:00
parent b94bd2e96f
commit 740993e3a4

View file

@ -1,11 +1,7 @@
package stacks package stacks
import ( import (
"fmt"
"io/ioutil"
"net/http" "net/http"
"os"
"path"
"strconv" "strconv"
"github.com/asaskevich/govalidator" "github.com/asaskevich/govalidator"
@ -13,7 +9,6 @@ import (
httperror "github.com/portainer/libhttp/error" httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request" "github.com/portainer/libhttp/request"
portainer "github.com/portainer/portainer/api" portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/filesystem"
gittypes "github.com/portainer/portainer/api/git/types" gittypes "github.com/portainer/portainer/api/git/types"
k "github.com/portainer/portainer/api/kubernetes" k "github.com/portainer/portainer/api/kubernetes"
) )
@ -95,16 +90,12 @@ func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.
return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Invalid request payload", Err: err} return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Invalid request payload", Err: err}
} }
tempFileDir, _ := ioutil.TempDir("", "kub_file_content") stackFolder := strconv.Itoa(int(stack.ID))
defer os.RemoveAll(tempFileDir) projectPath, err := handler.FileService.StoreStackFileFromBytes(stackFolder, stack.EntryPoint, []byte(payload.StackFileContent))
if err != nil {
if err := filesystem.WriteToFile(path.Join(tempFileDir, stack.EntryPoint), []byte(payload.StackFileContent)); err != nil { return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to persist Kubernetes manifest file on disk", Err: err}
return &httperror.HandlerError{StatusCode: http.StatusBadRequest, Message: "Failed to persist deployment file in a temp directory", Err: err}
} }
stack.ProjectPath = projectPath
//use temp dir as the stack project path for deployment
//so if the deployment failed, the original file won't be over-written
stack.ProjectPath = tempFileDir
_, err = handler.deployKubernetesStack(r, endpoint, stack, k.KubeAppLabels{ _, err = handler.deployKubernetesStack(r, endpoint, stack, k.KubeAppLabels{
StackID: int(stack.ID), StackID: int(stack.ID),
@ -117,17 +108,5 @@ func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.
return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to deploy Kubernetes stack via file content", Err: err} return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: "Unable to deploy Kubernetes stack via file content", Err: err}
} }
stackFolder := strconv.Itoa(int(stack.ID))
projectPath, err := handler.FileService.StoreStackFileFromBytes(stackFolder, stack.EntryPoint, []byte(payload.StackFileContent))
if err != nil {
fileType := "Manifest"
if stack.IsComposeFormat {
fileType = "Compose"
}
errMsg := fmt.Sprintf("Unable to persist Kubernetes %s file on disk", fileType)
return &httperror.HandlerError{StatusCode: http.StatusInternalServerError, Message: errMsg, Err: err}
}
stack.ProjectPath = projectPath
return nil return nil
} }