Skip to content

Commit

Permalink
rollback log changes in helm
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksontong committed Jul 29, 2024
1 parent e8ea3ba commit 6bfa319
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pkg/application/helm/action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ func (c *Client) InstallWithLocal(ctx context.Context, options *InstallOptions,
for _, rel := range rels {
if rel.Info.Status == release.StatusDeployed {
// release 记录已存在,状态为deployed,不再进行重复安装
log.Infof("Release %s for %s is already exist. igonre it now.", options.ReleaseName, options.Namespace)
log.Infof("Release %s is already exist. igonre it now.", options.ReleaseName)
return nil, nil
}
// release 记录已存在,状态为其他,删除重试
log.Infof("install release %s for %s is already exist, status is %s. delete it now.", options.ReleaseName, options.Namespace, rel.Info.Status)
log.Infof("install release %s is already exist, status is %s. delete it now.", options.ReleaseName, rel.Info.Status)
actionConfig.Releases.Delete(rel.Name, rel.Version)
}
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func (c *Client) InstallWithLocal(ctx context.Context, options *InstallOptions,
}

if chartRequested.Metadata.Deprecated {
log.Warnf("This chart %s/%s for %s is deprecated", options.ChartRepo, options.Chart, options.Namespace)
log.Warnf("This chart %s/%s is deprecated", options.ChartRepo, options.Chart)
}

if req := chartRequested.Metadata.Dependencies; req != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/application/helm/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *Client) Upgrade(ctx context.Context, options *UpgradeOptions) (*release
histClient.Max = 1
rels, err := histClient.Run(options.ReleaseName)
if errors.Is(err, driver.ErrReleaseNotFound) {
log.Infof("Release %d for %s does not exist. Installing it now.", options.ReleaseName, options.Namespace)
log.Infof("Release %s does not exist. Installing it now.", options.ReleaseName)
return c.Install(ctx, &InstallOptions{
DryRun: options.DryRun,
DependencyUpdate: options.DependencyUpdate,
Expand All @@ -100,7 +100,7 @@ func (c *Client) Upgrade(ctx context.Context, options *UpgradeOptions) (*release
for _, rel := range rels {
if rel.Info.Status == release.StatusPendingInstall || rel.Info.Status == release.StatusPendingUpgrade || rel.Info.Status == release.StatusPendingRollback {
// if release is pending, delete it.
log.Infof("upgrade release %s for %s is already exist, status is %s. delete it now.", options.ReleaseName, options.Namespace, rel.Info.Status)
log.Infof("upgrade release %s is already exist, status is %s. delete it now.", options.ReleaseName, rel.Info.Status)
actionConfig.Releases.Delete(rel.Name, rel.Version)
}
}
Expand Down Expand Up @@ -171,27 +171,27 @@ func (c *Client) Upgrade(ctx context.Context, options *UpgradeOptions) (*release
}

if chartRequested.Metadata.Deprecated {
log.Warnf("This chart %s/%s for %s is deprecated", options.ChartRepo, options.Chart, options.Namespace)
log.Warnf("This chart %s/%s is deprecated", options.ChartRepo, options.Chart)
}
rel, err := client.RunWithContext(ctx, options.ReleaseName, chartRequested, options.Values)
// if current release resource is deprecated, delete it.
if err != nil {
log.Infof("upgrade %s for %s RunWithContext failed,err:%s.", options.ReleaseName, options.Namespace, err.Error())
log.Infof("upgrade %s RunWithContext failed,err:%s.", options.ReleaseName, err.Error())
}
if err != nil && strings.Contains(err.Error(), "unable to build kubernetes objects from current release manifest") {
histClient := action.NewHistory(actionConfig)
histClient.Max = 1
rels, err := histClient.Run(options.ReleaseName)
if err != nil {
log.Infof("upgrade get release %s history for %s failed. err:%s.", options.ReleaseName, options.Namespace, err.Error())
log.Infof("upgrade get release %s history failed. err:%s.", options.ReleaseName, err.Error())
return nil, err
}
if len(rels) == 0 {
return nil, errors.Errorf("no revision for release %q", options.ReleaseName)
}
for _, rel := range rels {
// if release is deprecated, delete it.
log.Infof("upgrade release %s resource for %s is deprecated. delete it now. rel name:%s, rel version:%d.", options.ReleaseName, options.Namespace, rel.Name, rel.Version)
log.Infof("upgrade release %s resource is deprecated. delete it now. rel name:%s, rel version:%d.", options.ReleaseName, rel.Name, rel.Version)
actionConfig.Releases.Delete(rel.Name, rel.Version)
}
}
Expand Down

0 comments on commit 6bfa319

Please sign in to comment.