1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/gitopsUpdateDeployment.go

415 lines
13 KiB
Go
Raw Normal View History

feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
package cmd
import (
"bytes"
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
"fmt"
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/docker"
gitUtil "github.com/SAP/jenkins-library/pkg/git"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/pkg/errors"
"io"
"os"
"path/filepath"
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
"strings"
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
)
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
const toolKubectl = "kubectl"
const toolHelm = "helm"
const toolKustomize = "kustomize"
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
type iGitopsUpdateDeploymentGitUtils interface {
CommitSingleFile(filePath, commitMessage, author string) (plumbing.Hash, error)
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
PushChangesToRepository(username, password string) error
PlainClone(username, password, serverURL, directory string) error
ChangeBranch(branchName string) error
}
type gitopsUpdateDeploymentFileUtils interface {
TempDir(dir, pattern string) (name string, err error)
RemoveAll(path string) error
FileWrite(path string, content []byte, perm os.FileMode) error
}
type gitopsUpdateDeploymentExecRunner interface {
RunExecutable(executable string, params ...string) error
Stdout(out io.Writer)
Stderr(err io.Writer)
SetDir(dir string)
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
type gitopsUpdateDeploymentGitUtils struct {
worktree *git.Worktree
repository *git.Repository
}
func (g *gitopsUpdateDeploymentGitUtils) CommitSingleFile(filePath, commitMessage, author string) (plumbing.Hash, error) {
return gitUtil.CommitSingleFile(filePath, commitMessage, author, g.worktree)
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
func (g *gitopsUpdateDeploymentGitUtils) PushChangesToRepository(username, password string) error {
return gitUtil.PushChangesToRepository(username, password, g.repository)
}
func (g *gitopsUpdateDeploymentGitUtils) PlainClone(username, password, serverURL, directory string) error {
var err error
g.repository, err = gitUtil.PlainClone(username, password, serverURL, directory)
if err != nil {
return errors.Wrap(err, "plain clone failed")
}
g.worktree, err = g.repository.Worktree()
return errors.Wrap(err, "failed to retrieve worktree")
}
func (g *gitopsUpdateDeploymentGitUtils) ChangeBranch(branchName string) error {
return gitUtil.ChangeBranch(branchName, g.worktree)
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
func gitopsUpdateDeployment(config gitopsUpdateDeploymentOptions, _ *telemetry.CustomData) {
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
// for command execution use Command
var c gitopsUpdateDeploymentExecRunner = &command.Command{}
// reroute command output to logging framework
c.Stdout(log.Writer())
c.Stderr(log.Writer())
// for http calls import piperhttp "github.com/SAP/jenkins-library/pkg/http"
// and use a &piperhttp.Client{} in a custom system
// Example: step checkmarxExecuteScan.go
// error situations should stop execution through log.Entry().Fatal() call which leads to an os.Exit(1) in the end
err := runGitopsUpdateDeployment(&config, c, &gitopsUpdateDeploymentGitUtils{}, piperutils.Files{})
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runGitopsUpdateDeployment(config *gitopsUpdateDeploymentOptions, command gitopsUpdateDeploymentExecRunner, gitUtils iGitopsUpdateDeploymentGitUtils, fileUtils gitopsUpdateDeploymentFileUtils) error {
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
err := checkRequiredFieldsForDeployTool(config)
if err != nil {
return err
}
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
temporaryFolder, err := fileUtils.TempDir(".", "temp-")
if err != nil {
return errors.Wrap(err, "failed to create temporary directory")
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
defer func() {
err = fileUtils.RemoveAll(temporaryFolder)
if err != nil {
log.Entry().WithError(err).Error("error during temporary directory deletion")
}
}()
err = cloneRepositoryAndChangeBranch(config, gitUtils, temporaryFolder)
if err != nil {
return errors.Wrap(err, "repository could not get prepared")
}
filePath := filepath.Join(temporaryFolder, config.FilePath)
var outputBytes []byte
if config.Tool == toolKubectl {
outputBytes, err = executeKubectl(config, command, outputBytes, filePath)
if err != nil {
return errors.Wrap(err, "error on kubectl execution")
}
} else if config.Tool == toolHelm {
outputBytes, err = runHelmCommand(command, config)
if err != nil {
return errors.Wrap(err, "failed to apply helm command")
}
} else if config.Tool == toolKustomize {
outputBytes, err = runKustomizeCommand(command, config, filePath)
if err != nil {
return errors.Wrap(err, "failed to apply kustomize command")
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
} else {
log.SetErrorCategory(log.ErrorConfiguration)
return errors.New("tool " + config.Tool + " is not supported")
}
err = fileUtils.FileWrite(filePath, outputBytes, 0755)
if err != nil {
return errors.Wrap(err, "failed to write file")
}
commit, err := commitAndPushChanges(config, gitUtils)
if err != nil {
return errors.Wrap(err, "failed to commit and push changes")
}
log.Entry().Infof("Changes committed with %s", commit.String())
return nil
}
func checkRequiredFieldsForDeployTool(config *gitopsUpdateDeploymentOptions) error {
if config.Tool == toolHelm {
err := checkRequiredFieldsForHelm(config)
if err != nil {
return errors.Wrap(err, "missing required fields for helm")
}
logNotRequiredButFilledFieldForHelm(config)
} else if config.Tool == toolKubectl {
err := checkRequiredFieldsForKubectl(config)
if err != nil {
return errors.Wrap(err, "missing required fields for kubectl")
}
logNotRequiredButFilledFieldForKubectl(config)
} else if config.Tool == toolKustomize {
err := checkRequiredFieldsForKustomize(config)
if err != nil {
return errors.Wrap(err, "missing required fields for kustomize")
}
logNotRequiredButFilledFieldForKustomize(config)
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
}
return nil
}
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
func checkRequiredFieldsForHelm(config *gitopsUpdateDeploymentOptions) error {
var missingParameters []string
if config.ChartPath == "" {
missingParameters = append(missingParameters, "chartPath")
}
if config.DeploymentName == "" {
missingParameters = append(missingParameters, "deploymentName")
}
if len(missingParameters) > 0 {
log.SetErrorCategory(log.ErrorConfiguration)
return errors.Errorf("the following parameters are necessary for helm: %v", missingParameters)
}
return nil
}
func checkRequiredFieldsForKustomize(config *gitopsUpdateDeploymentOptions) error {
var missingParameters []string
if config.FilePath == "" {
missingParameters = append(missingParameters, "filePath")
}
if config.DeploymentName == "" {
missingParameters = append(missingParameters, "deploymentName")
}
if len(missingParameters) > 0 {
log.SetErrorCategory(log.ErrorConfiguration)
return errors.Errorf("the following parameters are necessary for kustomize: %v", missingParameters)
}
return nil
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
func checkRequiredFieldsForKubectl(config *gitopsUpdateDeploymentOptions) error {
var missingParameters []string
if config.ContainerName == "" {
missingParameters = append(missingParameters, "containerName")
}
if len(missingParameters) > 0 {
log.SetErrorCategory(log.ErrorConfiguration)
return errors.Errorf("the following parameters are necessary for kubectl: %v", missingParameters)
}
return nil
}
func logNotRequiredButFilledFieldForHelm(config *gitopsUpdateDeploymentOptions) {
if config.ContainerName != "" {
log.Entry().Info("containerName is not used for helm and can be removed")
}
}
func logNotRequiredButFilledFieldForKubectl(config *gitopsUpdateDeploymentOptions) {
if config.ChartPath != "" {
log.Entry().Info("chartPath is not used for kubectl and can be removed")
}
if len(config.HelmValues) > 0 {
log.Entry().Info("helmValues is not used for kubectl and can be removed")
}
if len(config.DeploymentName) > 0 {
log.Entry().Info("deploymentName is not used for kubectl and can be removed")
}
}
func logNotRequiredButFilledFieldForKustomize(config *gitopsUpdateDeploymentOptions) {
if config.ChartPath != "" {
log.Entry().Info("chartPath is not used for kubectl and can be removed")
}
if len(config.HelmValues) > 0 {
log.Entry().Info("helmValues is not used for kubectl and can be removed")
}
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
func cloneRepositoryAndChangeBranch(config *gitopsUpdateDeploymentOptions, gitUtils iGitopsUpdateDeploymentGitUtils, temporaryFolder string) error {
err := gitUtils.PlainClone(config.Username, config.Password, config.ServerURL, temporaryFolder)
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
if err != nil {
return errors.Wrap(err, "failed to plain clone repository")
}
err = gitUtils.ChangeBranch(config.BranchName)
if err != nil {
return errors.Wrap(err, "failed to change branch")
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
return nil
}
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
func executeKubectl(config *gitopsUpdateDeploymentOptions, command gitopsUpdateDeploymentExecRunner, outputBytes []byte, filePath string) ([]byte, error) {
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
registryImage, err := buildRegistryPlusImage(config)
if err != nil {
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
return nil, errors.Wrap(err, "failed to apply kubectl command")
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
patchString := "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"" + config.ContainerName + "\",\"image\":\"" + registryImage + "\"}]}}}}"
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
outputBytes, err = runKubeCtlCommand(command, patchString, filePath)
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
if err != nil {
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
return nil, errors.Wrap(err, "failed to apply kubectl command")
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
return outputBytes, nil
}
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
func buildRegistryPlusImage(config *gitopsUpdateDeploymentOptions) (string, error) {
registryURL := config.ContainerRegistryURL
if registryURL == "" {
return config.ContainerImageNameTag, nil
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
url, err := docker.ContainerRegistryFromURL(registryURL)
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
if err != nil {
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
return "", errors.Wrap(err, "registry URL could not be extracted")
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
if url != "" {
url = url + "/"
}
return url + config.ContainerImageNameTag, nil
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
func runKubeCtlCommand(command gitopsUpdateDeploymentExecRunner, patchString string, filePath string) ([]byte, error) {
var kubectlOutput = bytes.Buffer{}
command.Stdout(&kubectlOutput)
kubeParams := []string{
"patch",
"--local",
"--output=yaml",
"--patch=" + patchString,
"--filename=" + filePath,
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
err := command.RunExecutable(toolKubectl, kubeParams...)
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
if err != nil {
return nil, errors.Wrap(err, "failed to apply kubectl command")
}
return kubectlOutput.Bytes(), nil
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
func runHelmCommand(runner gitopsUpdateDeploymentExecRunner, config *gitopsUpdateDeploymentOptions) ([]byte, error) {
var helmOutput = bytes.Buffer{}
runner.Stdout(&helmOutput)
registryImage, imageTag, err := buildRegistryPlusImageAndTagSeparately(config)
if err != nil {
return nil, errors.Wrap(err, "failed to extract registry URL, image name, and image tag")
}
helmParams := []string{
"template",
config.DeploymentName,
filepath.Join(".", config.ChartPath),
"--set=image.repository=" + registryImage,
"--set=image.tag=" + imageTag,
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
for _, value := range config.HelmValues {
helmParams = append(helmParams, "--values", value)
}
err = runner.RunExecutable(toolHelm, helmParams...)
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
if err != nil {
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
return nil, errors.Wrap(err, "failed to execute helm command")
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
return helmOutput.Bytes(), nil
}
func runKustomizeCommand(runner gitopsUpdateDeploymentExecRunner, config *gitopsUpdateDeploymentOptions, filePath string) ([]byte, error) {
var kustomizeOutput = bytes.Buffer{}
runner.Stdout(&kustomizeOutput)
kustomizeParams := []string{
"edit",
"set",
"image",
config.DeploymentName + "=" + config.ContainerImageNameTag,
}
runner.SetDir(filepath.Dir(filePath))
err := runner.RunExecutable(toolKustomize, kustomizeParams...)
if err != nil {
return nil, errors.Wrap(err, "failed to execute kustomize command")
}
return kustomizeOutput.Bytes(), nil
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
// buildRegistryPlusImageAndTagSeparately combines the registry together with the image name. Handles the tag separately.
// Tag is defined by everything on the right hand side of the colon sign. This looks weird for sha container versions but works for helm.
func buildRegistryPlusImageAndTagSeparately(config *gitopsUpdateDeploymentOptions) (string, string, error) {
registryURL := config.ContainerRegistryURL
url := ""
if registryURL != "" {
containerURL, err := docker.ContainerRegistryFromURL(registryURL)
if err != nil {
return "", "", errors.Wrap(err, "registry URL could not be extracted")
}
if containerURL != "" {
containerURL = containerURL + "/"
}
url = containerURL
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
imageNameTag := config.ContainerImageNameTag
var imageName, imageTag string
if strings.Contains(imageNameTag, ":") {
split := strings.Split(imageNameTag, ":")
if split[0] == "" {
log.SetErrorCategory(log.ErrorConfiguration)
return "", "", errors.New("image name could not be extracted")
}
if split[1] == "" {
log.SetErrorCategory(log.ErrorConfiguration)
return "", "", errors.New("tag could not be extracted")
}
imageName = split[0]
imageTag = split[1]
return url + imageName, imageTag, nil
}
log.SetErrorCategory(log.ErrorConfiguration)
return "", "", errors.New("image name and tag could not be extracted")
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
}
func commitAndPushChanges(config *gitopsUpdateDeploymentOptions, gitUtils iGitopsUpdateDeploymentGitUtils) (plumbing.Hash, error) {
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
commitMessage := config.CommitMessage
if commitMessage == "" {
commitMessage = defaultCommitMessage(config)
}
commit, err := gitUtils.CommitSingleFile(config.FilePath, commitMessage, config.Username)
feat(Gitops): new step to update deployment (#2178) * kanikoExecute: improve user experience * ensure proper tags * update permissions in case a container runs with a different user we need to make sure that the orchestrator user can work on the file * update permissions * ensure availablility of directories on Jenkins * (fix) clean up tmp dir in test * add resilience for incorrect step yaml * incorporate PR feedback * Adds piper step to update deployment configuration in external git repository. https://github.wdf.sap.corp/ContinuousDelivery/piper-ita/issues/21 * Adds handling of branchName as an optional parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Feedback about description Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adapt to interface guide * Refactors to GitopsExecRunner * Refactors to GitopsExecRunner in test * Removes unnecessary mocked methods * Adds tests for git utils * Adds new step to CommonStepsTest.groovy * Updates description from yaml * Restricts visibility of methods and interfaces Adds comments where necessary * Updates comments * Fixes URL name * updates description * updates generated file * Fixes compile issue in CommonStepsTest.groovy * Updates long description * Updates test to run green on all kind of OS * Removes global variables from tests * Default branch: master Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Typo in Hierarchy Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> * Refactors test to allow parallel execution * Renames utility variable in gitopsUpdateDeployment.go * Renames error variables in gitopsUpdateDeployment.go * simplified parameters for kubectl * Refactors util classes to use parameters rather than global variables * makes username and password mandatory * remove unnecessary mandatory flag * remove new methods from mock that are not necessary * replaces with EqualError * replaces with NoError * update generated file * refactor tests * refactor tests * make tests parallel executable * parallel execution of tests * Refactors interfaces to stop exposing interfaces * Feedback from PR * Simplifies failing mocks * Renames variables and interfaces * Fixes error messages * shorten variable names * Renames unused parameters in tests * Cleanup nil parameters * Typo * Wrap errors and remove unnecessary logs * Remove containername and filePath from GENERAL scope * correct generated file * corrects expected error messages Co-authored-by: OliverNocon <oliver.nocon@sap.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-20 09:05:17 +02:00
if err != nil {
return [20]byte{}, errors.Wrap(err, "committing changes failed")
}
err = gitUtils.PushChangesToRepository(config.Username, config.Password)
if err != nil {
return [20]byte{}, errors.Wrap(err, "pushing changes failed")
}
return commit, nil
}
feat(Gitops): Gitops update deployment with helm (#2247) * makes containerImage not mandatory * Adds kubectl container * Adds log statement to debug * adds general to container image * removes GENERAL again Removes condition from Kubectl container * removes workDir * marks logs as debug * adds workingdir again * Adds author to commits * Adds commit time now * remove deprecated and reorder * adds deprecated again to containerRegistryUrl Adds GENERAL scope to containerImage * updates generated file * Renames containerImageNameTag * adds else case * adds debug log * code cleanup * adds debug log * revert * adds debug logs * revert * makes root path not hidden * revert * Read container properties * Removes debug message * Removes debug message * Removes general scope again * Fixes unit test * Adds helm capabilities to the gitopsUpdateDeployment step * Adds helm capabilities to gitopsUpdateDeployment step * Removes condition from input field * Adds test for invalid deploy tool * Fixes typo * Adds tests for git errors and file errors Simplifies test setup * Adds test for error on image name extraction * fixes URL variable name * adds workind directory to paths * Refactors too long method * Reverts refactoring method * Adds repository name as parameter * Adds glob method * Test glob method * Revert "Test glob method" This reverts commit ac11b54c147f0326be60887ca69f6e7073c23d60. * Revert "Adds glob method" This reverts commit ddf47ddebe16ffede7d10388f986e5e1ec7805cc. * Revert "Adds repository name as parameter" This reverts commit 8fc471c909075629c6f9913559c5dc4841caf629. * Removes getWd * Adds stash deployDescriptor * removes = from paramters * Revert "removes = from paramters" This reverts commit 3ecb3665e2da2f3c75a391711863189be12ea29d. * Adds " around parameters * adds logging of all files * Updates helm to version 3.3.4 * Clean up debug logs * Raise error if no branch name provided. Defaulting should be handled by step configuration. * clean code * Updates fields and adds checks for required field for certain deploy tools * Fixes default commit message * Update long description * Removes default parameter * Update resources/metadata/gitopsUpdateDeployment.yaml Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Updates yaml file * Add error category and removes too much wrapping * Update generated file * Checks all parameters before returning the error * Introduces constant * Renames constant * Fixes unit tests * unexpose constants * Makes tests thread safe and resilient to failed deletion * Remove methods that did not work properly with hash containers rather than tags. Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-11-03 19:29:46 +02:00
func defaultCommitMessage(config *gitopsUpdateDeploymentOptions) string {
image, tag, _ := buildRegistryPlusImageAndTagSeparately(config)
commitMessage := fmt.Sprintf("Updated %v to version %v", image, tag)
return commitMessage
}