mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Move Update Apply conflict test to field manager test
This commit is contained in:
parent
1ade4ce269
commit
9828f986af
@ -95,6 +95,67 @@ func TestUpdateOnlyDoesNotTrackManagedFields(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestUpdateApplyConflict tests that applying to an object, which wasn't created by apply, will give conflicts
|
||||
func TestUpdateApplyConflict(t *testing.T) {
|
||||
f := NewTestFieldManager()
|
||||
|
||||
obj := &corev1.Pod{}
|
||||
obj.ObjectMeta.ManagedFields = []metav1.ManagedFieldsEntry{{}}
|
||||
|
||||
patch := []byte(`{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"name": "deployment",
|
||||
"labels": {"app": "nginx"}
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 3,
|
||||
"selector": {
|
||||
"matchLabels": {
|
||||
"app": "nginx"
|
||||
}
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"labels": {
|
||||
"app": "nginx"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [{
|
||||
"name": "nginx",
|
||||
"image": "nginx:latest"
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}`)
|
||||
newObj := &unstructured.Unstructured{Object: map[string]interface{}{}}
|
||||
if err := yaml.Unmarshal(patch, &newObj.Object); err != nil {
|
||||
t.Fatalf("error decoding YAML: %v", err)
|
||||
}
|
||||
|
||||
savedObject, err := f.Update(obj, newObj, "fieldmanager_test")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to apply object: %v", err)
|
||||
}
|
||||
|
||||
_, err = f.Apply(savedObject, []byte(`{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"name": "deployment",
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 101,
|
||||
}
|
||||
}`), "fieldmanager_conflict", false)
|
||||
if err == nil || !apierrors.IsConflict(err) {
|
||||
t.Fatalf("Expecting to get conflicts but got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyStripsFields(t *testing.T) {
|
||||
f := NewTestFieldManager()
|
||||
|
||||
|
@ -386,81 +386,6 @@ func TestApplyUpdateApplyConflictForced(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestUpdateApplyConflict tests that applying to an object, which wasn't created by apply, will give conflicts
|
||||
func TestUpdateApplyConflict(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ServerSideApply, true)()
|
||||
|
||||
_, client, closeFn := setup(t)
|
||||
defer closeFn()
|
||||
|
||||
obj := []byte(`{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"name": "deployment",
|
||||
"labels": {"app": "nginx"}
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 3,
|
||||
"selector": {
|
||||
"matchLabels": {
|
||||
"app": "nginx"
|
||||
}
|
||||
},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"labels": {
|
||||
"app": "nginx"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [{
|
||||
"name": "nginx",
|
||||
"image": "nginx:latest"
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}`)
|
||||
|
||||
_, err := client.CoreV1().RESTClient().Post().
|
||||
AbsPath("/apis/apps/v1").
|
||||
Namespace("default").
|
||||
Resource("deployments").
|
||||
Body(obj).Do().Get()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create object using post: %v", err)
|
||||
}
|
||||
|
||||
obj = []byte(`{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": {
|
||||
"name": "deployment",
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 101,
|
||||
}
|
||||
}`)
|
||||
_, err = client.CoreV1().RESTClient().Patch(types.ApplyPatchType).
|
||||
AbsPath("/apis/apps/v1").
|
||||
Namespace("default").
|
||||
Resource("deployments").
|
||||
Name("deployment").
|
||||
Param("fieldManager", "apply_test").
|
||||
Body([]byte(obj)).Do().Get()
|
||||
if err == nil {
|
||||
t.Fatalf("Expecting to get conflicts when applying object")
|
||||
}
|
||||
status, ok := err.(*errors.StatusError)
|
||||
if !ok {
|
||||
t.Fatalf("Expecting to get conflicts as API error")
|
||||
}
|
||||
if len(status.Status().Details.Causes) < 1 {
|
||||
t.Fatalf("Expecting to get at least one conflict when applying object, got: %v", status.Status().Details.Causes)
|
||||
}
|
||||
}
|
||||
|
||||
// TestApplyManagedFields makes sure that managedFields api does not change
|
||||
func TestApplyManagedFields(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ServerSideApply, true)()
|
||||
|
Loading…
Reference in New Issue
Block a user