From 5693012131dbf7a2e4a1d8c8be4351b64a3833ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=AF=93?= Date: Fri, 22 Mar 2024 10:27:58 +0800 Subject: [PATCH] fix: retain pod spec volume when its name has default token prefix --- pkg/controllers/sync/dispatch/retain.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pkg/controllers/sync/dispatch/retain.go b/pkg/controllers/sync/dispatch/retain.go index 5bc07faf..ff24d277 100644 --- a/pkg/controllers/sync/dispatch/retain.go +++ b/pkg/controllers/sync/dispatch/retain.go @@ -301,6 +301,10 @@ func retainPodFields(desiredObj, clusterObj *unstructured.Unstructured) error { return err } + if err := copyUnstructuredField(clusterObj, desiredObj, "spec", "volumes"); err != nil { + return err + } + // The following fields are fields that can be explicitly set by the user, but are defaulted by the Kubernetes // control plane (after creation) if left unset. For these fields, we retain the defaulted values in clusterObj if // the field was not explicitly set in desiredObj. Otherwise, we respect the user's choice. @@ -339,13 +343,6 @@ func retainPodFields(desiredObj, clusterObj *unstructured.Unstructured) error { } } - if volumes, exists, err := unstructured.NestedFieldNoCopy(desiredObj.Object, "spec", "volumes"); err == nil && - (!exists || volumes == nil) { - if err := copyUnstructuredField(clusterObj, desiredObj, "spec", "volumes"); err != nil { - return err - } - } - desiredContainers, _, _ := unstructured.NestedSlice(desiredObj.Object, "spec", "containers") // this is a deepcopy clusterContainers, _, _ := unstructured.NestedSlice(clusterObj.Object, "spec", "containers") // this is a deepcopy if err := retainContainers(desiredContainers, clusterContainers); err != nil {