Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pkg/action/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ func runFailurePlan(ctx context.Context, releaseNamespace string, failedPlan *pl
log.Default.Debug(ctx, "Execute failure plan")

if err := plan.ExecutePlan(ctx, releaseNamespace, failurePlan, taskStore, logStore, informerFactory, history, clientFactory, plan.ExecutePlanOptions{
LegacyProgressReporter: opts.LegacyProgressReporter,
TrackingOptions: opts.TrackingOptions,
NetworkParallelism: opts.NetworkParallelism,
LegacyProgressReporter: opts.LegacyProgressReporter,
TrackingOptions: opts.TrackingOptions,
NetworkParallelism: opts.NetworkParallelism,
InstallableResourceInfos: installableInfos,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full original installableInfos is passed into the failure plan, so every install resource still present in the cluster is re-emitted as NoOp/Completed in a stage where it is not an operation of that plan. This diverges from the StageReport doc contract ("ALL operations in the plan"). If this is intended (giving the consumer the full picture), consider clarifying the StageReport doc comment to mention these NoOp pseudo-operations.
(generated by pi-pi)

}); err != nil {
critErrs.Add(fmt.Errorf("execute failure plan: %w", err))
}
Expand Down
25 changes: 19 additions & 6 deletions pkg/action/release_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ func releaseInstall(ctx context.Context, ctxCancelFn context.CancelCauseFunc, re
printNotes(ctx, newRelease.Info.Notes)
}

if opts.LegacyProgressReportCh != nil {
reporter := plan.NewLegacyProgressReporter(opts.LegacyProgressReportCh)
reporter.StartStage(installPlan, releaseNamespace, instResInfos, clientFactory.Mapper())
reporter.Stop(ctx)
close(opts.LegacyProgressReportCh)
}

log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render(fmt.Sprintf("Skipped release %q (namespace: %q): cluster resources already as desired", releaseName, releaseNamespace)))

