Skip to content

Commit

Permalink
improve logging (run-int-tests) (gardener#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
achimweigel authored Feb 12, 2024
1 parent 95edff6 commit 94decb9
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
11 changes: 8 additions & 3 deletions pkg/deployer/helm/chartresolver/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ func GetChart(ctx context.Context,
func getChartFromResourceRef(ctx context.Context, resourceRef string, lsCtx *lsv1alpha1.Context,
lsClient client.Client) (_ *chart.Chart, err error) {

op := "getChartFromResourceRef"

octx := ocm.New(datacontext.MODE_EXTENDED)

if lsCtx == nil {
return nil, fmt.Errorf("landscaper context cannot be nil")
return nil, lserrors.NewError(op, "NoContext", "landscaper context cannot be nil", lsv1alpha1.ErrorForInfoOnly,
lsv1alpha1.ErrorConfigurationProblem)
}
if lsCtx.RepositoryContext == nil || lsCtx.RepositoryContext.Raw == nil {
return nil, fmt.Errorf("landscaper context %s/%s does not specify a repository context but has"+

if lsCtx == nil || lsCtx.RepositoryContext == nil || lsCtx.RepositoryContext.Raw == nil {
msg := fmt.Sprintf("landscaper context %s/%s does not specify a repository context but has"+
" to specify a repository context to resolve resource from an ocm reference", lsCtx.Namespace, lsCtx.Name)
return nil, lserrors.NewError(op, "NoContext", msg, lsv1alpha1.ErrorForInfoOnly, lsv1alpha1.ErrorConfigurationProblem)
}

// Credential Handling
Expand Down
13 changes: 12 additions & 1 deletion pkg/deployer/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"strings"

"github.com/gardener/component-cli/ociclient/cache"
"helm.sh/helm/v3/pkg/chart"
Expand Down Expand Up @@ -145,6 +146,9 @@ func (h *Helm) Template(ctx context.Context) (map[string]string, map[string]stri
h.Configuration.OCI,
h.SharedCache)
if err != nil {
if h.isDownloadInfoError(err) {
return nil, nil, nil, nil, lserrors.NewWrappedError(err, currOp, "GetHelmChart", err.Error(), lsv1alpha1.ErrorForInfoOnly)
}
return nil, nil, nil, nil, lserrors.NewWrappedError(err, currOp, "GetHelmChart", err.Error())
}

Expand All @@ -164,7 +168,7 @@ func (h *Helm) Template(ctx context.Context) (map[string]string, map[string]stri
values, err = chartutil.ToRenderValues(ch, values, options, nil)
if err != nil {
return nil, nil, nil, nil, lserrors.NewWrappedError(
err, currOp, "RenderHelmValues", err.Error(), lsv1alpha1.ErrorConfigurationProblem)
err, currOp, "PrepareHelmValues", err.Error(), lsv1alpha1.ErrorConfigurationProblem)
}

files, err := engine.RenderWithClient(ch, values, restConfig)
Expand Down Expand Up @@ -250,3 +254,10 @@ func (h *Helm) TargetClient(ctx context.Context) (*rest.Config, client.Client, k
}
return nil, nil, nil, errors.New("neither a target nor kubeconfig are defined")
}

func (h *Helm) isDownloadInfoError(err error) bool {
msg := err.Error()
return strings.Contains(msg, "no chart name found") ||
(strings.Contains(msg, "cannot get chart repository") && strings.Contains(msg, "could not find protocol handler for")) ||
(strings.Contains(msg, "cannot download repository index for") && strings.Contains(msg, "404 Not Found"))
}
21 changes: 20 additions & 1 deletion pkg/deployer/helm/realhelmdeployer/real_helm_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func (c *RealHelmDeployer) installRelease(ctx context.Context, values map[string

message := fmt.Sprintf("unable to install helm chart release: %s", err.Error())
logger.Info(message)

if c.isHelmInstallMessage(message) {
return nil, lserror.NewWrappedError(err, currOp, "Install", message, lsv1alpha1.ErrorForInfoOnly)
}
return nil, lserror.NewWrappedError(err, currOp, "Install", message)
}

Expand All @@ -172,6 +176,10 @@ func (c *RealHelmDeployer) installRelease(ctx context.Context, values map[string
return rel, nil
}

func (c *RealHelmDeployer) isHelmInstallMessage(message string) bool {
return strings.Contains(message, "rendered manifests contain a resource that already exists. Unable to continue with install")
}

// upgradeRelease upgrades a helm release
func (c *RealHelmDeployer) upgradeRelease(ctx context.Context, values map[string]interface{}) (*release.Release, error) {
currOp := "UpgradeHelmRelease"
Expand Down Expand Up @@ -208,14 +216,25 @@ func (c *RealHelmDeployer) upgradeRelease(ctx context.Context, values map[string

message := fmt.Sprintf("unable to upgrade helm chart release: %s", err.Error())
logger.Info(message)
return nil, lserror.NewWrappedError(err, currOp, "Install", message)

if c.isHelmUpgradeMessage(message) {
return nil, lserror.NewWrappedError(err, currOp, "Update", message, lsv1alpha1.ErrorForInfoOnly)
}
return nil, lserror.NewWrappedError(err, currOp, "Update", message)
}

logger.Info(fmt.Sprintf("%s successfully upgraded in %s", c.releaseName, c.defaultNamespace))

return rel, nil
}

func (c *RealHelmDeployer) isHelmUpgradeMessage(message string) bool {
return strings.Contains(message, "rendered manifests contain a resource that already exists. Unable to continue with update") ||
strings.Contains(message, "pre-upgrade hooks failed") ||
strings.Contains(message, "The order in patch list") ||
strings.Contains(message, "YAML parse error on")
}

func (c *RealHelmDeployer) deleteRelease(ctx context.Context) error {
currOp := "DeleteHelmRelease"
logger, ctx := logging.FromContextOrNew(ctx, []interface{}{lc.KeyMethod, currOp})
Expand Down
7 changes: 6 additions & 1 deletion pkg/deployer/lib/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,12 @@ func (c *controller) buildResult(ctx context.Context, phase lsv1alpha1.DeployIte

if lsError != nil {
logger, _ := logging.FromContextOrNew(ctx, nil)
logger.Error(lsError, "reconcile deploy item")

if lserrors.ContainsErrorCode(lsError, lsv1alpha1.ErrorForInfoOnly) {
logger.Info(lsError.Error())
} else {
logger.Error(lsError, "reconcile deploy item")
}
}

if phase.IsFinal() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/deployer/lib/readinesscheck/readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func WaitForObjectsReady(ctx context.Context, timeout time.Duration, kubeClient

if wait.Interrupted(err) {
msg := fmt.Sprintf("timeout at: %q", checkpoint)
return lserror.NewWrappedError(err, "WaitForObjectsReady", lsv1alpha1.ProgressingTimeoutReason, msg, lsv1alpha1.ErrorTimeout)
return lserror.NewWrappedError(err, "WaitForObjectsReady", lsv1alpha1.ProgressingTimeoutReason, msg,
lsv1alpha1.ErrorTimeout, lsv1alpha1.ErrorForInfoOnly)
}

return err
Expand Down
10 changes: 8 additions & 2 deletions pkg/landscaper/installations/executions/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"context"
"fmt"

lserrors "github.com/gardener/landscaper/apis/errors"

apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down Expand Up @@ -53,7 +55,11 @@ func New(op *installations.Operation) *ExecutionOperation {
}
}

func (o *ExecutionOperation) RenderDeployItemTemplates(ctx context.Context, inst *installations.InstallationImportsAndBlueprint) (core.DeployItemTemplateList, error) {
func (o *ExecutionOperation) RenderDeployItemTemplates(ctx context.Context,
inst *installations.InstallationImportsAndBlueprint) (core.DeployItemTemplateList, error) {

op := "RenderDeployItemTemplates"

cond := lsv1alpha1helper.GetOrInitCondition(inst.GetInstallation().Status.Conditions, lsv1alpha1.ReconcileExecutionCondition)

templateStateHandler := template.KubernetesStateHandler{
Expand All @@ -74,7 +80,7 @@ func (o *ExecutionOperation) RenderDeployItemTemplates(ctx context.Context, inst
if err != nil {
inst.MergeConditions(lsv1alpha1helper.UpdatedCondition(cond, lsv1alpha1.ConditionFalse,
TemplatingFailedReason, "Unable to template executions"))
return nil, fmt.Errorf("RenderDeployItemTemplates - unable to template executions: %w", err)
return nil, lserrors.NewWrappedError(err, op, "Template", "unable to template executions", lsv1alpha1.ErrorForInfoOnly)
}

if len(executions) == 0 {
Expand Down

0 comments on commit 94decb9

Please sign in to comment.