@@ -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
}
@@ -700,7 +701,7 @@ func (r *RootPodReconciler) createVolumes(ctx context.Context, lr *leafUtils.Lea
700
701
return nil
701
702
}
702
703
703
- func (r * RootPodReconciler ) CreatePodInLeafCluster (ctx context.Context , lr * leafUtils.LeafResource , pod * corev1.Pod ) error {
704
+ func (r * RootPodReconciler ) CreatePodInLeafCluster (ctx context.Context , lr * leafUtils.LeafResource , pod * corev1.Pod , nodeSelector kosmosv1alpha1. NodeSelector ) error {
704
705
if err := podutils .PopulateEnvironmentVariables (ctx , pod , r .envResourceManager ); err != nil {
705
706
// span.SetStatus(err)
706
707
return err
@@ -711,7 +712,7 @@ func (r *RootPodReconciler) CreatePodInLeafCluster(ctx context.Context, lr *leaf
711
712
return fmt .Errorf ("clusternode info is nil , name: %s" , pod .Spec .NodeName )
712
713
}
713
714
714
- basicPod := podutils .FitPod (pod , lr .IgnoreLabels , clusterNodeInfo .LeafMode == leafUtils . ALL )
715
+ basicPod := podutils .FitPod (pod , lr .IgnoreLabels , clusterNodeInfo .LeafMode , nodeSelector )
715
716
klog .V (4 ).Infof ("Creating pod %v/%+v" , pod .Namespace , pod .Name )
716
717
717
718
// create ns
@@ -765,24 +766,28 @@ func (r *RootPodReconciler) CreatePodInLeafCluster(ctx context.Context, lr *leaf
765
766
return nil
766
767
}
767
768
768
- func (r * RootPodReconciler ) UpdatePodInLeafCluster (ctx context.Context , lr * leafUtils.LeafResource , rootpod * corev1.Pod , leafpod * corev1.Pod ) error {
769
+ func (r * RootPodReconciler ) UpdatePodInLeafCluster (ctx context.Context , lr * leafUtils.LeafResource , rootPod * corev1.Pod , leafPod * corev1.Pod , nodeSelector kosmosv1alpha1. NodeSelector ) error {
769
770
// TODO: update env
770
771
// TODO: update config secret pv pvc ...
771
- klog .V (4 ).Infof ("Updating pod %v/%+v" , rootpod .Namespace , rootpod .Name )
772
+ klog .V (4 ).Infof ("Updating pod %v/%+v" , rootPod .Namespace , rootPod .Name )
772
773
773
- if ! podutils .IsKosmosPod (leafpod ) {
774
+ if ! podutils .IsKosmosPod (leafPod ) {
774
775
klog .V (4 ).Info ("Pod is not created by kosmos tree, ignore" )
775
776
return nil
776
777
}
777
778
// not used
778
- podutils .FitLabels (leafpod .ObjectMeta .Labels , lr .IgnoreLabels )
779
- podCopy := leafpod .DeepCopy ()
779
+ podutils .FitLabels (leafPod .ObjectMeta .Labels , lr .IgnoreLabels )
780
+ podCopy := leafPod .DeepCopy ()
780
781
// util.GetUpdatedPod update PodCopy container image, annotations, labels.
781
782
// recover toleration, affinity, tripped ignore labels.
782
- podutils .GetUpdatedPod (podCopy , rootpod , lr .IgnoreLabels )
783
- if reflect .DeepEqual (leafpod .Spec , podCopy .Spec ) &&
784
- reflect .DeepEqual (leafpod .Annotations , podCopy .Annotations ) &&
785
- reflect .DeepEqual (leafpod .Labels , podCopy .Labels ) {
783
+ clusterNodeInfo := r .GlobalLeafManager .GetClusterNode (rootPod .Spec .NodeName )
784
+ if clusterNodeInfo == nil {
785
+ return fmt .Errorf ("clusternode info is nil , name: %s" , rootPod .Spec .NodeName )
786
+ }
787
+ podutils .GetUpdatedPod (podCopy , rootPod , lr .IgnoreLabels , clusterNodeInfo .LeafMode , nodeSelector )
788
+ if reflect .DeepEqual (leafPod .Spec , podCopy .Spec ) &&
789
+ reflect .DeepEqual (leafPod .Annotations , podCopy .Annotations ) &&
790
+ reflect .DeepEqual (leafPod .Labels , podCopy .Labels ) {
786
791
return nil
787
792
}
788
793
@@ -798,7 +803,7 @@ func (r *RootPodReconciler) UpdatePodInLeafCluster(ctx context.Context, lr *leaf
798
803
if err != nil {
799
804
return fmt .Errorf ("could not update pod: %v" , err )
800
805
}
801
- klog .V (4 ).Infof ("Update pod %v/%+v success " , rootpod .Namespace , rootpod .Name )
806
+ klog .V (4 ).Infof ("Update pod %v/%+v success " , rootPod .Namespace , rootPod .Name )
802
807
return nil
803
808
}
804
809
0 commit comments