return nil
Expand Down Expand Up @@ -588,9 +595,10 @@ func releaseInstall(ctx context.Context, ctxCancelFn context.CancelCauseFunc, re
log.Default.Debug(ctx, "Execute release install plan")

executePlanErr := plan.ExecutePlan(ctx, releaseNamespace, installPlan, taskStore, logStore, informerFactory, history, clientFactory, plan.ExecutePlanOptions{
LegacyProgressReporter: reporter,
TrackingOptions: opts.TrackingOptions,
NetworkParallelism: opts.NetworkParallelism,
LegacyProgressReporter: reporter,
TrackingOptions: opts.TrackingOptions,
NetworkParallelism: opts.NetworkParallelism,
InstallableResourceInfos: instResInfos,
})
if executePlanErr != nil {
criticalErrs.Add(fmt.Errorf("execute release install plan: %w", executePlanErr))
Expand Down Expand Up @@ -967,6 +975,10 @@ func runRollbackPlan(ctx context.Context, releaseName, releaseNamespace string,
})

if releaseIsUpToDate && planIsUseless {
if opts.LegacyProgressReporter != nil {
opts.LegacyProgressReporter.StartStage(rollbackPlan, releaseNamespace, instResInfos, clientFactory.Mapper())
}

log.Default.Info(ctx, color.Style{color.Bold, color.Green}.Render("Skipped rollback release")+" %q (namespace: %q): cluster resources already as desired", releaseName, releaseNamespace)

return &runRollbackPlanResult{}, nonCritErrs, critErrs
Expand All @@ -975,9 +987,10 @@ func runRollbackPlan(ctx context.Context, releaseName, releaseNamespace string,
log.Default.Debug(ctx, "Execute rollback plan")

executePlanErr := plan.ExecutePlan(ctx, releaseNamespace, rollbackPlan, taskStore, logStore, informerFactory, history, clientFactory, plan.ExecutePlanOptions{
LegacyProgressReporter: opts.LegacyProgressReporter,
TrackingOptions: opts.TrackingOptions,
NetworkParallelism: opts.NetworkParallelism,
LegacyProgressReporter: opts.LegacyProgressReporter,
TrackingOptions: opts.TrackingOptions,
NetworkParallelism: opts.NetworkParallelism,
InstallableResourceInfos: instResInfos,
})
if executePlanErr != nil {
critErrs.Add(fmt.Errorf("execute rollback plan: %w", executePlanErr))
Expand Down
5 changes: 3 additions & 2 deletions pkg/action/release_rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,9 @@ func releaseRollback(ctx context.Context, ctxCancelFn context.CancelCauseFunc, r
log.Default.Debug(ctx, "Execute release install plan")

executePlanErr := plan.ExecutePlan(ctx, releaseNamespace, installPlan, taskStore, logStore, informerFactory, history, clientFactory, plan.ExecutePlanOptions{
TrackingOptions: opts.TrackingOptions,
NetworkParallelism: opts.NetworkParallelism,
TrackingOptions: opts.TrackingOptions,
NetworkParallelism: opts.NetworkParallelism,
InstallableResourceInfos: instResInfos,
})
if executePlanErr != nil {
criticalErrs.Add(fmt.Errorf("execute release install plan: %w", executePlanErr))
Expand Down
1 change: 1 addition & 0 deletions pkg/legacy/progrep/progress_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
OperationTypeDelete OperationType = "Delete"
OperationTypeApply OperationType = "Apply"
OperationTypeRecreate OperationType = "Recreate"
OperationTypeNoOp OperationType = "NoOp"
Comment thread
dmmordvi marked this conversation as resolved.
OperationTypeTrackReadiness OperationType = "TrackReadiness"
OperationTypeTrackPresence OperationType = "TrackPresence"
OperationTypeTrackAbsence OperationType = "TrackAbsence"
Expand Down
43 changes: 42 additions & 1 deletion pkg/plan/legacy_progress_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/samber/lo"
"k8s.io/apimachinery/pkg/api/meta"

kdutil "github.com/werf/kubedog/pkg/trackers/dyntracker/util"
"github.com/werf/nelm/pkg/legacy/progrep"
Expand Down Expand Up @@ -42,6 +43,17 @@ func (r *LegacyProgressReporter) ReportStatus(opID string, status progrep.Operat
})
}

func (r *LegacyProgressReporter) StartStage(p *Plan, releaseNamespace string, installableResourceInfos []*InstallableResourceInfo, mapper meta.RESTMapper) {
resolvedNamespaces := buildResolvedNamespaces(p, releaseNamespace, mapper)

untouchedResolvedNamespaces := make(map[string]string, len(installableResourceInfos))
for _, info := range installableResourceInfos {
untouchedResolvedNamespaces[info.ID()] = resolveNamespace(info.GroupVersionKind, info.Namespace, releaseNamespace, mapper)
}

r.startStage(p, resolvedNamespaces, installableResourceInfos, untouchedResolvedNamespaces)
}

func (r *LegacyProgressReporter) Stop(ctx context.Context) {
var report progrep.ProgressReport

Expand All @@ -59,7 +71,7 @@ func (r *LegacyProgressReporter) Stop(ctx context.Context) {
}()
}

func (r *LegacyProgressReporter) startStage(p *Plan, resolvedNamespaces map[string]string) {
func (r *LegacyProgressReporter) startStage(p *Plan, resolvedNamespaces map[string]string, untouched []*InstallableResourceInfo, untouchedResolvedNamespaces map[string]string) {
r.state.RWTransaction(func(s *progressReporterState) {
if len(s.ops) > 0 {
s.frozen = append(s.frozen, buildStageReport(s.ops))
Expand All @@ -71,6 +83,7 @@ func (r *LegacyProgressReporter) startStage(p *Plan, resolvedNamespaces map[stri
var entries []opEntry

entryIndex := make(map[string]int)
seenRefs := make(map[progrep.ObjectRef]struct{})

for _, op := range ops {
if op.Category != OperationCategoryResource && op.Category != OperationCategoryTrack {
Expand All @@ -81,6 +94,7 @@ func (r *LegacyProgressReporter) startStage(p *Plan, resolvedNamespaces map[stri
typ := mapOperationType(op.Type)
idx := len(entries)
entryIndex[op.ID()] = idx
seenRefs[ref] = struct{}{}

entries = append(entries, opEntry{
iteration: int(op.Iteration),
Expand All @@ -90,6 +104,33 @@ func (r *LegacyProgressReporter) startStage(p *Plan, resolvedNamespaces map[stri
})
}

for _, info := range untouched {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A resource with real drift can reach this NoOp/Completed branch. resourceInstallType() returns ResourceInstallTypeNone not only when the live and dry-apply states match, but also when a resource policy (skip-update / skip-create / skip-recreate) forces None despite an actual diff (skippedByPolicy=true). Such a resource produces no plan operation (and mustTrackReadiness is false), so it flows into this loop and is reported as NoOp/Completed. That reads as "unchanged" to the user even though the resource actually differs from the desired state and was only skipped by policy. This is display-only in the legacy progress reporter (deploy behavior is unaffected), but the label is misleading; consider distinguishing "skipped by policy" from "unchanged".
(generated by pi-pi)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return NoOp type, so it is enough

if info.GetResult == nil {
continue
}

ref := progrep.ObjectRef{
GroupVersionKind: info.GroupVersionKind,
Name: info.Name,
Namespace: untouchedResolvedNamespaces[info.ID()],
}

if _, ok := seenRefs[ref]; ok {
continue
}

seenRefs[ref] = struct{}{}

entries = append(entries, opEntry{
iteration: 0,
ref: ref,
status: progrep.OperationStatusCompleted,
// Untouched resources have no real operation; NoOp is a
// neutral label for an already-present, unchanged resource shown as Completed.
typ: progrep.OperationTypeNoOp,
})
}

for _, op := range ops {
idx, ok := entryIndex[op.ID()]
if !ok {
Expand Down
Loading