@@ -661,6 +661,12 @@ func (r *Reconciler) reconcileNifiPod(log zap.Logger, desiredPod *corev1.Pod) (e
661
661
}
662
662
663
663
if err == nil {
664
+ // k8s-objectmatcher options
665
+ opts := []patch.CalculateOption {
666
+ patch .IgnoreStatusFields (),
667
+ patch .IgnoreVolumeClaimTemplateTypeMetaAndStatus (),
668
+ patch .IgnorePDBSelector (),
669
+ }
664
670
// Since toleration does not support patchStrategy:"merge,retainKeys", we need to add all toleration from the current pod if the toleration is set in the CR
665
671
if len (desiredPod .Spec .Tolerations ) > 0 {
666
672
desiredPod .Spec .Tolerations = append (desiredPod .Spec .Tolerations , currentPod .Spec .Tolerations ... )
@@ -674,8 +680,55 @@ func (r *Reconciler) reconcileNifiPod(log zap.Logger, desiredPod *corev1.Pod) (e
674
680
}
675
681
desiredPod .Spec .Tolerations = uniqueTolerations
676
682
}
683
+ // If there are extra initContainers from webhook injections we need to add them
684
+ if len (currentPod .Spec .InitContainers ) > len (desiredPod .Spec .InitContainers ) {
685
+ desiredPod .Spec .InitContainers = append (currentPod .Spec .InitContainers , desiredPod .Spec .InitContainers ... )
686
+ uniqueContainers := []corev1.Container {}
687
+ keys := make (map [string ]bool )
688
+ for _ , c := range desiredPod .Spec .InitContainers {
689
+ if _ , value := keys [c .Name ]; ! value {
690
+ keys [c .Name ] = true
691
+ uniqueContainers = append (uniqueContainers , c )
692
+ }
693
+ }
694
+ desiredPod .Spec .InitContainers = uniqueContainers
695
+ }
696
+ // If there are extra containers from webhook injections we need to add them
697
+ if len (currentPod .Spec .Containers ) > len (desiredPod .Spec .Containers ) {
698
+ desiredPod .Spec .Containers = append (currentPod .Spec .Containers , desiredPod .Spec .Containers ... )
699
+ uniqueContainers := []corev1.Container {}
700
+ keys := make (map [string ]bool )
701
+ for _ , c := range desiredPod .Spec .Containers {
702
+ if _ , value := keys [c .Name ]; ! value {
703
+ keys [c .Name ] = true
704
+ uniqueContainers = append (uniqueContainers , c )
705
+ }
706
+ }
707
+ desiredPod .Spec .Containers = uniqueContainers
708
+ }
709
+ // Remove problematic fields if istio
710
+ if _ , ok := currentPod .Annotations ["istio.io/rev" ]; ok {
711
+ // Prometheus scrape port is overridden by istio injection
712
+ delete (currentPod .Annotations , "prometheus.io/port" )
713
+ delete (desiredPod .Annotations , "prometheus.io/port" )
714
+ // Liveness probe port is overridden by istio injection
715
+ desiredContainer := corev1.Container {}
716
+ for _ , c := range desiredPod .Spec .Containers {
717
+ if c .Name == "nifi" {
718
+ desiredContainer = c
719
+ }
720
+ }
721
+ currentContainers := []corev1.Container {}
722
+ for _ , c := range currentPod .Spec .Containers {
723
+ if c .Name == "nifi" {
724
+ c .LivenessProbe = desiredContainer .LivenessProbe
725
+ }
726
+ currentContainers = append (currentContainers , c )
727
+ }
728
+ currentPod .Spec .Containers = currentContainers
729
+ }
677
730
// Check if the resource actually updated
678
- patchResult , err := patch .DefaultPatchMaker .Calculate (currentPod , desiredPod )
731
+ patchResult , err := patch .DefaultPatchMaker .Calculate (currentPod , desiredPod , opts ... )
679
732
if err != nil {
680
733
log .Error ("could not match pod objects" ,
681
734
zap .String ("clusterName" , r .NifiCluster .Name ),
@@ -697,7 +750,7 @@ func (r *Reconciler) reconcileNifiPod(log zap.Logger, desiredPod *corev1.Pod) (e
697
750
698
751
log .Debug ("pod resource is in sync" ,
699
752
zap .String ("clusterName" , r .NifiCluster .Name ),
700
- zap .String ("podName" , desiredPod .Name ))
753
+ zap .String ("podName" , currentPod .Name ))
701
754
702
755
return nil , k8sutil .PodReady (currentPod )
703
756
}
0 commit comments