|
23 | 23 | package reconcile |
24 | 24 |
|
25 | 25 | import ( |
| 26 | + "reflect" |
26 | 27 | "strings" |
27 | 28 |
|
28 | 29 | driver "github.com/arangodb/go-driver" |
29 | 30 | upgraderules "github.com/arangodb/go-upgrade-rules" |
30 | 31 | "github.com/rs/zerolog" |
31 | 32 | "github.com/rs/zerolog/log" |
32 | | - "k8s.io/api/core/v1" |
33 | 33 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
34 | 34 |
|
35 | 35 | api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1alpha" |
36 | 36 | "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" |
| 37 | + v1 "k8s.io/api/core/v1" |
37 | 38 | ) |
38 | 39 |
|
39 | 40 | // upgradeDecision is the result of an upgrade check. |
@@ -394,9 +395,106 @@ func podNeedsRotation(log zerolog.Logger, p v1.Pod, apiObject metav1.Object, spe |
394 | 395 | return true, "Resource Requirements changed" |
395 | 396 | } |
396 | 397 |
|
| 398 | + var memberStatus, _, _ = status.Members.MemberStatusByPodName(p.GetName()) |
| 399 | + if memberStatus.SideCarSpecs == nil { |
| 400 | + memberStatus.SideCarSpecs = make(map[string]v1.Container) |
| 401 | + } |
| 402 | + |
| 403 | + // Check for missing side cars in |
| 404 | + for _, specSidecar := range groupSpec.GetSidecars() { |
| 405 | + var stateSidecar v1.Container |
| 406 | + if stateSidecar, found = memberStatus.SideCarSpecs[specSidecar.Name]; !found { |
| 407 | + return true, "Sidecar " + specSidecar.Name + " not found in running pod " + p.GetName() |
| 408 | + } |
| 409 | + if sideCarRequireRotation(specSidecar.DeepCopy(), &stateSidecar) { |
| 410 | + return true, "Sidecar " + specSidecar.Name + " requires rotation" |
| 411 | + } |
| 412 | + } |
| 413 | + |
| 414 | + for name := range memberStatus.SideCarSpecs { |
| 415 | + var found = false |
| 416 | + for _, specSidecar := range groupSpec.GetSidecars() { |
| 417 | + if name == specSidecar.Name { |
| 418 | + found = true |
| 419 | + break |
| 420 | + } |
| 421 | + } |
| 422 | + if !found { |
| 423 | + return true, "Sidecar " + name + " no longer in specification" |
| 424 | + } |
| 425 | + } |
| 426 | + |
397 | 427 | return false, "" |
398 | 428 | } |
399 | 429 |
|
| 430 | +// sideCarRequireRotation checks if side car requires rotation including default parameters |
| 431 | +func sideCarRequireRotation(wanted, given *v1.Container) bool { |
| 432 | + if !reflect.DeepEqual(wanted.Args, given.Args) { |
| 433 | + return true |
| 434 | + } |
| 435 | + if !reflect.DeepEqual(wanted.Command, given.Command) { |
| 436 | + return true |
| 437 | + } |
| 438 | + if !reflect.DeepEqual(wanted.Env, given.Env) { |
| 439 | + return true |
| 440 | + } |
| 441 | + if !reflect.DeepEqual(wanted.EnvFrom, given.EnvFrom) { |
| 442 | + return true |
| 443 | + } |
| 444 | + if wanted.Image != given.Image { |
| 445 | + return true |
| 446 | + } |
| 447 | + if wanted.ImagePullPolicy != given.ImagePullPolicy { |
| 448 | + if wanted.ImagePullPolicy != "Always" || !strings.HasSuffix(given.Image, ":latest") { |
| 449 | + return true |
| 450 | + } |
| 451 | + } |
| 452 | + if wanted.Lifecycle != given.Lifecycle { |
| 453 | + return true |
| 454 | + } |
| 455 | + if wanted.LivenessProbe != given.LivenessProbe { |
| 456 | + return true |
| 457 | + } |
| 458 | + if !reflect.DeepEqual(wanted.Ports, given.Ports) { |
| 459 | + return true |
| 460 | + } |
| 461 | + if wanted.ReadinessProbe != given.ReadinessProbe { |
| 462 | + return true |
| 463 | + } |
| 464 | + if !reflect.DeepEqual(wanted.Resources, given.Resources) { |
| 465 | + return true |
| 466 | + } |
| 467 | + if wanted.SecurityContext != given.SecurityContext { |
| 468 | + return true |
| 469 | + } |
| 470 | + if wanted.Stdin != given.Stdin { |
| 471 | + return true |
| 472 | + } |
| 473 | + if wanted.StdinOnce != given.StdinOnce { |
| 474 | + return true |
| 475 | + } |
| 476 | + if wanted.TerminationMessagePath != given.TerminationMessagePath { |
| 477 | + return true |
| 478 | + } |
| 479 | + if wanted.TerminationMessagePolicy != given.TerminationMessagePolicy { |
| 480 | + return true |
| 481 | + } |
| 482 | + if wanted.TTY != given.TTY { |
| 483 | + return true |
| 484 | + } |
| 485 | + if !reflect.DeepEqual(wanted.VolumeDevices, given.VolumeDevices) { |
| 486 | + return true |
| 487 | + } |
| 488 | + if !reflect.DeepEqual(wanted.VolumeMounts, given.VolumeMounts) { |
| 489 | + return true |
| 490 | + } |
| 491 | + if wanted.WorkingDir != given.WorkingDir { |
| 492 | + return true |
| 493 | + } |
| 494 | + |
| 495 | + return false |
| 496 | +} |
| 497 | + |
400 | 498 | // resourcesRequireRotation returns true if the resource requirements have changed such that a rotation is required |
401 | 499 | func resourcesRequireRotation(wanted, given v1.ResourceRequirements) bool { |
402 | 500 | checkList := func(wanted, given v1.ResourceList) bool { |
|
0 commit comments