Skip to content

Commit

Permalink
Merge pull request #43 from banzaicloud/pdb-diff
Browse files Browse the repository at this point in the history
PDB selector diff fix
  • Loading branch information
waynz0r authored Aug 10, 2021
2 parents af0ea18 + d3b5173 commit 191d64b
Show file tree
Hide file tree
Showing 10 changed files with 759 additions and 91 deletions.
61 changes: 17 additions & 44 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
integration-test-environment: &integration-test-environment
GO_VERSION: "1.15.2"
KUBECONFIG: /home/circleci/.kube/config
MINIKUBE_VERSION: v1.13.1
MINIKUBE_VERSION: v1.22.0
MINIKUBE_WANTUPDATENOTIFICATION: false
MINIKUBE_WANTREPORTERRORPROMPT: false
MINIKUBE_HOME: /home/circleci
Expand Down Expand Up @@ -38,7 +38,7 @@ integration-test-base: &integration-test-base
- run:
name: Setup kubectl
command: |
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
curl -Lo kubectl "https://dl.k8s.io/release/${K8S_VERSION}/bin/linux/amd64/kubectl" && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
mkdir -p ${HOME}/.kube
touch ${HOME}/.kube/config
Expand Down Expand Up @@ -145,80 +145,53 @@ jobs:
name: Run verification
command: make

integration-test-k8s1-19:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.19.2

integration-test-k8s1-18:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.18.9

integration-test-k8s1-17:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.17.12

integration-test-k8s1-16:
integration-test-k8s1-21:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.16.15
K8S_VERSION: v1.21.3

integration-test-k8s1-15:
integration-test-k8s1-20:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.15.7
K8S_VERSION: v1.20.9

integration-test-k8s1-14:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.14.2

integration-test-k8s1-13:
integration-test-k8s1-19:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.13.6
K8S_VERSION: v1.19.2

integration-test-k8s1-12:
integration-test-k8s1-18:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.12.9
K8S_VERSION: v1.18.9

integration-test-k8s1-11:
integration-test-k8s1-17:
<<: *integration-test-base
environment:
<<: *integration-test-environment
K8S_VERSION: v1.11.9
K8S_VERSION: v1.17.12

workflows:
version: 2
ci:
jobs:
- check
- integration-test-k8s1-19:
- integration-test-k8s1-21:
requires:
- check
- integration-test-k8s1-18:
- integration-test-k8s1-20:
requires:
- check
- integration-test-k8s1-17:
requires:
- check
- integration-test-k8s1-16:
- integration-test-k8s1-19:
requires:
- check
- integration-test-k8s1-15:
- integration-test-k8s1-18:
requires:
- check
- integration-test-k8s1-14:
- integration-test-k8s1-17:
requires:
- check
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LICENSEI_VERSION = 0.3.1
LICENSEI_VERSION = 0.4.0
GOLANGCI_VERSION = 1.16.0

all: license fmt vet test
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,39 @@ if !patchResult.IsEmpty() {

```

### CalculateOptions

In certain cases there is a need to filter out certain fields when the patch generated by the library is false positive.
To help in these scenarios there are the following options to be used when calculating diffs:
- `IgnoreStatusFields`
- `IgnoreVolumeClaimTemplateTypeMetaAndStatus`
- `IgnorePDBSelector`

Example:
```
opts := []patch.CalculateOption{
patch.IgnoreStatusFields(),
}
patchResult, err := patch.DefaultPatchMaker.Calculate(existing.(runtime.Object), newObject.(runtime.Object), opts...)
if err != nil {
return err
}
```

#### IgnoreStatusFields

This CalculateOptions removes status fields from both objects before comparing.

#### IgnoreVolumeClaimTemplateTypeMetaAndStatus

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.

## Contributing

If you find this project useful here's how you can help:
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module github.com/banzaicloud/k8s-objectmatcher

go 1.13
go 1.15

require (
emperror.dev/errors v0.8.0
github.com/json-iterator/go v1.1.10
k8s.io/api v0.19.2
github.com/json-iterator/go v1.1.11
k8s.io/apimachinery v0.19.2
)
Loading

0 comments on commit 191d64b

Please sign in to comment.