diff --git a/internal/dashboard/business/oceanbase/obcluster.go b/internal/dashboard/business/oceanbase/obcluster.go index ef53080e5..7a711fe89 100644 --- a/internal/dashboard/business/oceanbase/obcluster.go +++ b/internal/dashboard/business/oceanbase/obcluster.go @@ -203,12 +203,28 @@ func buildOBClusterTopologyResp(ctx context.Context, obcluster *v1alpha1.OBClust affinities := make([]modelcommon.AffinitySpec, 0) if obzone.Spec.Topology.Affinity != nil { zoneAffinity := obzone.Spec.Topology.Affinity - switch { - case zoneAffinity.NodeAffinity != nil: - for _, term := range zoneAffinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms { - for _, req := range term.MatchExpressions { + if zoneAffinity.NodeAffinity != nil { + zn := zoneAffinity.NodeAffinity + if zn.RequiredDuringSchedulingIgnoredDuringExecution != nil { + for _, term := range zn.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms { + for _, req := range term.MatchExpressions { + affinities = append(affinities, modelcommon.AffinitySpec{ + Type: modelcommon.NodeAffinityType, + SelectorExpression: modelcommon.SelectorExpression{ + Key: req.Key, + Operator: string(req.Operator), + Values: req.Values, + }, + }) + } + } + } + for _, term := range zn.PreferredDuringSchedulingIgnoredDuringExecution { + for _, req := range term.Preference.MatchExpressions { affinities = append(affinities, modelcommon.AffinitySpec{ - Type: modelcommon.NodeAffinityType, + Type: modelcommon.NodeAffinityType, + Weight: term.Weight, + Preferred: true, SelectorExpression: modelcommon.SelectorExpression{ Key: req.Key, Operator: string(req.Operator), @@ -217,8 +233,10 @@ func buildOBClusterTopologyResp(ctx context.Context, obcluster *v1alpha1.OBClust }) } } - case zoneAffinity.PodAffinity != nil: - for _, term := range zoneAffinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution { + } + if zoneAffinity.PodAffinity != nil { + zp := zoneAffinity.PodAffinity + for _, term := range zp.RequiredDuringSchedulingIgnoredDuringExecution { for _, req := range term.LabelSelector.MatchExpressions { affinities = append(affinities, modelcommon.AffinitySpec{ Type: modelcommon.PodAffinityType, @@ -230,8 +248,24 @@ func buildOBClusterTopologyResp(ctx context.Context, obcluster *v1alpha1.OBClust }) } } - case zoneAffinity.PodAntiAffinity != nil: - for _, term := range zoneAffinity.PodAntiAffinity.RequiredDuringSchedulingIgnoredDuringExecution { + for _, term := range zp.PreferredDuringSchedulingIgnoredDuringExecution { + for _, req := range term.PodAffinityTerm.LabelSelector.MatchExpressions { + affinities = append(affinities, modelcommon.AffinitySpec{ + Type: modelcommon.PodAffinityType, + Weight: term.Weight, + Preferred: true, + SelectorExpression: modelcommon.SelectorExpression{ + Key: req.Key, + Operator: string(req.Operator), + Values: req.Values, + }, + }) + } + } + } + if zoneAffinity.PodAntiAffinity != nil { + zpa := zoneAffinity.PodAntiAffinity + for _, term := range zpa.RequiredDuringSchedulingIgnoredDuringExecution { for _, req := range term.LabelSelector.MatchExpressions { affinities = append(affinities, modelcommon.AffinitySpec{ Type: modelcommon.PodAntiAffinityType, @@ -243,14 +277,33 @@ func buildOBClusterTopologyResp(ctx context.Context, obcluster *v1alpha1.OBClust }) } } + for _, term := range zpa.PreferredDuringSchedulingIgnoredDuringExecution { + for _, req := range term.PodAffinityTerm.LabelSelector.MatchExpressions { + affinities = append(affinities, modelcommon.AffinitySpec{ + Type: modelcommon.PodAntiAffinityType, + Weight: term.Weight, + Preferred: true, + SelectorExpression: modelcommon.SelectorExpression{ + Key: req.Key, + Operator: string(req.Operator), + Values: req.Values, + }, + }) + } + } } } - tolerations := make([]modelcommon.KVPair, 0) + tolerations := make([]modelcommon.TolerationSpec, 0) for _, toleration := range obzone.Spec.Topology.Tolerations { - tolerations = append(tolerations, modelcommon.KVPair{ - Key: toleration.Key, - Value: toleration.Value, + tolerations = append(tolerations, modelcommon.TolerationSpec{ + KVPair: modelcommon.KVPair{ + Key: toleration.Key, + Value: toleration.Value, + }, + Operator: string(toleration.Operator), + Effect: string(toleration.Effect), + TolerationSeconds: toleration.TolerationSeconds, }) } respZone := response.OBZone{ diff --git a/internal/dashboard/model/common/common.go b/internal/dashboard/model/common/common.go index d324fb30f..827b89a57 100644 --- a/internal/dashboard/model/common/common.go +++ b/internal/dashboard/model/common/common.go @@ -38,6 +38,15 @@ type AffinityType string type AffinitySpec struct { SelectorExpression `json:",inline"` Type AffinityType `json:"type"` + Weight int32 `json:"weight,omitempty"` + Preferred bool `json:"preferred,omitempty"` +} + +type TolerationSpec struct { + KVPair `json:",inline"` + Operator string `json:"operator"` + Effect string `json:"effect"` + TolerationSeconds *int64 `json:"tolerationSeconds,omitempty"` } type ClusterMode string diff --git a/internal/dashboard/model/response/obcluster.go b/internal/dashboard/model/response/obcluster.go index fa9d9228d..5dc586753 100644 --- a/internal/dashboard/model/response/obcluster.go +++ b/internal/dashboard/model/response/obcluster.go @@ -41,8 +41,8 @@ type OBZone struct { OBServers []OBServer `json:"observers,omitempty"` NodeSelector []common.KVPair `json:"nodeSelector,omitempty"` - Tolerations []common.KVPair `json:"tolerations,omitempty"` - Affinities []common.AffinitySpec `json:"affinities,omitempty"` + Tolerations []common.TolerationSpec `json:"tolerations,omitempty"` + Affinities []common.AffinitySpec `json:"affinities,omitempty"` } type OBMetrics struct {