mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-21 20:59:17 +00:00
clean up test
Kubernetes-commit: 8f6d7f1fa13db3d7a3354a13f014e1ce7acabda0
This commit is contained in:
parent
ced85a8521
commit
46dc22f46a
@ -20,7 +20,7 @@ import (
|
|||||||
// 3. Client-side apply tends to own more fields (including fields that are defaulted),
|
// 3. Client-side apply tends to own more fields (including fields that are defaulted),
|
||||||
// this will possibly remove this defaults, they will be re-defaulted, that's fine.
|
// this will possibly remove this defaults, they will be re-defaulted, that's fine.
|
||||||
// 4. Care must be taken to not overwrite the managed fields on the server if they
|
// 4. Care must be taken to not overwrite the managed fields on the server if they
|
||||||
// have changed during the RMW operation.
|
// have changed before sending a patch.
|
||||||
//
|
//
|
||||||
// csaManager - Name of FieldManager formerly used for `Update` operations
|
// csaManager - Name of FieldManager formerly used for `Update` operations
|
||||||
// ssaManager - Name of FieldManager formerly used for `Apply` operations
|
// ssaManager - Name of FieldManager formerly used for `Apply` operations
|
||||||
@ -29,7 +29,6 @@ func UpgradeManagedFields(
|
|||||||
obj runtime.Object,
|
obj runtime.Object,
|
||||||
csaManagerName string,
|
csaManagerName string,
|
||||||
ssaManagerName string,
|
ssaManagerName string,
|
||||||
subResource string,
|
|
||||||
) (runtime.Object, error) {
|
) (runtime.Object, error) {
|
||||||
accessor, err := meta.Accessor(obj)
|
accessor, err := meta.Accessor(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,12 +11,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestUpgradeCSA(t *testing.T) {
|
func TestUpgradeCSA(t *testing.T) {
|
||||||
// Initial object has managed fields from using CSA
|
|
||||||
originalYAML := []byte(`
|
cases := []struct {
|
||||||
|
CSAManager string
|
||||||
|
SSAManager string
|
||||||
|
OriginalObject []byte
|
||||||
|
ExpectedObject []byte
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
CSAManager: "kubectl-client-side-apply",
|
||||||
|
SSAManager: "kubectl",
|
||||||
|
OriginalObject: []byte(`
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data: {}
|
||||||
key: value
|
|
||||||
legacy: unused
|
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
@ -40,25 +47,10 @@ metadata:
|
|||||||
time: "2022-08-22T23:08:23Z"
|
time: "2022-08-22T23:08:23Z"
|
||||||
name: test
|
name: test
|
||||||
namespace: default
|
namespace: default
|
||||||
resourceVersion: "12502"
|
`),
|
||||||
uid: 1f186675-58e6-4d7b-8bc5-7ece581e3013
|
ExpectedObject: []byte(`
|
||||||
`)
|
|
||||||
initialObject := unstructured.Unstructured{}
|
|
||||||
err := yaml.Unmarshal(originalYAML, &initialObject)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
upgraded, err := csaupgrade.UpgradeManagedFields(&initialObject, "kubectl-client-side-apply", "kubectl", "")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedYAML := []byte(`
|
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data: {}
|
||||||
key: value
|
|
||||||
legacy: unused
|
|
||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
@ -82,12 +74,29 @@ metadata:
|
|||||||
time: "2022-08-22T23:08:23Z"
|
time: "2022-08-22T23:08:23Z"
|
||||||
name: test
|
name: test
|
||||||
namespace: default
|
namespace: default
|
||||||
resourceVersion: "12502"
|
`),
|
||||||
uid: 1f186675-58e6-4d7b-8bc5-7ece581e3013
|
},
|
||||||
`)
|
}
|
||||||
|
|
||||||
|
for _, testCase := range cases {
|
||||||
|
initialObject := unstructured.Unstructured{}
|
||||||
|
err := yaml.Unmarshal(testCase.OriginalObject, &initialObject)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
upgraded, err := csaupgrade.UpgradeManagedFields(
|
||||||
|
&initialObject,
|
||||||
|
testCase.CSAManager,
|
||||||
|
testCase.SSAManager,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
expectedObject := unstructured.Unstructured{}
|
expectedObject := unstructured.Unstructured{}
|
||||||
err = yaml.Unmarshal(expectedYAML, &expectedObject)
|
err = yaml.Unmarshal(testCase.ExpectedObject, &expectedObject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -96,3 +105,4 @@ metadata:
|
|||||||
t.Fatal(cmp.Diff(&expectedObject, upgraded))
|
t.Fatal(cmp.Diff(&expectedObject, upgraded))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user