Skip to content

Commit

Permalink
keep back compatibility with old sts
Browse files Browse the repository at this point in the history
  • Loading branch information
cofyc committed Dec 5, 2019
1 parent 7bdfbbc commit 1b60283
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 84 deletions.
72 changes: 36 additions & 36 deletions pkg/manager/member/pd_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,41 @@ func (pmm *pdMemberManager) getNewPDSetForTidbCluster(tc *v1alpha1.TidbCluster)
Value: tc.Spec.Timezone,
},
}
podSpec := corev1.PodSpec{
SchedulerName: tc.Spec.SchedulerName,
Affinity: tc.Spec.PD.Affinity,
NodeSelector: tc.Spec.PD.NodeSelector,
HostNetwork: tc.Spec.PD.HostNetwork,
Containers: []corev1.Container{
{
Name: v1alpha1.PDMemberType.String(),
Image: tc.Spec.PD.Image,
Command: []string{"/bin/sh", "/usr/local/bin/pd_start_script.sh"},
ImagePullPolicy: tc.Spec.PD.ImagePullPolicy,
Ports: []corev1.ContainerPort{
{
Name: "server",
ContainerPort: int32(2380),
Protocol: corev1.ProtocolTCP,
},
{
Name: "client",
ContainerPort: int32(2379),
Protocol: corev1.ProtocolTCP,
},
},
VolumeMounts: volMounts,
Resources: util.ResourceRequirement(tc.Spec.PD.ContainerSpec),
},
},
RestartPolicy: corev1.RestartPolicyAlways,
Tolerations: tc.Spec.PD.Tolerations,
Volumes: vols,
SecurityContext: tc.Spec.PD.PodSecurityContext,
}

dnsPolicy := corev1.DNSClusterFirst // same as k8s defaults
if tc.Spec.PD.HostNetwork {
dnsPolicy = corev1.DNSClusterFirstWithHostNet
podSpec.DNSPolicy = corev1.DNSClusterFirstWithHostNet
env = append(env, corev1.EnvVar{
Name: "POD_NAME",
ValueFrom: &corev1.EnvVarSource{
Expand All @@ -524,6 +555,8 @@ func (pmm *pdMemberManager) getNewPDSetForTidbCluster(tc *v1alpha1.TidbCluster)
})
}

podSpec.Containers[0].Env = env

pdSet := &apps.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: setName,
Expand All @@ -539,40 +572,7 @@ func (pmm *pdMemberManager) getNewPDSetForTidbCluster(tc *v1alpha1.TidbCluster)
Labels: pdLabel.Labels(),
Annotations: podAnnotations,
},
Spec: corev1.PodSpec{
SchedulerName: tc.Spec.SchedulerName,
Affinity: tc.Spec.PD.Affinity,
NodeSelector: tc.Spec.PD.NodeSelector,
HostNetwork: tc.Spec.PD.HostNetwork,
DNSPolicy: dnsPolicy,
Containers: []corev1.Container{
{
Name: v1alpha1.PDMemberType.String(),
Image: tc.Spec.PD.Image,
Command: []string{"/bin/sh", "/usr/local/bin/pd_start_script.sh"},
ImagePullPolicy: tc.Spec.PD.ImagePullPolicy,
Ports: []corev1.ContainerPort{
{
Name: "server",
ContainerPort: int32(2380),
Protocol: corev1.ProtocolTCP,
},
{
Name: "client",
ContainerPort: int32(2379),
Protocol: corev1.ProtocolTCP,
},
},
VolumeMounts: volMounts,
Resources: util.ResourceRequirement(tc.Spec.PD.ContainerSpec),
Env: env,
},
},
RestartPolicy: corev1.RestartPolicyAlways,
Tolerations: tc.Spec.PD.Tolerations,
Volumes: vols,
SecurityContext: tc.Spec.PD.PodSecurityContext,
},
Spec: podSpec,
},
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{
{
Expand Down
28 changes: 14 additions & 14 deletions pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,20 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust
},
})

dnsPolicy := corev1.DNSClusterFirst // same as k8s defaults
podSpec := corev1.PodSpec{
SchedulerName: tc.Spec.SchedulerName,
Affinity: tc.Spec.TiDB.Affinity,
NodeSelector: tc.Spec.TiDB.NodeSelector,
Containers: containers,
RestartPolicy: corev1.RestartPolicyAlways,
Tolerations: tc.Spec.TiDB.Tolerations,
Volumes: vols,
SecurityContext: tc.Spec.TiDB.PodSecurityContext,
HostNetwork: tc.Spec.TiDB.HostNetwork,
}

if tc.Spec.TiDB.HostNetwork {
dnsPolicy = corev1.DNSClusterFirstWithHostNet
podSpec.DNSPolicy = corev1.DNSClusterFirstWithHostNet
}

