// TestPatchVeryLargeObject tests that a small object can be patched to be very large without exceeding the size limit due to managedFields
TestPatchVeryLargeObject tests that a small object can be patched to be very large without exceeding the size limit due to managedFields
// TestPatchVeryLargeObject tests that a small object can be patched to be very large without exceeding the size limit due to managedFields
func TestPatchVeryLargeObject(t *testing.T) {
	defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ServerSideApply, true)()
	_, client, closeFn := setup(t)
	defer closeFn()
	cfg := &v1.ConfigMap{
		ObjectMeta: metav1.ObjectMeta{
			Name:      "large-patch-test-cm",
			Namespace: "default",
		},
		Data: map[string]string{"k": "v"},
	}
	if _, err := client.CoreV1().ConfigMaps(cfg.Namespace).Create(context.TODO(), cfg, metav1.CreateOptions{}); err != nil {
		t.Errorf("unable to create configMap: %v", err)
	}
	patchString := `{"data":{"k":"v"`
	for i := 0; i < 9999; i++ {
		unique := fmt.Sprintf("this-key-is-very-long-so-as-to-create-a-very-large-serialized-fieldset-%v", i)
		patchString = fmt.Sprintf("%s,%q:%q", patchString, unique, "A")
	}
	patchString = fmt.Sprintf("%s}}", patchString)
	_, err := client.CoreV1().RESTClient().Patch(types.MergePatchType).
		AbsPath("/api/v1").
		Namespace(cfg.Namespace).
		Resource("configmaps").
		Name(cfg.Name).
		Body([]byte(patchString)).Do(context.TODO()).Get()
	if err != nil {
		t.Errorf("unable to patch configMap: %v", err)
	}
	_, err = client.CoreV1().RESTClient().Patch(types.ApplyPatchType).
		Namespace("default").
		Resource("configmaps").
		Name("large-patch-test-cm").
		Param("fieldManager", "apply_test").
		Body([]byte(`{
			"apiVersion": "v1",
			"kind": "ConfigMap",
			"metadata": {
				"name": "large-patch-test-cm",
				"namespace": "default",
			}
		}`)).
		Do(context.TODO()).
		Get()
	if err == nil {
		t.Fatalf("expected to fail to update object using Apply patch, but succeeded")
	}
}
func TestPatchVeryLargeObject ( t * testing . T ) { defer featuregatetesting . SetFeatureGateDuringTest ( t , utilfeature . DefaultFeatureGate , genericfeatures . ServerSideApply , true ) ( ) _ , client , closeFn := setup ( t ) defer closeFn ( ) cfg := & v1 . ConfigMap { ObjectMeta : metav1 . ObjectMeta { Name : " " , Namespace : " " , } , Data : map [ string ] string { " " : " " } , } if _ , err := client . CoreV1 ( ) . ConfigMaps ( cfg . Namespace ) . Create ( context . TODO ( ) , cfg , metav1 . CreateOptions { } ) ; err != nil { t . Errorf ( " " , err ) } patchString := `{"data":{"k":"v"` for i := 0 ; i < 9999 ; i ++ { unique := fmt . Sprintf ( " " , i ) patchString = fmt . Sprintf ( " " , patchString , unique , " " ) } patchString = fmt . Sprintf ( " " , patchString ) _ , err := client . CoreV1 ( ) . RESTClient ( ) . Patch ( types . MergePatchType ) . AbsPath ( " " ) . Namespace ( cfg . Namespace ) . Resource ( " " ) . Name ( cfg . Name ) . Body ( [ ] byte ( patchString ) ) . Do ( context . TODO ( ) ) . Get ( ) if err != nil { t . Errorf ( " " , err ) } _ , err = client . CoreV1 ( ) . RESTClient ( ) . Patch ( types . ApplyPatchType ) . Namespace ( " " ) . Resource ( " " ) . Name ( " " ) . Param ( " " , " " ) . Body ( [ ] byte ( `{
			"apiVersion": "v1",
			"kind": "ConfigMap",
			"metadata": {
				"name": "large-patch-test-cm",
				"namespace": "default",
			}
		}` ) ) . Do ( context . TODO ( ) ) . Get ( ) if err == nil { t . Fatalf ( " " ) } }
TestPatchVeryLargeObject tests that a small object can be patched to be very large without exceeding the size limit due to managedFields
TestPatchVeryLargeObject tests that a small object can be patched to be very large without exceeding the size limit due to managedFields
// Create a small config map. // Should be able to update a small object to be near the object size limit. // Applying to the same object should cause managedFields to go over the object size limit, and fail.