You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
-6Lines changed: 0 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,6 @@ In certain cases there is a need to filter out certain fields when the patch gen
65
65
To help in these scenarios there are the following options to be used when calculating diffs:
66
66
-`IgnoreStatusFields`
67
67
-`IgnoreVolumeClaimTemplateTypeMetaAndStatus`
68
-
-`IgnorePDBSelector`
69
68
-`IgnoreField("field-name-to-ignore")`
70
69
71
70
Example:
@@ -88,11 +87,6 @@ This CalculateOptions removes status fields from both objects before comparing.
88
87
89
88
This CalculateOption clears volumeClaimTemplate fields from both objects before comparing (applies to statefulsets).
90
89
91
-
#### IgnorePdbSelector
92
-
93
-
Checks `selector` fields of PDB objects before comparing and removes them if they match. `reflect.DeepEquals` is used for the equality check.
94
-
This is required because map fields using `patchStrategy:"replace"` will always diff regardless if they are otherwise equal.
95
-
96
90
#### IgnoreField("field-name-to-ignore")
97
91
98
92
This CalculateOption removes the field provided (as a string) in the call before comparing them. A common usage might be to remove the metadata fields by using the `IgnoreField("metadata")` option.
There are existing libraries in the wild that can calculate a patch by giving them two different objects. If the patch is empty the two objects match and we are ready, right?
35
+
There are existing libraries in the wild that can calculate a patch by giving them two different objects. If the patch is empty the two objects match and we are ready, right?
37
36
Well not quite. JSON Merge Patch, defined by [rfc7396](https://tools.ietf.org/html/rfc7396) replaces lists completely which is not always what we need. Kubernetes defines
38
37
and uses a modified version called [strategic merge patch](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md).
39
38
40
-
Strategic Merge Patch extends the JSON Merge Patch format by adding explicit directives for deleting, replacing, ordering and merging lists.
39
+
Strategic Merge Patch extends the JSON Merge Patch format by adding explicit directives for deleting, replacing, ordering and merging lists.
41
40
It uses the go struct tag of the API objects to determine what lists should be merged and which ones should not. Worth to note it's not tied to
42
41
Kubernetes objects only, so we can use this for matching custom go structs as well.
43
42
@@ -46,21 +45,21 @@ Kubernetes objects only, so we can use this for matching custom go structs as we
46
45
#### Defaults and version compatibility
47
46
48
47
As outlined previously Kubernetes objects are amended with different default values when submitted. For example PodSpec.RestartPolicy will be set to "Always" when
49
-
ommitted from the object, so we will have a mismatch when we try to compare it later. This library uses the same functions to set the default values on the local
50
-
objects before matching so that they won't differ.
48
+
ommitted from the object, so we will have a mismatch when we try to compare it later. This library uses the same functions to set the default values on the local
49
+
objects before matching so that they won't differ.
51
50
52
-
Since the defaults functions are defined in the main kubernetes repo, there is a higher chance that objects decorated using these functions will be incompatible
51
+
Since the defaults functions are defined in the main kubernetes repo, there is a higher chance that objects decorated using these functions will be incompatible
53
52
when comparing them with objects coming from different server versions. Also since the library depends on the kubernetes repo it is more tightly coupled to it's
54
53
version.
55
54
56
-
To preserve compatibility between the client and server versions [.circleci/config.yml](.circleci/config.yml) contains jobs that run the integration test suite against Kubernetes
55
+
To preserve compatibility between the client and server versions [.circleci/config.yml](.circleci/config.yml) contains jobs that run the integration test suite against Kubernetes
57
56
versions from 1.10 to 1.14. The library itself is known and tested to be working with operators depending on Kubernetes client version 1.12 and 1.13.
58
57
59
58
#### Generated values
60
59
61
-
There are values that are generated by the API Server dynamically. To workaround this the library removes null fields from the patch as long as it's not inside a list.
62
-
(In case of lists, even if we remove null fields we would still left with `setElementOrder` directives)
63
-
This works as long as we don't set/unset complete fields on the objects conditionally, because in that case we would miss to detect a change to unset something.
60
+
There are values that are generated by the API Server dynamically. To workaround this the library removes null fields from the patch as long as it's not inside a list.
61
+
(In case of lists, even if we remove null fields we would still left with `setElementOrder` directives)
62
+
This works as long as we don't set/unset complete fields on the objects conditionally, because in that case we would miss to detect a change to unset something.
64
63
65
-
In case a field gets removed from somewhere inside a list we have to explicitly tell to ignore it. One example is NodePort in Service objects, see [service.go](service.go).
64
+
In case a field gets removed from somewhere inside a list we have to explicitly tell to ignore it. One example is NodePort in Service objects, see [service.go](service.go).
66
65
Another example is Volume and VolumeMount generated automatically for the service account token, see [pod.go](pod.go).
0 commit comments