Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(application): update install failed and upgrade failed message #2113

Merged
merged 1 commit into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 9 additions & 24 deletions pkg/application/controller/app/action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package action

import (
"context"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
applicationv1 "tkestack.io/tke/api/application/v1"
applicationversionedclient "tkestack.io/tke/api/client/clientset/versioned/typed/application/v1"
Expand All @@ -32,7 +30,6 @@ import (
applicationprovider "tkestack.io/tke/pkg/application/provider/application"
"tkestack.io/tke/pkg/application/util"
chartpath "tkestack.io/tke/pkg/application/util/chartpath/v1"
"tkestack.io/tke/pkg/util/log"
"tkestack.io/tke/pkg/util/metrics"
)

Expand All @@ -43,8 +40,13 @@ func Install(ctx context.Context,
app *applicationv1.App,
repo appconfig.RepoConfiguration,
updateStatusFunc applicationprovider.UpdateStatusFunc) (*applicationv1.App, error) {
newApp, err := applicationClient.Apps(app.Namespace).Get(ctx, app.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

hooks := getHooks(app)
err := hooks.PreInstall(ctx, applicationClient, platformClient, app, repo, updateStatusFunc)
err = hooks.PreInstall(ctx, applicationClient, platformClient, app, repo, updateStatusFunc)
if err != nil {
return nil, err
}
Expand All @@ -54,31 +56,20 @@ func Install(ctx context.Context,
}
destfile, err := Pull(ctx, applicationClient, platformClient, app, repo, updateStatusFunc)
if err != nil {
newStatus := app.Status.DeepCopy()
newStatus := newApp.Status.DeepCopy()
if updateStatusFunc != nil {
if app.Status.Phase == applicationv1.AppPhaseInstallFailed {
log.Error(fmt.Sprintf("install app failed, helm pull err: %s", err.Error()))
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
// delayed retry, queue.AddRateLimited does not meet the demand
return app, nil
}
newStatus.Phase = applicationv1.AppPhaseInstallFailed
newStatus.Message = "fetch chart failed"
newStatus.Reason = err.Error()
newStatus.LastTransitionTime = metav1.Now()
_, updateStatusErr := updateStatusFunc(ctx, app, &app.Status, newStatus)
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
_, updateStatusErr := updateStatusFunc(ctx, newApp, &newApp.Status, newStatus)
metrics.GaugeApplicationInstallFailed.WithLabelValues(newApp.Spec.TargetCluster, newApp.Name).Set(1)
if updateStatusErr != nil {
return nil, updateStatusErr
}
}
}

newApp, err := applicationClient.Apps(app.Namespace).Get(ctx, app.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

values, err := helmutil.MergeValues(app.Spec.Values.Values, app.Spec.Values.RawValues, string(app.Spec.Values.RawValuesType))
if err != nil {
return nil, err
Expand All @@ -102,12 +93,6 @@ func Install(ctx context.Context,
newStatus := newApp.Status.DeepCopy()
var updateStatusErr error
if err != nil {
if app.Status.Phase == applicationv1.AppPhaseInstallFailed {
log.Error(fmt.Sprintf("install app failed, helm install err: %s", err.Error()))
metrics.GaugeApplicationInstallFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
// delayed retry, queue.AddRateLimited does not meet the demand
return app, nil
}
newStatus.Phase = applicationv1.AppPhaseInstallFailed
newStatus.Message = "install app failed"
newStatus.Reason = err.Error()
Expand Down
36 changes: 12 additions & 24 deletions pkg/application/controller/app/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package action

import (
"context"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
applicationv1 "tkestack.io/tke/api/application/v1"
applicationversionedclient "tkestack.io/tke/api/client/clientset/versioned/typed/application/v1"
Expand All @@ -32,7 +30,6 @@ import (
applicationprovider "tkestack.io/tke/pkg/application/provider/application"
"tkestack.io/tke/pkg/application/util"
chartpath "tkestack.io/tke/pkg/application/util/chartpath/v1"
"tkestack.io/tke/pkg/util/log"
"tkestack.io/tke/pkg/util/metrics"
)

Expand All @@ -43,8 +40,13 @@ func Upgrade(ctx context.Context,
app *applicationv1.App,
repo appconfig.RepoConfiguration,
updateStatusFunc applicationprovider.UpdateStatusFunc) (*applicationv1.App, error) {
newApp, err := applicationClient.Apps(app.Namespace).Get(ctx, app.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

hooks := getHooks(app)
err := hooks.PreUpgrade(ctx, applicationClient, platformClient, app, repo, updateStatusFunc)
err = hooks.PreUpgrade(ctx, applicationClient, platformClient, app, repo, updateStatusFunc)
if err != nil {
return nil, err
}
Expand All @@ -55,29 +57,21 @@ func Upgrade(ctx context.Context,

destfile, err := Pull(ctx, applicationClient, platformClient, app, repo, updateStatusFunc)
if err != nil {
newStatus := app.Status.DeepCopy()
newStatus := newApp.Status.DeepCopy()
if updateStatusFunc != nil {
if app.Status.Phase == applicationv1.AppPhaseUpgradFailed {
log.Error(fmt.Sprintf("upgrade app failed, helm pull err: %s", err.Error()))
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
// delayed retry, queue.AddRateLimited does not meet the demand
return app, nil
}
newStatus.Phase = applicationv1.AppPhaseUpgradFailed
newStatus.Message = "fetch chart failed"
newStatus.Reason = err.Error()
newStatus.LastTransitionTime = metav1.Now()
updateStatusFunc(ctx, app, &app.Status, newStatus)
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
_, updateStatusErr := updateStatusFunc(ctx, newApp, &newApp.Status, newStatus)
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(newApp.Spec.TargetCluster, newApp.Name).Set(1)
if updateStatusErr != nil {
return newApp, updateStatusErr
}
}
return nil, err
}

newApp, err := applicationClient.Apps(app.Namespace).Get(ctx, app.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

values, err := helmutil.MergeValues(app.Spec.Values.Values, app.Spec.Values.RawValues, string(app.Spec.Values.RawValuesType))
if err != nil {
return nil, err
Expand All @@ -103,12 +97,6 @@ func Upgrade(ctx context.Context,
newStatus := newApp.Status.DeepCopy()
var updateStatusErr error
if err != nil {
if app.Status.Phase == applicationv1.AppPhaseUpgradFailed {
log.Error(fmt.Sprintf("upgrade app failed, helm upgrade err: %s", err.Error()))
metrics.GaugeApplicationUpgradeFailed.WithLabelValues(app.Spec.TargetCluster, app.Name).Set(1)
// delayed retry, queue.AddRateLimited does not meet the demand
return app, nil
}
newStatus.Phase = applicationv1.AppPhaseUpgradFailed
newStatus.Message = "upgrade app failed"
newStatus.Reason = err.Error()
Expand Down
1 change: 1 addition & 0 deletions pkg/application/helm/action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (c *Client) InstallWithLocal(options *InstallOptions, chartLocalFile string
client.ReleaseName = options.ReleaseName
client.Description = options.Description
client.IsUpgrade = options.IsUpgrade
client.Atomic = true

options.ChartPathOptions.ApplyTo(&client.ChartPathOptions)

Expand Down