@@ -735,6 +735,8 @@ func convertProtoToMysqlCrd(req proto.Param, mysqlCrd proto.MysqlCrd) *mysqloper
735
735
ServiceType : convertServiceTypeToProto (mysqlCrd .Master .ServiceType ),
736
736
ServiceWhiteList : mysqlCrd .Master .ServiceWhiteList ,
737
737
Env : convertProtoToEnvVar (mysqlCrd .Master .Env ),
738
+ Affinity : convertNodeSpecToV1Affinity (& mysqlCrd .Master ),
739
+ Tolerations : convertProtoToTolerations (mysqlCrd .Master .Tolerations ),
738
740
},
739
741
Status : mysqloperatorv1.MysqlStatus {
740
742
ObservedGeneration : mysqlCrd .Master .Status .ObservedGeneration ,
@@ -764,6 +766,8 @@ func convertProtoToMysqlCrd(req proto.Param, mysqlCrd proto.MysqlCrd) *mysqloper
764
766
ServiceType : convertServiceTypeToProto (mysqlCrd .Slave .ServiceType ),
765
767
ServiceWhiteList : mysqlCrd .Slave .ServiceWhiteList ,
766
768
Env : convertProtoToEnvVar (mysqlCrd .Slave .Env ),
769
+ Affinity : convertNodeSpecToV1Affinity (& mysqlCrd .Slave ),
770
+ Tolerations : convertProtoToTolerations (mysqlCrd .Slave .Tolerations ),
767
771
},
768
772
Status : mysqloperatorv1.MysqlStatus {
769
773
ObservedGeneration : mysqlCrd .Slave .Status .ObservedGeneration ,
@@ -796,6 +800,8 @@ func convertMysqlCrdToProto(m *mysqloperatorv1.MysqlOperator) proto.MysqlCrd {
796
800
ServiceType : convertProtoToServiceType (m .Spec .MasterSpec .Spec .ServiceType ),
797
801
ServiceWhiteList : m .Spec .MasterSpec .Spec .ServiceWhiteList ,
798
802
Env : convertEnvVarToProto (m .Spec .MasterSpec .Spec .Env ),
803
+ Affinity : convertMysqlSpecToNodeSpecV1Affinity (& m .Spec .MasterSpec .Spec ),
804
+ Tolerations : convertTolerationsToProto (m .Spec .MasterSpec .Spec .Tolerations ),
799
805
Status : proto.Status {
800
806
ObservedGeneration : m .Spec .MasterSpec .Status .ObservedGeneration ,
801
807
Replicas : m .Spec .MasterSpec .Status .Replicas ,
@@ -819,6 +825,8 @@ func convertMysqlCrdToProto(m *mysqloperatorv1.MysqlOperator) proto.MysqlCrd {
819
825
ServiceType : convertProtoToServiceType (m .Spec .SlaveSpec .Spec .ServiceType ),
820
826
ServiceWhiteList : m .Spec .SlaveSpec .Spec .ServiceWhiteList ,
821
827
Env : convertEnvVarToProto (m .Spec .SlaveSpec .Spec .Env ),
828
+ Affinity : convertMysqlSpecToNodeSpecV1Affinity (& m .Spec .SlaveSpec .Spec ),
829
+ Tolerations : convertTolerationsToProto (m .Spec .SlaveSpec .Spec .Tolerations ),
822
830
Status : proto.Status {
823
831
ObservedGeneration : m .Spec .SlaveSpec .Status .ObservedGeneration ,
824
832
Replicas : m .Spec .SlaveSpec .Status .Replicas ,
@@ -833,6 +841,39 @@ func convertMysqlCrdToProto(m *mysqloperatorv1.MysqlOperator) proto.MysqlCrd {
833
841
}
834
842
}
835
843
844
+ func convertNodeSpecToV1Affinity (v * proto.NodeSpec ) * corev1.Affinity {
845
+ var in * proto.Affinity
846
+ if v .Affinity == nil {
847
+ in = nil
848
+ } else {
849
+ in = v .Affinity
850
+ }
851
+ aft := convertProtoToAffinity (in )
852
+ return aft
853
+ }
854
+
855
+ func convertRedisSpecToNodeSpecV1Affinity (v * redisoperatorv1.RedisSpec ) * proto.Affinity {
856
+ var in * corev1.Affinity
857
+ if v .Affinity == nil {
858
+ in = nil
859
+ } else {
860
+ in = v .Affinity
861
+ }
862
+ aft := convertAffinityToProto (in )
863
+ return aft
864
+ }
865
+
866
+ func convertMysqlSpecToNodeSpecV1Affinity (v * mysqloperatorv1.MysqlSpec ) * proto.Affinity {
867
+ var in * corev1.Affinity
868
+ if v .Affinity == nil {
869
+ in = nil
870
+ } else {
871
+ in = v .Affinity
872
+ }
873
+ aft := convertAffinityToProto (in )
874
+ return aft
875
+ }
876
+
836
877
func convertProtoToRedisCrd (req proto.Param , redisCrd proto.RedisCrd ) * redisoperatorv1.RedisOperator {
837
878
masterReplicas := redisCrd .Master .Replicas
838
879
var a int32
@@ -872,6 +913,8 @@ func convertProtoToRedisCrd(req proto.Param, redisCrd proto.RedisCrd) *redisoper
872
913
ServiceType : convertServiceTypeToProto (redisCrd .Master .ServiceType ),
873
914
ServiceWhiteList : redisCrd .Master .ServiceWhiteList ,
874
915
Env : convertProtoToEnvVar (redisCrd .Master .Env ),
916
+ Affinity : convertNodeSpecToV1Affinity (& redisCrd .Master ),
917
+ Tolerations : convertProtoToTolerations (redisCrd .Master .Tolerations ),
875
918
},
876
919
Status : redisoperatorv1.RedisStatus {
877
920
ObservedGeneration : redisCrd .Master .Status .ObservedGeneration ,
@@ -901,6 +944,8 @@ func convertProtoToRedisCrd(req proto.Param, redisCrd proto.RedisCrd) *redisoper
901
944
ServiceType : convertServiceTypeToProto (redisCrd .Slave .ServiceType ),
902
945
ServiceWhiteList : redisCrd .Slave .ServiceWhiteList ,
903
946
Env : convertProtoToEnvVar (redisCrd .Slave .Env ),
947
+ Affinity : convertNodeSpecToV1Affinity (& redisCrd .Slave ),
948
+ Tolerations : convertProtoToTolerations (redisCrd .Slave .Tolerations ),
904
949
},
905
950
Status : redisoperatorv1.RedisStatus {
906
951
ObservedGeneration : redisCrd .Slave .Status .ObservedGeneration ,
@@ -933,6 +978,8 @@ func convertRedisCrdToProto(v *redisoperatorv1.RedisOperator) proto.RedisCrd {
933
978
ServiceType : convertProtoToServiceType (v .Spec .MasterSpec .Spec .ServiceType ),
934
979
ServiceWhiteList : v .Spec .MasterSpec .Spec .ServiceWhiteList ,
935
980
Env : convertEnvVarToProto (v .Spec .MasterSpec .Spec .Env ),
981
+ Affinity : convertRedisSpecToNodeSpecV1Affinity (& v .Spec .MasterSpec .Spec ),
982
+ Tolerations : convertTolerationsToProto (v .Spec .MasterSpec .Spec .Tolerations ),
936
983
Status : proto.Status {
937
984
ObservedGeneration : v .Spec .MasterSpec .Status .ObservedGeneration ,
938
985
Replicas : v .Spec .MasterSpec .Status .Replicas ,
@@ -956,6 +1003,8 @@ func convertRedisCrdToProto(v *redisoperatorv1.RedisOperator) proto.RedisCrd {
956
1003
ServiceType : convertProtoToServiceType (v .Spec .SlaveSpec .Spec .ServiceType ),
957
1004
ServiceWhiteList : v .Spec .SlaveSpec .Spec .ServiceWhiteList ,
958
1005
Env : convertEnvVarToProto (v .Spec .SlaveSpec .Spec .Env ),
1006
+ Affinity : convertRedisSpecToNodeSpecV1Affinity (& v .Spec .SlaveSpec .Spec ),
1007
+ Tolerations : convertTolerationsToProto (v .Spec .SlaveSpec .Spec .Tolerations ),
959
1008
Status : proto.Status {
960
1009
ObservedGeneration : v .Spec .SlaveSpec .Status .ObservedGeneration ,
961
1010
Replicas : v .Spec .SlaveSpec .Status .Replicas ,
@@ -1160,6 +1209,33 @@ func convertProtoToHelixSagaCrd(req proto.Param, hs proto.HelixSagaCrd) *helixsa
1160
1209
}
1161
1210
}
1162
1211
1212
+ func convertAffinityToProto (in * corev1.Affinity ) * proto.Affinity {
1213
+ aft := & proto.Affinity {
1214
+ NodeAffinity : & proto.NodeAffinity {
1215
+ RequiredDuringSchedulingIgnoredDuringExecution : & proto.NodeSelector {
1216
+ NodeSelectorTerms : make ([]proto.NodeSelectorTerm , 0 ),
1217
+ },
1218
+ PreferredDuringSchedulingIgnoredDuringExecution : make ([]proto.PreferredSchedulingTerm , 0 ),
1219
+ },
1220
+ }
1221
+ if in != nil &&
1222
+ in .NodeAffinity != nil &&
1223
+ in .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution != nil &&
1224
+ len (in .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms ) > 0 {
1225
+ aft = & proto.Affinity {
1226
+ NodeAffinity : & proto.NodeAffinity {
1227
+ RequiredDuringSchedulingIgnoredDuringExecution : & proto.NodeSelector {
1228
+ NodeSelectorTerms : convertNodeSelectorTermsToProto (in .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms ),
1229
+ },
1230
+ PreferredDuringSchedulingIgnoredDuringExecution : make ([]proto.PreferredSchedulingTerm , 0 ),
1231
+ },
1232
+ //PodAffinity: &proto.PodAffinity{},
1233
+ //PodAntiAffinity: &proto.PodAntiAffinity{},
1234
+ }
1235
+ }
1236
+ return aft
1237
+ }
1238
+
1163
1239
func convertHelixSagaAppToProto (a []helixsagaoperatorv1.HelixSagaApp ) []proto.HelixSagaApp {
1164
1240
res := make ([]proto.HelixSagaApp , 0 )
1165
1241
for _ , v := range a {
@@ -1170,39 +1246,13 @@ func convertHelixSagaAppToProto(a []helixsagaoperatorv1.HelixSagaApp) []proto.He
1170
1246
if v .Spec .Template == "" {
1171
1247
v .Spec .Template = helixsagaoperatorv1 .TemplateTypeStatefulSet
1172
1248
}
1173
- aft := & proto.Affinity {
1174
- NodeAffinity : & proto.NodeAffinity {
1175
- RequiredDuringSchedulingIgnoredDuringExecution : & proto.NodeSelector {
1176
- NodeSelectorTerms : make ([]proto.NodeSelectorTerm , 0 ),
1177
- },
1178
- PreferredDuringSchedulingIgnoredDuringExecution : make ([]proto.PreferredSchedulingTerm , 0 ),
1179
- },
1180
- }
1181
- //if v.Spec.Affinity != nil {
1182
- // klog.Infof("name:%s Affinity:%v", v.Spec.Name, *v.Spec.Affinity)
1183
- // if v.Spec.Affinity.NodeAffinity != nil {
1184
- // klog.Infof("name:%s NodeAffinity:%v", v.Spec.Name, *v.Spec.Affinity.NodeAffinity)
1185
- // if v.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution != nil {
1186
- // klog.Infof("name:%s RequiredDuringSchedulingIgnoredDuringExecution:%v", v.Spec.Name, *v.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution)
1187
- // klog.Infof("name:%s NodeSelectorTerms:%v", v.Spec.Name, v.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms)
1188
- // }
1189
- // }
1190
- //}
1191
- if v .Spec .Affinity != nil &&
1192
- v .Spec .Affinity .NodeAffinity != nil &&
1193
- v .Spec .Affinity .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution != nil &&
1194
- len (v .Spec .Affinity .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms ) > 0 {
1195
- aft = & proto.Affinity {
1196
- NodeAffinity : & proto.NodeAffinity {
1197
- RequiredDuringSchedulingIgnoredDuringExecution : & proto.NodeSelector {
1198
- NodeSelectorTerms : convertNodeSelectorTermsToProto (v .Spec .Affinity .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms ),
1199
- },
1200
- PreferredDuringSchedulingIgnoredDuringExecution : make ([]proto.PreferredSchedulingTerm , 0 ),
1201
- },
1202
- //PodAffinity: &proto.PodAffinity{},
1203
- //PodAntiAffinity: &proto.PodAntiAffinity{},
1204
- }
1249
+ var in * corev1.Affinity
1250
+ if v .Spec .Affinity == nil {
1251
+ in = nil
1252
+ } else {
1253
+ in = v .Spec .Affinity
1205
1254
}
1255
+ aft := convertAffinityToProto (in )
1206
1256
klog .Infof ("proto.HelixSagaApp Name:%v" , v .Spec .Name )
1207
1257
res = append (res , proto.HelixSagaApp {
1208
1258
Spec : proto.HelixSagaAppSpec {
@@ -1359,6 +1409,26 @@ func convertProtoToTolerations(in []proto.Toleration) []corev1.Toleration {
1359
1409
return res
1360
1410
}
1361
1411
1412
+ func convertProtoToAffinity (in * proto.Affinity ) * corev1.Affinity {
1413
+ aft := & corev1.Affinity {}
1414
+ if in != nil &&
1415
+ in .NodeAffinity != nil &&
1416
+ in .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution != nil &&
1417
+ len (in .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms ) > 0 {
1418
+ aft = & corev1.Affinity {
1419
+ NodeAffinity : & corev1.NodeAffinity {
1420
+ RequiredDuringSchedulingIgnoredDuringExecution : & corev1.NodeSelector {
1421
+ NodeSelectorTerms : convertProtoToNodeSelectorTerms (in .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms ),
1422
+ },
1423
+ PreferredDuringSchedulingIgnoredDuringExecution : make ([]corev1.PreferredSchedulingTerm , 0 ),
1424
+ },
1425
+ PodAffinity : & corev1.PodAffinity {},
1426
+ PodAntiAffinity : & corev1.PodAntiAffinity {},
1427
+ }
1428
+ }
1429
+ return aft
1430
+ }
1431
+
1362
1432
func convertProtoToHelixSagaApp (a []proto.HelixSagaApp ) []helixsagaoperatorv1.HelixSagaApp {
1363
1433
res := make ([]helixsagaoperatorv1.HelixSagaApp , 0 )
1364
1434
for _ , v := range a {
@@ -1372,7 +1442,13 @@ func convertProtoToHelixSagaApp(a []proto.HelixSagaApp) []helixsagaoperatorv1.He
1372
1442
if v .Spec .Template == "" {
1373
1443
v .Spec .Template = proto .TemplateTypeStatefulSet
1374
1444
}
1375
- aft := & corev1.Affinity {}
1445
+ var in * proto.Affinity
1446
+ if v .Spec .Affinity == nil {
1447
+ in = nil
1448
+ } else {
1449
+ in = v .Spec .Affinity
1450
+ }
1451
+ aft := convertProtoToAffinity (in )
1376
1452
if v .Spec .Affinity != nil &&
1377
1453
v .Spec .Affinity .NodeAffinity != nil &&
1378
1454
v .Spec .Affinity .NodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution != nil &&
0 commit comments