Skip to content

Commit

Permalink
fix: retain pod spec volume when its name has default token prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
wy-lucky committed Mar 25, 2024
1 parent 214e71b commit 284939f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pkg/controllers/sync/dispatch/retain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 284939f

Please sign in to comment.