func TestUpdateVeryLargeObject(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-update-test-cm",
			Namespace: "default",
		},
		Data: map[string]string{"k": "v"},
	}

	// Create a small config map.
	cfg, err := client.CoreV1().ConfigMaps(cfg.Namespace).Create(context.TODO(), cfg, metav1.CreateOptions{})
	if err != nil {
		t.Errorf("unable to create configMap: %v", err)
	}

	// Should be able to update a small object to be near the object size limit.
	var updateErr error
	pollErr := wait.PollImmediate(100*time.Millisecond, 30*time.Second, func() (bool, error) {
		updateCfg, err := client.CoreV1().ConfigMaps(cfg.Namespace).Get(context.TODO(), cfg.Name, metav1.GetOptions{})
		if err != nil {
			return false, err
		}

		// Apply the large update, then attempt to push it to the apiserver.
		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)
			updateCfg.Data[unique] = "A"
		}

		if _, err = client.CoreV1().ConfigMaps(cfg.Namespace).Update(context.TODO(), updateCfg, metav1.UpdateOptions{}); err == nil {
			return true, nil
		}
		updateErr = err
		return false, nil
	})
	if pollErr == wait.ErrWaitTimeout {
		t.Errorf("unable to update configMap: %v", updateErr)
	}

	// Applying to the same object should cause managedFields to go over the object size limit, and fail.
	_, err = client.CoreV1().RESTClient().Patch(types.ApplyPatchType).
		Namespace(cfg.Namespace).
		Resource("configmaps").
		Name(cfg.Name).
		Param("fieldManager", "apply_test").
		Body([]byte(`{
			"apiVersion": "v1",
			"kind": "ConfigMap",
			"metadata": {
				"name": "large-update-test-cm",
				"namespace": "default",
			}
		}`)).
		Do(context.TODO()).
		Get()
	if err == nil {
		t.Fatalf("expected to fail to update object using Apply patch, but succeeded")
	}
}
// TestUpdateVeryLargeObject tests that a small object can be updated to be very large without exceeding the size limit due to managedFields
TestUpdateVeryLargeObject tests that a small object can be updated to be very large without exceeding the size limit due to managedFields
// TestUpdateVeryLargeObject tests that a small object can be updated to be very large without exceeding the size limit due to managedFields
func TestUpdateVeryLargeObject(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-update-test-cm",
			Namespace: "default",
		},
		Data: map[string]string{"k": "v"},
	}
	cfg, err := client.CoreV1().ConfigMaps(cfg.Namespace).Create(context.TODO(), cfg, metav1.CreateOptions{})
	if err != nil {
		t.Errorf("unable to create configMap: %v", err)
	}
	var updateErr error
	pollErr := wait.PollImmediate(100*time.Millisecond, 30*time.Second, func() (bool, error) {
		updateCfg, err := client.CoreV1().ConfigMaps(cfg.Namespace).Get(context.TODO(), cfg.Name, metav1.GetOptions{})
		if err != nil {
			return false, err
		}
		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)
			updateCfg.Data[unique] = "A"
		}
		if _, err = client.CoreV1().ConfigMaps(cfg.Namespace).Update(context.TODO(), updateCfg, metav1.UpdateOptions{}); err == nil {
			return true, nil
		}
		updateErr = err
		return false, nil
	})
	if pollErr == wait.ErrWaitTimeout {
		t.Errorf("unable to update configMap: %v", updateErr)
	}
	_, err = client.CoreV1().RESTClient().Patch(types.ApplyPatchType).
		Namespace(cfg.Namespace).
		Resource("configmaps").
		Name(cfg.Name).
		Param("fieldManager", "apply_test").
		Body([]byte(`{
			"apiVersion": "v1",
			"kind": "ConfigMap",
			"metadata": {
				"name": "large-update-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 TestUpdateVeryLargeObject ( 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 { " " : " " } , } cfg , err := client . CoreV1 ( ) . ConfigMaps ( cfg . Namespace ) . Create ( context . TODO ( ) , cfg , metav1 . CreateOptions { } ) if err != nil { t . Errorf ( " " , err ) } var updateErr error pollErr := wait . PollImmediate ( 100 * time . Millisecond , 30 * time . Second , func ( ) ( bool , error ) { updateCfg , err := client . CoreV1 ( ) . ConfigMaps ( cfg . Namespace ) . Get ( context . TODO ( ) , cfg . Name , metav1 . GetOptions { } ) if err != nil { return false , err } for i := 0 ; i < 9999 ; i ++ { unique := fmt . Sprintf ( " " , i ) updateCfg . Data [ unique ] = " " } if _ , err = client . CoreV1 ( ) . ConfigMaps ( cfg . Namespace ) . Update ( context . TODO ( ) , updateCfg , metav1 . UpdateOptions { } ) ; err == nil { return true , nil } updateErr = err return false , nil } ) if pollErr == wait . ErrWaitTimeout { t . Errorf ( " " , updateErr ) } _ , err = client . CoreV1 ( ) . RESTClient ( ) . Patch ( types . ApplyPatchType ) . Namespace ( cfg . Namespace ) . Resource ( " " ) . Name ( cfg . Name ) . Param ( " " , " " ) . Body ( [ ] byte ( `{
			"apiVersion": "v1",
			"kind": "ConfigMap",
			"metadata": {
				"name": "large-update-test-cm",
				"namespace": "default",
			}
		}` ) ) . Do ( context . TODO ( ) ) . Get ( ) if err == nil { t . Fatalf ( " " ) } }
TestUpdateVeryLargeObject tests that a small object can be updated to be very large without exceeding the size limit due to managedFields
TestUpdateVeryLargeObject tests that a small object can be updated 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. // Apply the large update, then attempt to push it to the apiserver. // Applying to the same object should cause managedFields to go over the object size limit, and fail.