mirror of https://github.com/k3s-io/k3s
switch to k8s json to avoid number conversion issue
parent
b4ad869c0c
commit
b29f4c26d7
|
@ -17,12 +17,12 @@ limitations under the License.
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/conversion/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/json"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
|
||||
"github.com/evanphx/json-patch"
|
||||
|
|
|
@ -284,6 +284,37 @@ func (tc *patchTestCase) Run(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestNumberConversion(t *testing.T) {
|
||||
codec := api.Codecs.LegacyCodec(schema.GroupVersion{Version: "v1"})
|
||||
|
||||
currentVersionedObject := &v1.Service{
|
||||
TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "v1"},
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "test-service"},
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{
|
||||
{
|
||||
Port: 80,
|
||||
Protocol: "TCP",
|
||||
NodePort: 31678,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
versionedObjToUpdate := &v1.Service{}
|
||||
versionedObj := &v1.Service{}
|
||||
|
||||
patchJS := []byte(`{"spec":{"ports":[{"port":80,"nodePort":31789}]}}`)
|
||||
|
||||
_, _, err := strategicPatchObject(codec, currentVersionedObject, patchJS, versionedObjToUpdate, versionedObj)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ports := versionedObjToUpdate.Spec.Ports
|
||||
if len(ports) != 1 || ports[0].Port != 80 || ports[0].NodePort != 31789 {
|
||||
t.Fatal(errors.New("Ports failed to merge because of number conversion issue"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPatchResourceWithVersionConflict(t *testing.T) {
|
||||
namespace := "bar"
|
||||
name := "foo"
|
||||
|
|
|
@ -10023,6 +10023,7 @@ go_library(
|
|||
"//vendor:k8s.io/apimachinery/pkg/runtime/serializer/streaming",
|
||||
"//vendor:k8s.io/apimachinery/pkg/types",
|
||||
"//vendor:k8s.io/apimachinery/pkg/util/httpstream",
|
||||
"//vendor:k8s.io/apimachinery/pkg/util/json",
|
||||
"//vendor:k8s.io/apimachinery/pkg/util/mergepatch",
|
||||
"//vendor:k8s.io/apimachinery/pkg/util/net",
|
||||
"//vendor:k8s.io/apimachinery/pkg/util/runtime",
|
||||
|
|
Loading…
Reference in New Issue