Skip to content

Commit d382a5f

Browse files
authored
Merge pull request #9 from neverCase/alpha-1.20
Alpha 1.20
2 parents 4c9e7a8 + 5785599 commit d382a5f

File tree

18 files changed

+916
-408
lines changed

18 files changed

+916
-408
lines changed

api/handle/k8s_handle.go

Lines changed: 109 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ func convertProtoToMysqlCrd(req proto.Param, mysqlCrd proto.MysqlCrd) *mysqloper
735735
ServiceType: convertServiceTypeToProto(mysqlCrd.Master.ServiceType),
736736
ServiceWhiteList: mysqlCrd.Master.ServiceWhiteList,
737737
Env: convertProtoToEnvVar(mysqlCrd.Master.Env),
738+
Affinity: convertNodeSpecToV1Affinity(&mysqlCrd.Master),
739+
Tolerations: convertProtoToTolerations(mysqlCrd.Master.Tolerations),
738740
},
739741
Status: mysqloperatorv1.MysqlStatus{
740742
ObservedGeneration: mysqlCrd.Master.Status.ObservedGeneration,
@@ -764,6 +766,8 @@ func convertProtoToMysqlCrd(req proto.Param, mysqlCrd proto.MysqlCrd) *mysqloper
764766
ServiceType: convertServiceTypeToProto(mysqlCrd.Slave.ServiceType),
765767
ServiceWhiteList: mysqlCrd.Slave.ServiceWhiteList,
766768
Env: convertProtoToEnvVar(mysqlCrd.Slave.Env),
769+
Affinity: convertNodeSpecToV1Affinity(&mysqlCrd.Slave),
770+
Tolerations: convertProtoToTolerations(mysqlCrd.Slave.Tolerations),
767771
},
768772
Status: mysqloperatorv1.MysqlStatus{
769773
ObservedGeneration: mysqlCrd.Slave.Status.ObservedGeneration,
@@ -796,6 +800,8 @@ func convertMysqlCrdToProto(m *mysqloperatorv1.MysqlOperator) proto.MysqlCrd {
796800
ServiceType: convertProtoToServiceType(m.Spec.MasterSpec.Spec.ServiceType),
797801
ServiceWhiteList: m.Spec.MasterSpec.Spec.ServiceWhiteList,
798802
Env: convertEnvVarToProto(m.Spec.MasterSpec.Spec.Env),
803+
Affinity: convertMysqlSpecToNodeSpecV1Affinity(&m.Spec.MasterSpec.Spec),
804+
Tolerations: convertTolerationsToProto(m.Spec.MasterSpec.Spec.Tolerations),
799805
Status: proto.Status{
800806
ObservedGeneration: m.Spec.MasterSpec.Status.ObservedGeneration,
801807
Replicas: m.Spec.MasterSpec.Status.Replicas,
@@ -819,6 +825,8 @@ func convertMysqlCrdToProto(m *mysqloperatorv1.MysqlOperator) proto.MysqlCrd {
819825
ServiceType: convertProtoToServiceType(m.Spec.SlaveSpec.Spec.ServiceType),
820826
ServiceWhiteList: m.Spec.SlaveSpec.Spec.ServiceWhiteList,
821827
Env: convertEnvVarToProto(m.Spec.SlaveSpec.Spec.Env),
828+
Affinity: convertMysqlSpecToNodeSpecV1Affinity(&m.Spec.SlaveSpec.Spec),
829+
Tolerations: convertTolerationsToProto(m.Spec.SlaveSpec.Spec.Tolerations),
822830
Status: proto.Status{
823831
ObservedGeneration: m.Spec.SlaveSpec.Status.ObservedGeneration,
824832
Replicas: m.Spec.SlaveSpec.Status.Replicas,
@@ -833,6 +841,39 @@ func convertMysqlCrdToProto(m *mysqloperatorv1.MysqlOperator) proto.MysqlCrd {
833841
}
834842
}
835843

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+
836877
func convertProtoToRedisCrd(req proto.Param, redisCrd proto.RedisCrd) *redisoperatorv1.RedisOperator {
837878
masterReplicas := redisCrd.Master.Replicas
838879
var a int32
@@ -872,6 +913,8 @@ func convertProtoToRedisCrd(req proto.Param, redisCrd proto.RedisCrd) *redisoper
872913
ServiceType: convertServiceTypeToProto(redisCrd.Master.ServiceType),
873914
ServiceWhiteList: redisCrd.Master.ServiceWhiteList,
874915
Env: convertProtoToEnvVar(redisCrd.Master.Env),
916+
Affinity: convertNodeSpecToV1Affinity(&redisCrd.Master),
917+
Tolerations: convertProtoToTolerations(redisCrd.Master.Tolerations),
875918
},
876919
Status: redisoperatorv1.RedisStatus{
877920
ObservedGeneration: redisCrd.Master.Status.ObservedGeneration,
@@ -901,6 +944,8 @@ func convertProtoToRedisCrd(req proto.Param, redisCrd proto.RedisCrd) *redisoper
901944
ServiceType: convertServiceTypeToProto(redisCrd.Slave.ServiceType),
902945
ServiceWhiteList: redisCrd.Slave.ServiceWhiteList,
903946
Env: convertProtoToEnvVar(redisCrd.Slave.Env),
947+
Affinity: convertNodeSpecToV1Affinity(&redisCrd.Slave),
948+
Tolerations: convertProtoToTolerations(redisCrd.Slave.Tolerations),
904949
},
905950
Status: redisoperatorv1.RedisStatus{
906951
ObservedGeneration: redisCrd.Slave.Status.ObservedGeneration,
@@ -933,6 +978,8 @@ func convertRedisCrdToProto(v *redisoperatorv1.RedisOperator) proto.RedisCrd {
933978
ServiceType: convertProtoToServiceType(v.Spec.MasterSpec.Spec.ServiceType),
934979
ServiceWhiteList: v.Spec.MasterSpec.Spec.ServiceWhiteList,
935980
Env: convertEnvVarToProto(v.Spec.MasterSpec.Spec.Env),
981+
Affinity: convertRedisSpecToNodeSpecV1Affinity(&v.Spec.MasterSpec.Spec),
982+
Tolerations: convertTolerationsToProto(v.Spec.MasterSpec.Spec.Tolerations),
936983
Status: proto.Status{
937984
ObservedGeneration: v.Spec.MasterSpec.Status.ObservedGeneration,
938985
Replicas: v.Spec.MasterSpec.Status.Replicas,
@@ -956,6 +1003,8 @@ func convertRedisCrdToProto(v *redisoperatorv1.RedisOperator) proto.RedisCrd {
9561003
ServiceType: convertProtoToServiceType(v.Spec.SlaveSpec.Spec.ServiceType),
9571004
ServiceWhiteList: v.Spec.SlaveSpec.Spec.ServiceWhiteList,
9581005
Env: convertEnvVarToProto(v.Spec.SlaveSpec.Spec.Env),
1006+
Affinity: convertRedisSpecToNodeSpecV1Affinity(&v.Spec.SlaveSpec.Spec),
1007+
Tolerations: convertTolerationsToProto(v.Spec.SlaveSpec.Spec.Tolerations),
9591008
Status: proto.Status{
9601009
ObservedGeneration: v.Spec.SlaveSpec.Status.ObservedGeneration,
9611010
Replicas: v.Spec.SlaveSpec.Status.Replicas,
@@ -1160,6 +1209,33 @@ func convertProtoToHelixSagaCrd(req proto.Param, hs proto.HelixSagaCrd) *helixsa
11601209
}
11611210
}
11621211

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+
11631239
func convertHelixSagaAppToProto(a []helixsagaoperatorv1.HelixSagaApp) []proto.HelixSagaApp {
11641240
res := make([]proto.HelixSagaApp, 0)
11651241
for _, v := range a {
@@ -1170,39 +1246,13 @@ func convertHelixSagaAppToProto(a []helixsagaoperatorv1.HelixSagaApp) []proto.He
11701246
if v.Spec.Template == "" {
11711247
v.Spec.Template = helixsagaoperatorv1.TemplateTypeStatefulSet
11721248
}
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
12051254
}
1255+
aft := convertAffinityToProto(in)
12061256
klog.Infof("proto.HelixSagaApp Name:%v", v.Spec.Name)
12071257
res = append(res, proto.HelixSagaApp{
12081258
Spec: proto.HelixSagaAppSpec{
@@ -1359,6 +1409,26 @@ func convertProtoToTolerations(in []proto.Toleration) []corev1.Toleration {
13591409
return res
13601410
}
13611411

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+
13621432
func convertProtoToHelixSagaApp(a []proto.HelixSagaApp) []helixsagaoperatorv1.HelixSagaApp {
13631433
res := make([]helixsagaoperatorv1.HelixSagaApp, 0)
13641434
for _, v := range a {
@@ -1372,7 +1442,13 @@ func convertProtoToHelixSagaApp(a []proto.HelixSagaApp) []helixsagaoperatorv1.He
13721442
if v.Spec.Template == "" {
13731443
v.Spec.Template = proto.TemplateTypeStatefulSet
13741444
}
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)
13761452
if v.Spec.Affinity != nil &&
13771453
v.Spec.Affinity.NodeAffinity != nil &&
13781454
v.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution != nil &&

0 commit comments

Comments
 (0)