Skip to content

Commit 870d3ba

Browse files
committed
Revert "feat: retry with client side dry run if server one was failed (argoproj#548)"
This reverts commit c0c2dd1. Signed-off-by: Anand Francis Joseph <[email protected]>
1 parent aba3819 commit 870d3ba

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

pkg/sync/sync_context.go

+20-30
Original file line numberDiff line numberDiff line change
@@ -921,39 +921,29 @@ func (sc *syncContext) applyObject(t *syncTask, dryRun, force, validate bool) (c
921921
var err error
922922
var message string
923923
shouldReplace := sc.replace || resourceutil.HasAnnotationOption(t.targetObj, common.AnnotationSyncOptions, common.SyncOptionReplace)
924-
applyFn := func(dryRunStrategy cmdutil.DryRunStrategy) (string, error) {
925-
if !shouldReplace {
926-
return sc.resourceOps.ApplyResource(context.TODO(), t.targetObj, dryRunStrategy, force, validate, serverSideApply, sc.serverSideApplyManager, false)
927-
}
928-
if t.liveObj == nil {
929-
return sc.resourceOps.CreateResource(context.TODO(), t.targetObj, dryRunStrategy, validate)
930-
}
931-
// Avoid using `kubectl replace` for CRDs since 'replace' might recreate resource and so delete all CRD instances.
932-
// The same thing applies for namespaces, which would delete the namespace as well as everything within it,
933-
// so we want to avoid using `kubectl replace` in that case as well.
934-
if kube.IsCRD(t.targetObj) || t.targetObj.GetKind() == kubeutil.NamespaceKind {
935-
update := t.targetObj.DeepCopy()
936-
update.SetResourceVersion(t.liveObj.GetResourceVersion())
937-
_, err = sc.resourceOps.UpdateResource(context.TODO(), update, dryRunStrategy)
938-
if err != nil {
939-
return fmt.Sprintf("error when updating: %v", err.Error()), err
924+
if shouldReplace {
925+
if t.liveObj != nil {
926+
// Avoid using `kubectl replace` for CRDs since 'replace' might recreate resource and so delete all CRD instances.
927+
// The same thing applies for namespaces, which would delete the namespace as well as everything within it,
928+
// so we want to avoid using `kubectl replace` in that case as well.
929+
if kube.IsCRD(t.targetObj) || t.targetObj.GetKind() == kubeutil.NamespaceKind {
930+
update := t.targetObj.DeepCopy()
931+
update.SetResourceVersion(t.liveObj.GetResourceVersion())
932+
_, err = sc.resourceOps.UpdateResource(context.TODO(), update, dryRunStrategy)
933+
if err == nil {
934+
message = fmt.Sprintf("%s/%s updated", t.targetObj.GetKind(), t.targetObj.GetName())
935+
} else {
936+
message = fmt.Sprintf("error when updating: %v", err.Error())
937+
}
938+
} else {
939+
message, err = sc.resourceOps.ReplaceResource(context.TODO(), t.targetObj, dryRunStrategy, force)
940940
}
941-
return fmt.Sprintf("%s/%s updated", t.targetObj.GetKind(), t.targetObj.GetName()), nil
942-
941+
} else {
942+
message, err = sc.resourceOps.CreateResource(context.TODO(), t.targetObj, dryRunStrategy, validate)
943943
}
944-
return sc.resourceOps.ReplaceResource(context.TODO(), t.targetObj, dryRunStrategy, force)
945-
}
946-
947-
message, err = applyFn(dryRunStrategy)
948-
949-
// DryRunServer fails with "Kind does not support fieldValidation" error for kubernetes server < 1.25
950-
// it fails inside apply.go , o.DryRunVerifier.HasSupport(info.Mapping.GroupVersionKind) line
951-
// so we retry with DryRunClient that works for all cases, but cause issues with hooks
952-
// Details: https://github.com/argoproj/argo-cd/issues/16177
953-
if dryRunStrategy == cmdutil.DryRunServer && err != nil {
954-
message, err = applyFn(cmdutil.DryRunClient)
944+
} else {
945+
message, err = sc.resourceOps.ApplyResource(context.TODO(), t.targetObj, dryRunStrategy, force, validate, serverSideApply, sc.serverSideApplyManager, false)
955946
}
956-
957947
if err != nil {
958948
return common.ResultCodeSyncFailed, err.Error()
959949
}

0 commit comments

Comments
 (0)