Skip to content

Commit

Permalink
Merge pull request #100 from cisco-open/dependabot/go_modules/gomod-0…
Browse files Browse the repository at this point in the history
…8ac6d2c31

build(deps): bump the gomod group with 2 updates
  • Loading branch information
pepov authored Jun 6, 2024
2 parents 26241f6 + 39671a6 commit cacf194
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 273 deletions.
40 changes: 17 additions & 23 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ["1.18", "1.19", "1.20"]
go: ["1.22"]

steps:
- name: Set up Go
Expand All @@ -33,16 +33,15 @@ jobs:
strategy:
fail-fast: false
matrix:
kube: ["1.19", "1.20", "1.21", "1.22", "1.23", "1.24"]
# kube: ["1.19", "1.20", "1.21", "1.22", "1.23", "1.24", "1.25", "1.26"]
kube: ["1.25", "1.26", "1.27", "1.28", "1.29", "1.30"]
env:
KUBECONFIG: ${{ github.workspace }}/.kube/config

steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.22'

- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -52,23 +51,18 @@ jobs:
id: node_image
run: |
case ${{ matrix.kube }} in
1.19)
NODE_IMAGE=kindest/node:v1.19.16@sha256:476cb3269232888437b61deca013832fee41f9f074f9bed79f57e4280f7c48b7 ;;
1.20)
NODE_IMAGE=kindest/node:v1.20.15@sha256:a32bf55309294120616886b5338f95dd98a2f7231519c7dedcec32ba29699394 ;;
1.21)
NODE_IMAGE=kindest/node:v1.21.14@sha256:9d9eb5fb26b4fbc0c6d95fa8c790414f9750dd583f5d7cee45d92e8c26670aa1 ;;
1.22)
NODE_IMAGE=kindest/node:v1.22.15@sha256:7d9708c4b0873f0fe2e171e2b1b7f45ae89482617778c1c875f1053d4cef2e41 ;;
1.23)
NODE_IMAGE=kindest/node:v1.23.13@sha256:ef453bb7c79f0e3caba88d2067d4196f427794086a7d0df8df4f019d5e336b61 ;;
1.24)
NODE_IMAGE=kindest/node:v1.24.7@sha256:577c630ce8e509131eab1aea12c022190978dd2f745aac5eb1fe65c0807eb315 ;;
# Integration tests don't pass on these versions due to API incompatibilities
# 1.25)
# NODE_IMAGE=kindest/node:v1.25.3@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1 ;;
# 1.26)
# NODE_IMAGE=kindest/node:v1.26.0@sha256:691e24bd2417609db7e589e1a479b902d2e209892a10ce375fab60a8407c7352 ;;
1.25)
NODE_IMAGE=kindest/node:v1.25.11@sha256:227fa11ce74ea76a0474eeefb84cb75d8dad1b08638371ecf0e86259b35be0c8 ;;
1.26)
NODE_IMAGE=kindest/node:v1.26.6@sha256:6e2d8b28a5b601defe327b98bd1c2d1930b49e5d8c512e1895099e4504007adb ;;
1.27)
NODE_IMAGE=kindest/node:v1.27.3@sha256:3966ac761ae0136263ffdb6cfd4db23ef8a83cba8a463690e98317add2c9ba72 ;;
1.28)
NODE_IMAGE=kindest/node:v1.28.9@sha256:9ba4d311e7861d27b210e5960e5ce921a7c53d3c67e0545fd8a1cb9a76dfa2cb ;;
1.29)
NODE_IMAGE=kindest/node:v1.29.4@sha256:ea40a6bd365a17f71fd3883a1d34a0791d7d6b0eb75832c6d85b6f2326827f1e ;;
1.30)
NODE_IMAGE=kindest/node:v1.30.0@sha256:2af5d1b382926abcd6336312d652cd045b7cc47475844a608669c71b1fefcfbc ;;
esac
echo "image=$NODE_IMAGE" >> $GITHUB_OUTPUT
Expand All @@ -89,7 +83,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.22'

- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -107,7 +101,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.22'

- name: Checkout code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/
/bin/
/.licensei.cache
.idea
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
LICENSEI_VERSION = 0.5.0
GOLANGCI_VERSION = 1.51.1
LICENSEI_VERSION = 0.9.0
GOLANGCI_VERSION = 1.59.0

all: license fmt vet test

Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ In certain cases there is a need to filter out certain fields when the patch gen
To help in these scenarios there are the following options to be used when calculating diffs:
- `IgnoreStatusFields`
- `IgnoreVolumeClaimTemplateTypeMetaAndStatus`
- `IgnorePDBSelector`
- `IgnoreField("field-name-to-ignore")`

Example:
Expand All @@ -88,11 +87,6 @@ This CalculateOptions removes status fields from both objects before comparing.

This CalculateOption clears volumeClaimTemplate fields from both objects before comparing (applies to statefulsets).

#### IgnorePdbSelector

Checks `selector` fields of PDB objects before comparing and removes them if they match. `reflect.DeepEquals` is used for the equality check.
This is required because map fields using `patchStrategy:"replace"` will always diff regardless if they are otherwise equal.

#### IgnoreField("field-name-to-ignore")

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.
Expand Down
21 changes: 10 additions & 11 deletions docs/legacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ The legacy version was last available with the 0.1.1 version.
- PersistentVolumeClaim
- Service
- ServiceAccount
- PodDisruptionBudget
- Unstructured
- Node

Expand All @@ -33,11 +32,11 @@ objectMatcher.Match(e.ObjectOld, e.ObjectNew)

### The idea

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?
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?
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
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).

Strategic Merge Patch extends the JSON Merge Patch format by adding explicit directives for deleting, replacing, ordering and merging lists.
Strategic Merge Patch extends the JSON Merge Patch format by adding explicit directives for deleting, replacing, ordering and merging lists.
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
Kubernetes objects only, so we can use this for matching custom go structs as well.

Expand All @@ -46,21 +45,21 @@ Kubernetes objects only, so we can use this for matching custom go structs as we
#### Defaults and version compatibility

As outlined previously Kubernetes objects are amended with different default values when submitted. For example PodSpec.RestartPolicy will be set to "Always" when
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
objects before matching so that they won't differ.
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
objects before matching so that they won't differ.

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
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
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
version.

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
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
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.

#### Generated values

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.
(In case of lists, even if we remove null fields we would still left with `setElementOrder` directives)
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.
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.
(In case of lists, even if we remove null fields we would still left with `setElementOrder` directives)
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.

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).
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).
Another example is Volume and VolumeMount generated automatically for the service account token, see [pod.go](pod.go).
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/cisco-open/k8s-objectmatcher

go 1.17
go 1.22.0

require (
emperror.dev/errors v0.8.1
github.com/evanphx/json-patch v5.6.0+incompatible
github.com/evanphx/json-patch v5.9.0+incompatible
github.com/json-iterator/go v1.1.12
k8s.io/apimachinery v0.19.2
k8s.io/apimachinery v0.19.16
)

require (
Expand All @@ -28,6 +28,6 @@ require (
gopkg.in/yaml.v2 v2.2.8 // indirect
k8s.io/klog/v2 v2.2.0 // indirect
k8s.io/kube-openapi v0.0.0-20200805222855-6aeccd4b50c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.0.1 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
Loading

0 comments on commit cacf194

Please sign in to comment.