mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
chore(kompose): remove the code EE-4917 (#12003)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
This commit is contained in:
parent
ac4b129195
commit
6e7a42727a
14 changed files with 61 additions and 168 deletions
|
@ -34,7 +34,6 @@ func createStackPayloadFromK8sFileContentPayload(name, namespace, fileContent st
|
|||
StackName: name,
|
||||
Namespace: namespace,
|
||||
StackFileContent: fileContent,
|
||||
ComposeFormat: composeFormat,
|
||||
FromAppTemplate: fromAppTemplate,
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +66,6 @@ func createStackPayloadFromK8sGitPayload(name, repoUrl, repoReference, repoUsern
|
|||
TLSSkipVerify: repoSkipSSLVerify,
|
||||
},
|
||||
Namespace: namespace,
|
||||
ComposeFormat: composeFormat,
|
||||
ManifestFile: manifest,
|
||||
AdditionalFiles: additionalFiles,
|
||||
AutoUpdate: autoUpdate,
|
||||
|
@ -83,10 +81,9 @@ type kubernetesManifestURLDeploymentPayload struct {
|
|||
|
||||
func createStackPayloadFromK8sUrlPayload(name, namespace, manifestUrl string, composeFormat bool) stackbuilders.StackPayload {
|
||||
return stackbuilders.StackPayload{
|
||||
StackName: name,
|
||||
Namespace: namespace,
|
||||
ManifestURL: manifestUrl,
|
||||
ComposeFormat: composeFormat,
|
||||
StackName: name,
|
||||
Namespace: namespace,
|
||||
ManifestURL: manifestUrl,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,22 +99,23 @@ func (payload *kubernetesGitDeploymentPayload) Validate(r *http.Request) error {
|
|||
if govalidator.IsNull(payload.RepositoryURL) || !govalidator.IsURL(payload.RepositoryURL) {
|
||||
return errors.New("Invalid repository URL. Must correspond to a valid URL format")
|
||||
}
|
||||
|
||||
if payload.RepositoryAuthentication && govalidator.IsNull(payload.RepositoryPassword) {
|
||||
return errors.New("Invalid repository credentials. Password must be specified when authentication is enabled")
|
||||
}
|
||||
|
||||
if govalidator.IsNull(payload.ManifestFile) {
|
||||
return errors.New("Invalid manifest file in repository")
|
||||
}
|
||||
if err := update.ValidateAutoUpdateSettings(payload.AutoUpdate); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
return update.ValidateAutoUpdateSettings(payload.AutoUpdate)
|
||||
}
|
||||
|
||||
func (payload *kubernetesManifestURLDeploymentPayload) Validate(r *http.Request) error {
|
||||
if govalidator.IsNull(payload.ManifestURL) || !govalidator.IsURL(payload.ManifestURL) {
|
||||
return errors.New("Invalid manifest URL")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -171,9 +169,8 @@ func (handler *Handler) createKubernetesStackFromFileContent(w http.ResponseWrit
|
|||
}
|
||||
|
||||
stackBuilderDirector := stackbuilders.NewStackBuilderDirector(k8sStackBuilder)
|
||||
_, httpErr := stackBuilderDirector.Build(&stackPayload, endpoint)
|
||||
if httpErr != nil {
|
||||
return httpErr
|
||||
if _, err := stackBuilderDirector.Build(&stackPayload, endpoint); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp := &createKubernetesStackResponse{
|
||||
|
@ -213,13 +210,11 @@ func (handler *Handler) createKubernetesStackFromGitRepository(w http.ResponseWr
|
|||
return httperror.InternalServerError("Unable to load user information from the database", err)
|
||||
}
|
||||
|
||||
//make sure the webhook ID is unique
|
||||
// Make sure the webhook ID is unique
|
||||
if payload.AutoUpdate != nil && payload.AutoUpdate.Webhook != "" {
|
||||
isUnique, err := handler.checkUniqueWebhookID(payload.AutoUpdate.Webhook)
|
||||
if err != nil {
|
||||
if isUnique, err := handler.checkUniqueWebhookID(payload.AutoUpdate.Webhook); err != nil {
|
||||
return httperror.InternalServerError("Unable to check for webhook ID collision", err)
|
||||
}
|
||||
if !isUnique {
|
||||
} else if !isUnique {
|
||||
return httperror.Conflict(fmt.Sprintf("Webhook ID: %s already exists", payload.AutoUpdate.Webhook), stackutils.ErrWebhookIDAlreadyExists)
|
||||
}
|
||||
}
|
||||
|
@ -247,16 +242,13 @@ func (handler *Handler) createKubernetesStackFromGitRepository(w http.ResponseWr
|
|||
user)
|
||||
|
||||
stackBuilderDirector := stackbuilders.NewStackBuilderDirector(k8sStackBuilder)
|
||||
_, httpErr := stackBuilderDirector.Build(&stackPayload, endpoint)
|
||||
if httpErr != nil {
|
||||
return httpErr
|
||||
if _, err := stackBuilderDirector.Build(&stackPayload, endpoint); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp := &createKubernetesStackResponse{
|
||||
return response.JSON(w, &createKubernetesStackResponse{
|
||||
Output: k8sStackBuilder.GetResponse(),
|
||||
}
|
||||
|
||||
return response.JSON(w, resp)
|
||||
})
|
||||
}
|
||||
|
||||
// @id StackCreateKubernetesUrl
|
||||
|
@ -296,16 +288,13 @@ func (handler *Handler) createKubernetesStackFromManifestURL(w http.ResponseWrit
|
|||
user)
|
||||
|
||||
stackBuilderDirector := stackbuilders.NewStackBuilderDirector(k8sStackBuilder)
|
||||
_, httpErr := stackBuilderDirector.Build(&stackPayload, endpoint)
|
||||
if httpErr != nil {
|
||||
return httpErr
|
||||
if _, err := stackBuilderDirector.Build(&stackPayload, endpoint); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp := &createKubernetesStackResponse{
|
||||
return response.JSON(w, &createKubernetesStackResponse{
|
||||
Output: k8sStackBuilder.GetResponse(),
|
||||
}
|
||||
|
||||
return response.JSON(w, resp)
|
||||
})
|
||||
}
|
||||
|
||||
func (handler *Handler) deployKubernetesStack(userID portainer.UserID, endpoint *portainer.Endpoint, stack *portainer.Stack, appLabels k.KubeAppLabels) (string, error) {
|
||||
|
@ -320,8 +309,7 @@ func (handler *Handler) deployKubernetesStack(userID portainer.UserID, endpoint
|
|||
return "", errors.Wrap(err, "failed to create temp kub deployment files")
|
||||
}
|
||||
|
||||
err = k8sDeploymentConfig.Deploy()
|
||||
if err != nil {
|
||||
if err := k8sDeploymentConfig.Deploy(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
|
@ -202,40 +201,7 @@ func (handler *Handler) deleteStack(userID portainer.UserID, stack *portainer.St
|
|||
}
|
||||
|
||||
if stack.Type == portainer.KubernetesStack {
|
||||
var manifestFiles []string
|
||||
|
||||
//if it is a compose format kub stack, create a temp dir and convert the manifest files into it
|
||||
//then process the remove operation
|
||||
if stack.IsComposeFormat {
|
||||
fileNames := stackutils.GetStackFilePaths(stack, false)
|
||||
tmpDir, err := os.MkdirTemp("", "kube_delete")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp directory for deleting kub stack")
|
||||
}
|
||||
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
for _, fileName := range fileNames {
|
||||
manifestFilePath := filesystem.JoinPaths(tmpDir, fileName)
|
||||
manifestContent, err := handler.FileService.GetFileContent(stack.ProjectPath, fileName)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read manifest file")
|
||||
}
|
||||
|
||||
manifestContent, err = handler.KubernetesDeployer.ConvertCompose(manifestContent)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to convert docker compose file to a kube manifest")
|
||||
}
|
||||
|
||||
err = filesystem.WriteToFile(manifestFilePath, manifestContent)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create temp manifest file")
|
||||
}
|
||||
manifestFiles = append(manifestFiles, manifestFilePath)
|
||||
}
|
||||
} else {
|
||||
manifestFiles = stackutils.GetStackFilePaths(stack, true)
|
||||
}
|
||||
manifestFiles := stackutils.GetStackFilePaths(stack, true)
|
||||
|
||||
out, err := handler.KubernetesDeployer.Remove(userID, endpoint, manifestFiles, stack.Namespace)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package stacks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
@ -41,6 +40,7 @@ func (payload *kubernetesFileStackUpdatePayload) Validate(r *http.Request) error
|
|||
if govalidator.IsNull(payload.StackFileContent) {
|
||||
return errors.New("Invalid stack file content")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -48,13 +48,13 @@ func (payload *kubernetesGitStackUpdatePayload) Validate(r *http.Request) error
|
|||
if err := update.ValidateAutoUpdateSettings(payload.AutoUpdate); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.Stack, endpoint *portainer.Endpoint) *httperror.HandlerError {
|
||||
|
||||
if stack.GitConfig != nil {
|
||||
//stop the autoupdate job if there is any
|
||||
// Stop the autoupdate job if there is any
|
||||
if stack.AutoUpdate != nil {
|
||||
deployments.StopAutoupdate(stack.ID, stack.AutoUpdate.JobID, handler.Scheduler)
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.
|
|||
|
||||
stack.GitConfig.ReferenceName = payload.RepositoryReferenceName
|
||||
stack.GitConfig.TLSSkipVerify = payload.TLSSkipVerify
|
||||
stack.GitConfig.Authentication = nil
|
||||
stack.AutoUpdate = payload.AutoUpdate
|
||||
|
||||
if payload.RepositoryAuthentication {
|
||||
|
@ -74,16 +75,15 @@ func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.
|
|||
if password == "" && stack.GitConfig != nil && stack.GitConfig.Authentication != nil {
|
||||
password = stack.GitConfig.Authentication.Password
|
||||
}
|
||||
|
||||
stack.GitConfig.Authentication = &gittypes.GitAuthentication{
|
||||
Username: payload.RepositoryUsername,
|
||||
Password: password,
|
||||
}
|
||||
_, err := handler.GitService.LatestCommitID(stack.GitConfig.URL, stack.GitConfig.ReferenceName, stack.GitConfig.Authentication.Username, stack.GitConfig.Authentication.Password, stack.GitConfig.TLSSkipVerify)
|
||||
if err != nil {
|
||||
|
||||
if _, err := handler.GitService.LatestCommitID(stack.GitConfig.URL, stack.GitConfig.ReferenceName, stack.GitConfig.Authentication.Username, stack.GitConfig.Authentication.Password, stack.GitConfig.TLSSkipVerify); err != nil {
|
||||
return httperror.InternalServerError("Unable to fetch git repository", err)
|
||||
}
|
||||
} else {
|
||||
stack.GitConfig.Authentication = nil
|
||||
}
|
||||
|
||||
if payload.AutoUpdate != nil && payload.AutoUpdate.Interval != "" {
|
||||
|
@ -99,8 +99,7 @@ func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.
|
|||
|
||||
var payload kubernetesFileStackUpdatePayload
|
||||
|
||||
err := request.DecodeAndValidateJSONPayload(r, &payload)
|
||||
if err != nil {
|
||||
if err := request.DecodeAndValidateJSONPayload(r, &payload); err != nil {
|
||||
return httperror.BadRequest("Invalid request payload", err)
|
||||
}
|
||||
|
||||
|
@ -118,8 +117,7 @@ func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.
|
|||
|
||||
if payload.StackName != stack.Name {
|
||||
stack.Name = payload.StackName
|
||||
err := handler.DataStore.Stack().Update(stack.ID, stack)
|
||||
if err != nil {
|
||||
if err := handler.DataStore.Stack().Update(stack.ID, stack); err != nil {
|
||||
return httperror.InternalServerError("Failed to update stack name", err)
|
||||
}
|
||||
}
|
||||
|
@ -132,18 +130,16 @@ func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.
|
|||
registryutils.RefreshEcrSecret(cli, endpoint, handler.DataStore, stack.Namespace)
|
||||
}
|
||||
|
||||
//use temp dir as the stack project path for deployment
|
||||
//so if the deployment failed, the original file won't be over-written
|
||||
// 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(tokenData.ID, endpoint, stack, k.KubeAppLabels{
|
||||
if _, err := handler.deployKubernetesStack(tokenData.ID, endpoint, stack, k.KubeAppLabels{
|
||||
StackID: int(stack.ID),
|
||||
StackName: stack.Name,
|
||||
Owner: stack.CreatedBy,
|
||||
Kind: "content",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
}); err != nil {
|
||||
return httperror.InternalServerError("Unable to deploy Kubernetes stack via file content", err)
|
||||
}
|
||||
|
||||
|
@ -154,12 +150,7 @@ func (handler *Handler) updateKubernetesStack(r *http.Request, stack *portainer.
|
|||
log.Warn().Err(rollbackErr).Msg("rollback stack file error")
|
||||
}
|
||||
|
||||
fileType := "Manifest"
|
||||
if stack.IsComposeFormat {
|
||||
fileType = "Compose"
|
||||
}
|
||||
errMsg := fmt.Sprintf("Unable to persist Kubernetes %s file on disk", fileType)
|
||||
return httperror.InternalServerError(errMsg, err)
|
||||
return httperror.InternalServerError("Unable to persist Kubernetes Manifest file on disk", err)
|
||||
}
|
||||
stack.ProjectPath = projectPath
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue