mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Calculate patches for commands using input version
This commit is contained in:
parent
e51752239c
commit
e3a8b5e223
@ -2985,6 +2985,16 @@ run_rs_tests() {
|
||||
# Cleanup services
|
||||
kubectl delete service frontend{,-2} "${kube_flags[@]}"
|
||||
|
||||
# Test set commands
|
||||
# Pre-condition: frontend replica set exists at generation 1
|
||||
kube::test::get_object_assert 'rs frontend' "{{${generation_field}}}" '1'
|
||||
kubectl set image rs/frontend "${kube_flags[@]}" *=gcr.io/google-containers/pause:test-cmd
|
||||
kube::test::get_object_assert 'rs frontend' "{{${generation_field}}}" '2'
|
||||
kubectl set env rs/frontend "${kube_flags[@]}" foo=bar
|
||||
kube::test::get_object_assert 'rs frontend' "{{${generation_field}}}" '3'
|
||||
kubectl set resources rs/frontend "${kube_flags[@]}" --limits=cpu=200m,memory=512Mi
|
||||
kube::test::get_object_assert 'rs frontend' "{{${generation_field}}}" '4'
|
||||
|
||||
### Delete replica set with id
|
||||
# Pre-condition: frontend replica set exists
|
||||
kube::test::get_object_assert rs "{{range.items}}{{$id_field}}:{{end}}" 'frontend:'
|
||||
@ -3064,6 +3074,14 @@ run_daemonset_tests() {
|
||||
kubectl apply -f hack/testdata/rollingupdate-daemonset.yaml "${kube_flags[@]}"
|
||||
# Template Generation should stay 1
|
||||
kube::test::get_object_assert 'daemonsets bind' "{{${template_generation_field}}}" '1'
|
||||
# Test set commands
|
||||
kubectl set image daemonsets/bind "${kube_flags[@]}" *=gcr.io/google-containers/pause:test-cmd
|
||||
kube::test::get_object_assert 'daemonsets bind' "{{${template_generation_field}}}" '2'
|
||||
kubectl set env daemonsets/bind "${kube_flags[@]}" foo=bar
|
||||
kube::test::get_object_assert 'daemonsets bind' "{{${template_generation_field}}}" '3'
|
||||
kubectl set resources daemonsets/bind "${kube_flags[@]}" --limits=cpu=200m,memory=512Mi
|
||||
kube::test::get_object_assert 'daemonsets bind' "{{${template_generation_field}}}" '4'
|
||||
|
||||
# Clean up
|
||||
kubectl delete -f hack/testdata/rollingupdate-daemonset.yaml "${kube_flags[@]}"
|
||||
|
||||
@ -4355,6 +4373,7 @@ runTests() {
|
||||
change_cause_annotation='.*kubernetes.io/change-cause.*'
|
||||
pdb_min_available=".spec.minAvailable"
|
||||
pdb_max_unavailable=".spec.maxUnavailable"
|
||||
generation_field=".metadata.generation"
|
||||
template_generation_field=".spec.templateGeneration"
|
||||
container_len="(len .spec.template.spec.containers)"
|
||||
image_field0="(index .spec.template.spec.containers 0).image"
|
||||
|
@ -126,7 +126,9 @@ type patchFn func(*resource.Info) ([]byte, error)
|
||||
// the changes in the object. Encoder must be able to encode the info into the appropriate destination type.
|
||||
// This function returns whether the mutation function made any change in the original object.
|
||||
func CalculatePatch(patch *Patch, encoder runtime.Encoder, mutateFn patchFn) bool {
|
||||
patch.Before, patch.Err = runtime.Encode(encoder, patch.Info.Object)
|
||||
versionedEncoder := api.Codecs.EncoderForVersion(encoder, patch.Info.Mapping.GroupVersionKind.GroupVersion())
|
||||
|
||||
patch.Before, patch.Err = runtime.Encode(versionedEncoder, patch.Info.Object)
|
||||
|
||||
patch.After, patch.Err = mutateFn(patch.Info)
|
||||
if patch.Err != nil {
|
||||
|
@ -381,7 +381,9 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
return runtime.Encode(o.Encoder, info.Object)
|
||||
// TODO: switch UpdatePodSpecForObject to work on v1.PodSpec, use info.VersionedObject, and avoid conversion completely
|
||||
versionedEncoder := api.Codecs.EncoderForVersion(o.Encoder, info.Mapping.GroupVersionKind.GroupVersion())
|
||||
return runtime.Encode(versionedEncoder, info.Object)
|
||||
}
|
||||
return nil, err
|
||||
})
|
||||
|
@ -225,7 +225,9 @@ func (o *ImageOptions) Run() error {
|
||||
return nil
|
||||
})
|
||||
if transformed && err == nil {
|
||||
return runtime.Encode(o.Encoder, info.Object)
|
||||
// TODO: switch UpdatePodSpecForObject to work on v1.PodSpec, use info.VersionedObject, and avoid conversion completely
|
||||
versionedEncoder := api.Codecs.EncoderForVersion(o.Encoder, info.Mapping.GroupVersionKind.GroupVersion())
|
||||
return runtime.Encode(versionedEncoder, info.Object)
|
||||
}
|
||||
return nil, err
|
||||
})
|
||||
|
@ -216,7 +216,9 @@ func (o *ResourcesOptions) Run() error {
|
||||
return nil
|
||||
})
|
||||
if transformed && err == nil {
|
||||
return runtime.Encode(o.Encoder, info.Object)
|
||||
// TODO: switch UpdatePodSpecForObject to work on v1.PodSpec, use info.VersionedObject, and avoid conversion completely
|
||||
versionedEncoder := api.Codecs.EncoderForVersion(o.Encoder, info.Mapping.GroupVersionKind.GroupVersion())
|
||||
return runtime.Encode(versionedEncoder, info.Object)
|
||||
}
|
||||
return nil, err
|
||||
})
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/rbac"
|
||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
@ -218,7 +219,9 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
|
||||
|
||||
transformed, err := updateSubjectForObject(info.Object, subjects, fn)
|
||||
if transformed && err == nil {
|
||||
return runtime.Encode(o.Encoder, info.Object)
|
||||
// TODO: switch UpdatePodSpecForObject to work on v1.PodSpec, use info.VersionedObject, and avoid conversion completely
|
||||
versionedEncoder := api.Codecs.EncoderForVersion(o.Encoder, info.Mapping.GroupVersionKind.GroupVersion())
|
||||
return runtime.Encode(versionedEncoder, info.Object)
|
||||
}
|
||||
return nil, err
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user