Skip to content

Commit

Permalink
Fixed configmap diff and updated Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
m1 committed Sep 15, 2023
1 parent 7a9416a commit 8a41695
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ The usecase we are mainly intrested is the first one. We want to track the chang
<div align="center">
<img src="./docs/msteams.png">
</div>

## TL;DR
#Latest Release:
1.0.1- [Release Notes]
- Add support for ignoring specific namespaces and watching more than one namespace
- Add metrics
- Deeper Diff for configmaps (currently it drops the new configmap as a whole). its Work for me atm. It needs more work to be more generic.

# Latest image

```
docmarr/kubernetes-diffwatcher:1.0.0
docmarr/kubernetes-diffwatcher:1.0.1
```

# Install
Expand Down Expand Up @@ -708,12 +716,14 @@ diffwatcher latest 919896d3cd90 3 minutes ago

# Things for future version

- Add support for ignoring specific namespaces and watching more than one namespace
- Change config source file from yaml to json
- Add metrics
- Deeper Diff for configmaps (currently it drops the new configmap as a whole)
- Add support for ignoring specific namespaces and watching more than one namespace (1.0.1)
- Add metrics (1.0.1)
- Deeper Diff for configmaps (currently it drops the new configmap as a whole)(1.0.1)
- Add regex support for path ignorance in diff

- Change config source file from yaml to json
- Dissable processing during deployment




Expand Down
19 changes: 15 additions & 4 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"os/signal"
"reflect"
"sort"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -815,17 +816,27 @@ func compareObjects(e Event) string {

func compareConfigMaps(old runtime.Object, new runtime.Object) (jsondiff.Patch, error) {

//Extracting data string from configmap
//TODO: extract name from config or even better from deployment
oldData, oldSuccess := old.(*api_v1.ConfigMap).Data["appsettings.json"]
newData, newSuccess := new.(*api_v1.ConfigMap).Data["appsettings.json"]
//Dynamic extraction of data from configmap
keys := make([]string, 0)
for k, _ := range old.(*api_v1.ConfigMap).Data {
keys = append(keys, k)
}

sort.Strings(keys)
k := keys[0]
if !strings.Contains(k, ".json") {
return nil, fmt.Errorf("error in extracting data from configmap")
}

oldData, oldSuccess := old.(*api_v1.ConfigMap).Data[k]
newData, newSuccess := new.(*api_v1.ConfigMap).Data[k]
if !oldSuccess || !newSuccess {
return nil, fmt.Errorf("error in extracting data from configmap")
}

oldDataStr := strings.ReplaceAll(oldData, "\\", "")
newDataStr := strings.ReplaceAll(newData, "\\", "")

return jsondiff.CompareJSON([]byte(oldDataStr), []byte(newDataStr))
}

Expand Down

0 comments on commit 8a41695

Please sign in to comment.