doContainersMatch checks if the containers match. They are assumed to be for the same name. If they don't match, the first diff found is returned
(currentContainer, targetContainer corev1.Container)
| 211 | // doContainersMatch checks if the containers match. They are assumed to be for the same name. |
| 212 | // If they don't match, the first diff found is returned |
| 213 | func doContainersMatch(currentContainer, targetContainer corev1.Container) (bool, string) { |
| 214 | comparisons := map[string]func() bool{ |
| 215 | "image": func() bool { |
| 216 | return currentContainer.Image == targetContainer.Image |
| 217 | }, |
| 218 | "environment": func() bool { |
| 219 | return EnvConfig{ |
| 220 | EnvFrom: currentContainer.EnvFrom, |
| 221 | EnvVars: currentContainer.Env, |
| 222 | }.IsEnvEqual(targetContainer) |
| 223 | }, |
| 224 | "readiness-probe": func() bool { |
| 225 | return reflect.DeepEqual(currentContainer.ReadinessProbe, targetContainer.ReadinessProbe) |
| 226 | }, |
| 227 | "liveness-probe": func() bool { |
| 228 | return reflect.DeepEqual(currentContainer.LivenessProbe, targetContainer.LivenessProbe) |
| 229 | }, |
| 230 | "startup-probe": func() bool { |
| 231 | return reflect.DeepEqual(currentContainer.StartupProbe, targetContainer.StartupProbe) |
| 232 | }, |
| 233 | "command": func() bool { |
| 234 | return reflect.DeepEqual(currentContainer.Command, targetContainer.Command) |
| 235 | }, |
| 236 | "resources": func() bool { |
| 237 | // semantic equality will compare the two objects semantically, not only numbers |
| 238 | return equality.Semantic.DeepEqual( |
| 239 | currentContainer.Resources, |
| 240 | targetContainer.Resources, |
| 241 | ) |
| 242 | }, |
| 243 | "ports": func() bool { |
| 244 | return reflect.DeepEqual(currentContainer.Ports, targetContainer.Ports) |
| 245 | }, |
| 246 | "security-context": func() bool { |
| 247 | return reflect.DeepEqual(currentContainer.SecurityContext, targetContainer.SecurityContext) |
| 248 | }, |
| 249 | } |
| 250 | |
| 251 | for diff, f := range comparisons { |
| 252 | if !f() { |
| 253 | return false, diff |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | match, diff := compareVolumeMounts(currentContainer.VolumeMounts, targetContainer.VolumeMounts) |
| 258 | if !match { |
| 259 | return false, "volume-mounts: " + diff |
| 260 | } |
| 261 | return true, "" |
| 262 | } |
| 263 | |
| 264 | func compareContainers(currentContainers, targetContainers []corev1.Container) (bool, string) { |
| 265 | current := make(map[string]corev1.Container) |
no test coverage detected