Skip to content

Commit 123fa58

Browse files
committed
pkg/cli/admin/upgrade: Use PATCH instead of POST for spec updates
ClusterVersion's spec can evolve over time, growing additional properties like capabilities [1]. With the old POST/Update(...) approach, that could lead to older oc (who didn't know about the new properties) naively clearing them when they washed the in-cluster resource through their local ClusterVersion Go type. With this commit, we transition to PATCH, so we can touch just spec.desiredUpdate, regardless of what else is going on in spec. [1]: openshift/api@5b82635
1 parent 27c7bdb commit 123fa58

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/cli/admin/upgrade/upgrade.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package upgrade
33
import (
44
"bytes"
55
"context"
6+
"encoding/json"
67
"errors"
78
"fmt"
89
"io"
@@ -321,10 +322,12 @@ func (o *Options) Run() error {
321322
fmt.Fprintf(o.ErrOut, "warning: --allow-upgrade-with-warnings is bypassing: %s", err)
322323
}
323324

324-
cv.Spec.DesiredUpdate = update
325-
326-
_, err := o.Client.ConfigV1().ClusterVersions().Update(context.TODO(), cv, metav1.UpdateOptions{})
325+
updateJSON, err := json.Marshal(update)
327326
if err != nil {
327+
return fmt.Errorf("marshal ClusterVersion patch: %v", err)
328+
}
329+
patch := []byte(fmt.Sprintf(`{"spec":{"desiredUpdate": %s}}`, updateJSON))
330+
if _, err := o.Client.ConfigV1().ClusterVersions().Patch(context.TODO(), cv.Name, types.MergePatchType, patch, metav1.PatchOptions{}); err != nil {
328331
return fmt.Errorf("Unable to upgrade: %v", err)
329332
}
330333

0 commit comments

Comments
 (0)