Skip to content

Commit

Permalink
Merge pull request #17497 from juanvallejo/jvallejo/calc-patches-usin…
Browse files Browse the repository at this point in the history
…g-input-version

Automatic merge from submit-queue.

calculate patches using input version

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1518325

Wrap an encoder to first convert to the same version used to read the
object (based on the mapping's GroupVersion)

cc @openshift/cli-review @liggitt
  • Loading branch information
openshift-merge-robot authored Nov 30, 2017
2 parents 354df72 + 8b074a8 commit a4e491d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/oc/cli/cmd/set/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ func CalculatePatches(infos []*resource.Info, encoder runtime.Encoder, mutateFn
var patches []*Patch
for _, info := range infos {
patch := &Patch{Info: info}
patch.Before, patch.Err = runtime.Encode(encoder, info.Object)

versionedEncoder := kapi.Codecs.EncoderForVersion(encoder, patch.Info.Mapping.GroupVersionKind.GroupVersion())
patch.Before, patch.Err = runtime.Encode(versionedEncoder, info.Object)

ok, err := mutateFn(info)
if !ok {
Expand All @@ -155,7 +157,7 @@ func CalculatePatches(infos []*resource.Info, encoder runtime.Encoder, mutateFn
continue
}

patch.After, patch.Err = runtime.Encode(encoder, info.Object)
patch.After, patch.Err = runtime.Encode(versionedEncoder, info.Object)
if patch.Err != nil {
continue
}
Expand Down
6 changes: 6 additions & 0 deletions test/cmd/volumes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ os::test::junit::declare_suite_start "cmd/volumes"
# This test validates the 'volume' command

os::cmd::expect_success 'oc create -f test/integration/testdata/test-deployment-config.yaml'
os::cmd::expect_success 'oc create -f test/testdata/rollingupdate-daemonset.yaml'

os::cmd::expect_success_and_text 'oc volume dc/test-deployment-config --list' 'vol1'
os::cmd::expect_success 'oc volume dc/test-deployment-config --add --name=vol0 -m /opt5'
Expand All @@ -36,6 +37,11 @@ os::cmd::expect_success_and_not_text 'oc set volume dc/test-deployment-config --
os::cmd::expect_success 'oc set volume dc/test-deployment-config --remove --confirm'
os::cmd::expect_success_and_not_text 'oc set volume dc/test-deployment-config --list' 'vol1'

# ensure that resources not present in all versions of a target group
# are still able to be encoded and patched accordingly
os::cmd::expect_success 'oc set volume ds/bind --add --name=vol2 --type=emptydir -m /opt'
os::cmd::expect_success 'oc set volume ds/bind --remove --name=vol2'

os::cmd::expect_success "oc volume dc/test-deployment-config --add -t 'secret' --secret-name='asdf' --default-mode '765'"
os::cmd::expect_success_and_text 'oc get dc/test-deployment-config -o jsonpath={.spec.template.spec.volumes[0]}' '501'
os::cmd::expect_success 'oc set volume dc/test-deployment-config --remove --confirm'
Expand Down
27 changes: 27 additions & 0 deletions test/testdata/rollingupdate-daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: bind
spec:
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 10%
template:
metadata:
labels:
service: bind
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "service"
operator: "In"
values: ["bind"]
topologyKey: "kubernetes.io/hostname"
namespaces: []
containers:
- name: kubernetes-pause
image: gcr.io/google-containers/pause:2.0

0 comments on commit a4e491d

Please sign in to comment.