Skip to content

Commit 8697b44

Browse files
Revert "Add option to skip the dryrun from the sync context (#708)" (#730)
* Revert "Add option to skip the dryrun from the sync context (#708)" This reverts commit 717b8bf. Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> * format Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> --------- Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
1 parent 69dfa70 commit 8697b44

File tree

6 files changed

+5
-55
lines changed

6 files changed

+5
-55
lines changed

pkg/sync/common/types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const (
2020

2121
// Sync option that disables dry run in resource is missing in the cluster
2222
SyncOptionSkipDryRunOnMissingResource = "SkipDryRunOnMissingResource=true"
23-
// Sync option that disables dry run for applying resources
24-
SyncOptionSkipDryRun = "SkipDryRun=true"
2523
// Sync option that disables resource pruning
2624
SyncOptionDisablePrune = "Prune=false"
2725
// Sync option that disables resource validation

pkg/sync/doc.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ that runs before all other resources. The `argocd.argoproj.io/sync-wave` annotat
8080
The sync options allows customizing the synchronization of selected resources. The options are specified using the
8181
annotation 'argocd.argoproj.io/sync-options'. Following sync options are supported:
8282
83-
- SkipDryRunOnMissingResource=true - disables dry run if CRD resource is missing in the cluster
84-
- SkipDryRun=true - disables dry run if resource is missing in the cluster
83+
- SkipDryRunOnMissingResource=true - disables dry run in resource is missing in the cluster
8584
- Prune=false - disables resource pruning
8685
- Validate=false - disables resource validation (equivalent to 'kubectl apply --validate=false')
8786

pkg/sync/sync_context.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@ func WithReplace(replace bool) SyncOpt {
188188
}
189189
}
190190

191-
func WithSkipDryRun(skipDryRun bool) SyncOpt {
192-
return func(ctx *syncContext) {
193-
ctx.skipDryRun = skipDryRun
194-
}
195-
}
196-
197191
func WithSkipDryRunOnMissingResource(skipDryRunOnMissingResource bool) SyncOpt {
198192
return func(ctx *syncContext) {
199193
ctx.skipDryRunOnMissingResource = skipDryRunOnMissingResource
@@ -361,7 +355,6 @@ type syncContext struct {
361355
namespace string
362356

363357
dryRun bool
364-
skipDryRun bool
365358
skipDryRunOnMissingResource bool
366359
force bool
367360
validate bool
@@ -867,13 +860,6 @@ func (sc *syncContext) getSyncTasks() (_ syncTasks, successful bool) {
867860
// to be created during app synchronization.
868861
sc.log.WithValues("task", task).V(1).Info("Skip dry-run for custom resource")
869862
task.skipDryRun = true
870-
case sc.skipDryRun:
871-
// Skip dryrun for task if the sync context is in skip dryrun mode
872-
// This can be useful when resource creation is depending on the creation of other resources
873-
// like namespaces that need to be created first before the resources in the namespace can be created
874-
// For CRD's one can also use the SkipDryRunOnMissingResource annotation.
875-
sc.log.WithValues("task", task).V(1).Info("Skipping dry-run for task because skipDryRun is set in the sync context")
876-
task.skipDryRun = true
877863
default:
878864
sc.setResourceResult(task, common.ResultCodeSyncFailed, "", err.Error())
879865
successful = false

pkg/sync/sync_context_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,39 +1198,6 @@ func TestNamespaceAutoCreationForNonExistingNs(t *testing.T) {
11981198
waveOverride: nil,
11991199
}, tasks[0])
12001200
})
1201-
1202-
t.Run("pre-sync task error should be ignored if skip dryrun is true", func(t *testing.T) {
1203-
syncCtx.resources = groupResources(ReconciliationResult{
1204-
Live: []*unstructured.Unstructured{nil},
1205-
Target: []*unstructured.Unstructured{pod},
1206-
})
1207-
1208-
fakeDisco := syncCtx.disco.(*fakedisco.FakeDiscovery)
1209-
fakeDisco.Resources = []*metav1.APIResourceList{}
1210-
syncCtx.disco = fakeDisco
1211-
1212-
syncCtx.skipDryRun = true
1213-
creatorCalled := false
1214-
syncCtx.syncNamespace = func(_, _ *unstructured.Unstructured) (bool, error) {
1215-
creatorCalled = true
1216-
return true, errors.New("some error")
1217-
}
1218-
tasks, successful := syncCtx.getSyncTasks()
1219-
1220-
assert.True(t, creatorCalled)
1221-
assert.True(t, successful)
1222-
assert.Len(t, tasks, 2)
1223-
assert.Equal(t, &syncTask{
1224-
phase: synccommon.SyncPhasePreSync,
1225-
liveObj: nil,
1226-
targetObj: tasks[0].targetObj,
1227-
skipDryRun: true,
1228-
syncStatus: synccommon.ResultCodeSyncFailed,
1229-
operationState: synccommon.OperationError,
1230-
message: "namespaceModifier error: some error",
1231-
waveOverride: nil,
1232-
}, tasks[0])
1233-
})
12341201
}
12351202

12361203
func createNamespaceTask(namespace string) (*syncTask, error) {

pkg/utils/kube/kubetest/mock_resource_operations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (r *MockResourceOps) GetLastResourceCommand(key kube.ResourceKey) string {
106106
return r.lastCommandPerResource[key]
107107
}
108108

109-
func (r *MockResourceOps) ApplyResource(_ context.Context, obj *unstructured.Unstructured, _ cmdutil.DryRunStrategy, force bool, validate bool, serverSideApply bool, manager string) (string, error) {
109+
func (r *MockResourceOps) ApplyResource(_ context.Context, obj *unstructured.Unstructured, _ cmdutil.DryRunStrategy, force, validate, serverSideApply bool, manager string) (string, error) {
110110
r.SetLastValidate(validate)
111111
r.SetLastServerSideApply(serverSideApply)
112112
r.SetLastServerSideApplyManager(manager)

pkg/utils/kube/resource_ops.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939

4040
// ResourceOperations provides methods to manage k8s resources
4141
type ResourceOperations interface {
42-
ApplyResource(ctx context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy, force bool, validate bool, serverSideApply bool, manager string) (string, error)
42+
ApplyResource(ctx context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy, force, validate, serverSideApply bool, manager string) (string, error)
4343
ReplaceResource(ctx context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy, force bool) (string, error)
4444
CreateResource(ctx context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy, validate bool) (string, error)
4545
UpdateResource(ctx context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy) (*unstructured.Unstructured, error)
@@ -302,7 +302,7 @@ func (k *kubectlResourceOperations) UpdateResource(ctx context.Context, obj *uns
302302
}
303303

304304
// ApplyResource performs an apply of a unstructured resource
305-
func (k *kubectlServerSideDiffDryRunApplier) ApplyResource(_ context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy, force bool, validate bool, serverSideApply bool, manager string) (string, error) {
305+
func (k *kubectlServerSideDiffDryRunApplier) ApplyResource(_ context.Context, obj *unstructured.Unstructured, dryRunStrategy cmdutil.DryRunStrategy, force, validate, serverSideApply bool, manager string) (string, error) {
306306
span := k.tracer.StartSpan("ApplyResource")
307307
span.SetBaggageItem("kind", obj.GetKind())
308308
span.SetBaggageItem("name", obj.GetName())
@@ -358,7 +358,7 @@ func (k *kubectlResourceOperations) ApplyResource(ctx context.Context, obj *unst
358358
})
359359
}
360360

361-
func newApplyOptionsCommon(config *rest.Config, fact cmdutil.Factory, ioStreams genericclioptions.IOStreams, obj *unstructured.Unstructured, fileName string, validate bool, force bool, serverSideApply bool, dryRunStrategy cmdutil.DryRunStrategy, manager string) (*apply.ApplyOptions, error) {
361+
func newApplyOptionsCommon(config *rest.Config, fact cmdutil.Factory, ioStreams genericclioptions.IOStreams, obj *unstructured.Unstructured, fileName string, validate bool, force, serverSideApply bool, dryRunStrategy cmdutil.DryRunStrategy, manager string) (*apply.ApplyOptions, error) {
362362
flags := apply.NewApplyFlags(ioStreams)
363363
o := &apply.ApplyOptions{
364364
IOStreams: ioStreams,

0 commit comments

Comments
 (0)