Okay, so this is a tough one. I think.
I have two arrays of objects that contain some information about pods. I'm looking to provide a side by side comparison of environments to show where pods contain the exact same image; the trick is that I also need to catch the pods where the images aren't matching. The results are going to be rendered on a table which will look something like this (at least as a first iteration):
|---------------------|------------------|------------------|
| Pod Name | Image from Env1 | Image from Env2 |
|---------------------|------------------|------------------|
| foo | foo:1.0.0 | foo:1.0.0 | <---- images match
|---------------------|------------------|------------------|
| foo | foobar:1.0.0 | | <---- No match for image tag; image name different from the pod name as the pods may contain multiple images
|---------------------|------------------|------------------|
| foo | | foobar:2.0.0 | <---- As above
|---------------------|------------------|------------------|
| bar | bar:2.0.0 | bar:2.0.0 | <---- images match
|---------------------|------------------|------------------|
| baz | baz:1.0.0 | | <----
|---------------------|------------------|------------------| Note the 'no match'; so own row for now
| baz | | baz:2.0.0 | <----
|---------------------|------------------|------------------|
I will later use CSS to highlight the matches vs. differences.
The things that I'm struggling with most are:
- Pods may have more than 1 image. 1 of those images may match between environments, but the other may not. When there is more than one image the tags inside that pod differ (see
foopod in table above) - How to check the objects match between environments whilst still capturing the ones that don't match. Using nested loops cause a whole bunch of issues with duplicates and false negatives
- I'm unsure on the best way to store the output. Likely something like:
[{ "Pod Name": "foo", "Image_Env_1": foo:1.0.0", "Image_Env_2": foo:1.0.0"}...and leaving blank strings (like the blank cell in the table) for a value in the non-matching cases. But this may clash with the other image in thefoopod that has different image tags.
So Env1 array looks something like this snippet:
[
{
"Image": {
"S": "foo:1.0.0"
},
"Pod Name": {
"S": "foo"
}
},
{
"Image": {
"S": "foobar:0.2.0"
},
"Pod Name": {
"S": "foo"
}
},
{
"Image": {
"S": "bar:1.0.0"
},
"Pod Name": {
"S": "bar"
}
},
{
"Image": {
"S": "baz:1.0.0"
},
"Pod Name": {
"S": "baz"
}
},
{
"Image": {
"S": "qux:1.0.0"
},
"Pod Name": {
"S": "foo"
}
}
]
Env2 array:
[
{
"Image": {
"S": "foo:2.0.0"
},
"Pod Name": {
"S": "foo"
}
},
{
"Image": {
"S": "foobar:0.2.0"
},
"Pod Name": {
"S": "foo"
}
},
{
"Image": {
"S": "bar:1.0.0"
},
"Pod Name": {
"S": "bar"
}
},
{
"Image": {
"S": "baz:3.0.0"
},
"Pod Name": {
"S": "baz"
}
}
]