@@ -27,6 +27,7 @@ import (
27
27
"sigs.k8s.io/controller-runtime/pkg/reconcile"
28
28
29
29
"github.com/kosmos.io/kosmos/cmd/clustertree/cluster-manager/app/options"
30
+ kosmosv1alpha1 "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1"
30
31
"github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/extensions/daemonset"
31
32
leafUtils "github.com/kosmos.io/kosmos/pkg/clustertree/cluster-manager/utils"
32
33
"github.com/kosmos.io/kosmos/pkg/utils"
@@ -198,7 +199,7 @@ func (r *RootPodReconciler) Reconcile(ctx context.Context, request reconcile.Req
198
199
// create pod in leaf
199
200
if err != nil {
200
201
if errors .IsNotFound (err ) {
201
- if err := r .CreatePodInLeafCluster (ctx , lr , & rootpod ); err != nil {
202
+ if err := r .CreatePodInLeafCluster (ctx , lr , & rootpod , r . GlobalLeafManager . GetClusterNode ( rootpod . Spec . NodeName ). LeafNodeSelector ); err != nil {
202
203
klog .Errorf ("create pod inleaf error, err: %s" , err )
203
204
return reconcile.Result {RequeueAfter : RootPodRequeueTime }, nil
204
205
} else {
@@ -212,7 +213,7 @@ func (r *RootPodReconciler) Reconcile(ctx context.Context, request reconcile.Req
212
213
213
214
// update pod in leaf
214
215
if podutils .ShouldEnqueue (leafPod , & rootpod ) {
215
- if err := r .UpdatePodInLeafCluster (ctx , lr , & rootpod , leafPod ); err != nil {
216
+ if err := r .UpdatePodInLeafCluster (ctx , lr , & rootpod , leafPod , r . GlobalLeafManager . GetClusterNode ( rootpod . Spec . NodeName ). LeafNodeSelector ); err != nil {
216
217
return reconcile.Result {RequeueAfter : RootPodRequeueTime }, nil
217
218
}
218
219
}
@@ -698,7 +699,7 @@ func (r *RootPodReconciler) createVolumes(ctx context.Context, lr *leafUtils.Lea
698
699
return nil
699
700
}
700
701
701
- func (r * RootPodReconciler ) CreatePodInLeafCluster (ctx context.Context , lr * leafUtils.LeafResource , pod * corev1.Pod ) error {
702
+ func (r * RootPodReconciler ) CreatePodInLeafCluster (ctx context.Context , lr * leafUtils.LeafResource , pod * corev1.Pod , nodeSelector kosmosv1alpha1. NodeSelector ) error {
702
703
if err := podutils .PopulateEnvironmentVariables (ctx , pod , r .envResourceManager ); err != nil {
703
704
// span.SetStatus(err)
704
705
return err
@@ -709,7 +710,7 @@ func (r *RootPodReconciler) CreatePodInLeafCluster(ctx context.Context, lr *leaf
709
710
return fmt .Errorf ("clusternode info is nil , name: %s" , pod .Spec .NodeName )
710
711
}
711
712
712
- basicPod := podutils .FitPod (pod , lr .IgnoreLabels , clusterNodeInfo .LeafMode == leafUtils . ALL )
713
+ basicPod := podutils .FitPod (pod , lr .IgnoreLabels , clusterNodeInfo .LeafMode , nodeSelector )
713
714
klog .V (4 ).Infof ("Creating pod %v/%+v" , pod .Namespace , pod .Name )
714
715
715
716
// create ns
@@ -763,24 +764,28 @@ func (r *RootPodReconciler) CreatePodInLeafCluster(ctx context.Context, lr *leaf
763
764
return nil
764
765
}
765
766
766
- func (r * RootPodReconciler ) UpdatePodInLeafCluster (ctx context.Context , lr * leafUtils.LeafResource , rootpod * corev1.Pod , leafpod * corev1.Pod ) error {
767
+ func (r * RootPodReconciler ) UpdatePodInLeafCluster (ctx context.Context , lr * leafUtils.LeafResource , rootPod * corev1.Pod , leafPod * corev1.Pod , nodeSelector kosmosv1alpha1. NodeSelector ) error {
767
768
// TODO: update env
768
769
// TODO: update config secret pv pvc ...
769
- klog .V (4 ).Infof ("Updating pod %v/%+v" , rootpod .Namespace , rootpod .Name )
770
+ klog .V (4 ).Infof ("Updating pod %v/%+v" , rootPod .Namespace , rootPod .Name )
770
771
771
- if ! podutils .IsKosmosPod (leafpod ) {
772
+ if ! podutils .IsKosmosPod (leafPod ) {
772
773
klog .V (4 ).Info ("Pod is not created by kosmos tree, ignore" )
773
774
return nil
774
775
}
775
776
// not used
776
- podutils .FitLabels (leafpod .ObjectMeta .Labels , lr .IgnoreLabels )
777
- podCopy := leafpod .DeepCopy ()
777
+ podutils .FitLabels (leafPod .ObjectMeta .Labels , lr .IgnoreLabels )
778
+ podCopy := leafPod .DeepCopy ()
778
779
// util.GetUpdatedPod update PodCopy container image, annotations, labels.
779
780
// recover toleration, affinity, tripped ignore labels.
780
- podutils .GetUpdatedPod (podCopy , rootpod , lr .IgnoreLabels )
781
- if reflect .DeepEqual (leafpod .Spec , podCopy .Spec ) &&
782
- reflect .DeepEqual (leafpod .Annotations , podCopy .Annotations ) &&
783
- reflect .DeepEqual (leafpod .Labels , podCopy .Labels ) {
781
+ clusterNodeInfo := r .GlobalLeafManager .GetClusterNode (rootPod .Spec .NodeName )
782
+ if clusterNodeInfo == nil {
783
+ return fmt .Errorf ("clusternode info is nil , name: %s" , rootPod .Spec .NodeName )
784
+ }
785
+ podutils .GetUpdatedPod (podCopy , rootPod , lr .IgnoreLabels , clusterNodeInfo .LeafMode , nodeSelector )
786
+ if reflect .DeepEqual (leafPod .Spec , podCopy .Spec ) &&
787
+ reflect .DeepEqual (leafPod .Annotations , podCopy .Annotations ) &&
788
+ reflect .DeepEqual (leafPod .Labels , podCopy .Labels ) {
784
789
return nil
785
790
}
786
791
@@ -796,7 +801,7 @@ func (r *RootPodReconciler) UpdatePodInLeafCluster(ctx context.Context, lr *leaf
796
801
if err != nil {
797
802
return fmt .Errorf ("could not update pod: %v" , err )
798
803
}
799
- klog .V (4 ).Infof ("Update pod %v/%+v success " , rootpod .Namespace , rootpod .Name )
804
+ klog .V (4 ).Infof ("Update pod %v/%+v success " , rootPod .Namespace , rootPod .Name )
800
805
return nil
801
806
}
802
807
0 commit comments