mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
93e3801945
* Implement helm step * Create kubernetes package * Refactoring helm.go * Add package, test commands * Add test for helm package * Add tests for helm.go * Add tests for helm.go * Add tests for utils.go * Add tests for helmExecute.go * small fix * Add helm lint * small fix * small fix * Fix according to comments * Fix test * small fix * Add helm add function * Changes according to new comments * Add helm push * Add unit tests * Add tests for helmExecute * Add small fix * small fix * small fix * Move DeployUtilsBundle from kubernetesDeploy to kubernetes package * small fix * small fix * Add unit-tests * Fix * Update resources/metadata/helmExecute.yaml * Update resources/metadata/helmExecute.yaml * Add helm chart server parameterization * small fix * small fix Co-authored-by: “Vitalii <“vitalii.sidorov@sap.com”> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
90 lines
2.8 KiB
Go
90 lines
2.8 KiB
Go
package kubernetes
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/command"
|
|
"github.com/SAP/jenkins-library/pkg/docker"
|
|
"github.com/SAP/jenkins-library/pkg/piperutils"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
)
|
|
|
|
// DeployUtils interface
|
|
type DeployUtils interface {
|
|
SetEnv(env []string)
|
|
Stdout(out io.Writer)
|
|
Stderr(err io.Writer)
|
|
RunExecutable(e string, p ...string) error
|
|
|
|
piperutils.FileUtils
|
|
}
|
|
|
|
// deployUtilsBundle struct for utils
|
|
type deployUtilsBundle struct {
|
|
*command.Command
|
|
*piperutils.Files
|
|
}
|
|
|
|
// NewDeployUtilsBundle initialize using deployUtilsBundle struct
|
|
func NewDeployUtilsBundle() DeployUtils {
|
|
utils := deployUtilsBundle{
|
|
Command: &command.Command{
|
|
ErrorCategoryMapping: map[string][]string{
|
|
log.ErrorConfiguration.String(): {
|
|
"Error: Get * no such host",
|
|
"Error: path * not found",
|
|
"Error: rendered manifests contain a resource that already exists.",
|
|
"Error: unknown flag",
|
|
"Error: UPGRADE FAILED: * failed to replace object: * is invalid",
|
|
"Error: UPGRADE FAILED: * failed to create resource: * is invalid",
|
|
"Error: UPGRADE FAILED: an error occurred * not found",
|
|
"Error: UPGRADE FAILED: query: failed to query with labels:",
|
|
"Invalid value: \"\": field is immutable",
|
|
},
|
|
log.ErrorCustom.String(): {
|
|
"Error: release * failed, * timed out waiting for the condition",
|
|
},
|
|
},
|
|
},
|
|
Files: &piperutils.Files{},
|
|
}
|
|
// reroute stderr output to logging framework, stdout will be used for command interactions
|
|
utils.Stderr(log.Writer())
|
|
return &utils
|
|
}
|
|
|
|
func getContainerInfo(config HelmExecuteOptions) (map[string]string, error) {
|
|
var err error
|
|
containerRegistry, err := docker.ContainerRegistryFromURL(config.ContainerRegistryURL)
|
|
if err != nil {
|
|
log.Entry().WithError(err).Fatalf("Container registry url '%v' incorrect", config.ContainerRegistryURL)
|
|
}
|
|
|
|
//support either image or containerImageName and containerImageTag
|
|
containerInfo := map[string]string{
|
|
"containerImageName": "",
|
|
"containerImageTag": "",
|
|
"containerRegistry": containerRegistry,
|
|
}
|
|
|
|
if len(config.Image) > 0 {
|
|
ref, err := docker.ContainerImageNameTagFromImage(config.Image)
|
|
if err != nil {
|
|
log.Entry().WithError(err).Fatalf("Container image '%v' incorrect", config.Image)
|
|
}
|
|
parts := strings.Split(ref, ":")
|
|
containerInfo["containerImageName"] = parts[0]
|
|
containerInfo["containerImageTag"] = parts[1]
|
|
} else if len(config.ContainerImageName) > 0 && len(config.ContainerImageTag) > 0 {
|
|
containerInfo["containerImageName"] = config.ContainerImageName
|
|
containerInfo["containerImageTag"] = config.ContainerImageTag
|
|
} else {
|
|
return nil, fmt.Errorf("image information not given - please either set image or containerImageName and containerImageTag")
|
|
}
|
|
|
|
return containerInfo, nil
|
|
}
|