Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 15 additions & 2 deletions pkg/app/piped/planner/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu
manifestCache.Put(in.MostRecentSuccessfulCommitHash, oldManifests)
}

progressive, desc := decideStrategy(oldManifests, newManifests, cfg.Workloads, in.Logger)
pipelineDefined := cfg.Pipeline != nil && len(cfg.Pipeline.Stages) > 0
progressive, desc := decideStrategy(oldManifests, newManifests, cfg.Workloads, pipelineDefined, in.Logger)
out.Summary = desc

if progressive {
Expand All @@ -230,14 +231,26 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu

// First up, checks to see if the workload's `spec.template` has been changed,
// and then checks if the configmap/secret's data.
func decideStrategy(olds, news []provider.Manifest, workloadRefs []config.K8sResourceReference, logger *zap.Logger) (progressive bool, desc string) {
// pipelineDefined should be true when the user has explicitly configured a pipeline
// in the application config, which forces progressive sync even when no workloads exist.
func decideStrategy(olds, news []provider.Manifest, workloadRefs []config.K8sResourceReference, pipelineDefined bool, logger *zap.Logger) (progressive bool, desc string) {
oldWorkloads := findWorkloadManifests(olds, workloadRefs)
if len(oldWorkloads) == 0 {
if pipelineDefined {
progressive = true
desc = "Sync progressively because pipeline is defined in the application config"
return
}
desc = "Quick sync by applying all manifests because it was unable to find the currently running workloads"
return
}
newWorkloads := findWorkloadManifests(news, workloadRefs)
if len(newWorkloads) == 0 {
if pipelineDefined {
progressive = true
desc = "Sync progressively because pipeline is defined in the application config"
return
}
desc = "Quick sync by applying all manifests because it was unable to find workloads in the new manifests"
return
}
Expand Down
62 changes: 61 additions & 1 deletion pkg/app/piped/planner/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,67 @@ func TestDecideStrategy(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
gotProgressive, gotDesc := decideStrategy(tc.olds, tc.news, tc.workloadRefs, zap.NewNop())
gotProgressive, gotDesc := decideStrategy(tc.olds, tc.news, tc.workloadRefs, false, zap.NewNop())
assert.Equal(t, tc.wantProgressive, gotProgressive)
assert.Equal(t, tc.wantDesc, gotDesc)
})
}
}

func TestDecideStrategyWithPipelineDefined(t *testing.T) {
t.Parallel()

configMapManifest := func(name, data string) provider.Manifest {
return provider.MakeManifest(provider.ResourceKey{
APIVersion: "v1",
Kind: provider.KindConfigMap,
Name: name,
}, &unstructured.Unstructured{
Object: map[string]interface{}{"data": data}},
)
}

tests := []struct {
name string
olds []provider.Manifest
news []provider.Manifest
pipelineDefined bool
wantProgressive bool
wantDesc string
}{
{
// Regression test for: https://github.com/pipe-cd/pipecd/issues/4799
// ConfigMap-only app (no Deployment) with pipeline defined in app.pipecd.yaml
// must use progressive sync, not QUICK_SYNC.
name: "configmap-only app with pipeline defined should be progressive",
olds: []provider.Manifest{
configMapManifest("my-config", "old-value"),
},
news: []provider.Manifest{
configMapManifest("my-config", "new-value"),
},
pipelineDefined: true,
wantProgressive: true,
wantDesc: "Sync progressively because pipeline is defined in the application config",
},
{
// Without a pipeline defined, ConfigMap-only app must still use QUICK_SYNC
// (no regression in the default/non-pipeline path).
name: "configmap-only app without pipeline defined should be quick sync",
olds: []provider.Manifest{
configMapManifest("my-config", "old-value"),
},
news: []provider.Manifest{
configMapManifest("my-config", "new-value"),
},
pipelineDefined: false,
wantProgressive: false,
wantDesc: "Quick sync by applying all manifests because it was unable to find the currently running workloads",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
gotProgressive, gotDesc := decideStrategy(tc.olds, tc.news, nil, tc.pipelineDefined, zap.NewNop())
assert.Equal(t, tc.wantProgressive, gotProgressive)
assert.Equal(t, tc.wantDesc, gotDesc)
})
Expand Down
Loading