tidbLabel := label.New().Instance(instanceName).TiDB()
Expand All @@ -351,18 +362,7 @@ func (tmm *tidbMemberManager) getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbClust
Labels: tidbLabel.Labels(),
Annotations: podAnnotations,
},
Spec: corev1.PodSpec{
SchedulerName: tc.Spec.SchedulerName,
Affinity: tc.Spec.TiDB.Affinity,
NodeSelector: tc.Spec.TiDB.NodeSelector,
Containers: containers,
RestartPolicy: corev1.RestartPolicyAlways,
Tolerations: tc.Spec.TiDB.Tolerations,
Volumes: vols,
SecurityContext: tc.Spec.TiDB.PodSecurityContext,
HostNetwork: tc.Spec.TiDB.HostNetwork,
DNSPolicy: dnsPolicy,
},
Spec: podSpec,
},
ServiceName: controller.TiDBPeerMemberName(tcName),
PodManagementPolicy: apps.ParallelPodManagement,
Expand Down
69 changes: 35 additions & 34 deletions pkg/manager/member/tikv_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,39 @@ func (tkmm *tikvMemberManager) getNewSetForTidbCluster(tc *v1alpha1.TidbCluster)
},
}

dnsPolicy := corev1.DNSClusterFirst // same as k8s defaults
podSpec := corev1.PodSpec{
SchedulerName: tc.Spec.SchedulerName,
Affinity: tc.Spec.TiKV.Affinity,
NodeSelector: tc.Spec.TiKV.NodeSelector,
HostNetwork: tc.Spec.TiKV.HostNetwork,
Containers: []corev1.Container{
{
Name: v1alpha1.TiKVMemberType.String(),
Image: tc.Spec.TiKV.Image,
Command: []string{"/bin/sh", "/usr/local/bin/tikv_start_script.sh"},
ImagePullPolicy: tc.Spec.TiKV.ImagePullPolicy,
SecurityContext: &corev1.SecurityContext{
Privileged: &tc.Spec.TiKV.Privileged,
},
Ports: []corev1.ContainerPort{
{
Name: "server",
ContainerPort: int32(20160),
Protocol: corev1.ProtocolTCP,
},
},
VolumeMounts: volMounts,
Resources: util.ResourceRequirement(tc.Spec.TiKV.ContainerSpec),
},
},
RestartPolicy: corev1.RestartPolicyAlways,
Tolerations: tc.Spec.TiKV.Tolerations,
Volumes: vols,
SecurityContext: tc.Spec.TiKV.PodSecurityContext,
}

if tc.Spec.TiKV.HostNetwork {
dnsPolicy = corev1.DNSClusterFirstWithHostNet
podSpec.DNSPolicy = corev1.DNSClusterFirstWithHostNet
env = append(env, corev1.EnvVar{
Name: "POD_NAME",
ValueFrom: &corev1.EnvVarSource{
Expand All @@ -360,6 +390,8 @@ func (tkmm *tikvMemberManager) getNewSetForTidbCluster(tc *v1alpha1.TidbCluster)
})
}

podSpec.Containers[0].Env = env

tikvset := &apps.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: setName,
Expand All @@ -375,38 +407,7 @@ func (tkmm *tikvMemberManager) getNewSetForTidbCluster(tc *v1alpha1.TidbCluster)
Labels: tikvLabel.Labels(),
Annotations: podAnnotations,
},
Spec: corev1.PodSpec{
SchedulerName: tc.Spec.SchedulerName,
Affinity: tc.Spec.TiKV.Affinity,
NodeSelector: tc.Spec.TiKV.NodeSelector,
HostNetwork: tc.Spec.TiKV.HostNetwork,
DNSPolicy: dnsPolicy,
Containers: []corev1.Container{
{
Name: v1alpha1.TiKVMemberType.String(),
Image: tc.Spec.TiKV.Image,
Command: []string{"/bin/sh", "/usr/local/bin/tikv_start_script.sh"},
ImagePullPolicy: tc.Spec.TiKV.ImagePullPolicy,
SecurityContext: &corev1.SecurityContext{
Privileged: &tc.Spec.TiKV.Privileged,
},
Ports: []corev1.ContainerPort{
{
Name: "server",
ContainerPort: int32(20160),
Protocol: corev1.ProtocolTCP,
},
},
VolumeMounts: volMounts,
Resources: util.ResourceRequirement(tc.Spec.TiKV.ContainerSpec),
Env: env,
},
},
RestartPolicy: corev1.RestartPolicyAlways,
Tolerations: tc.Spec.TiKV.Tolerations,
Volumes: vols,
SecurityContext: tc.Spec.TiKV.PodSecurityContext,
},
Spec: podSpec,
},
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{
tkmm.volumeClaimTemplate(q, v1alpha1.TiKVMemberType.String(), &storageClassName),
Expand Down

0 comments on commit 1b60283

Please sign in to comment.