in pkg/resources/statefulset/mysqld_statefulset.go [319:368]
func (mss *mysqldStatefulSet) NewStatefulSet(cs *ndbconfig.ConfigSummary, nc *v1.NdbCluster) (*appsv1.StatefulSet, error) {
statefulSet := mss.newStatefulSet(nc, cs)
statefulSetSpec := &statefulSet.Spec
// Fill in MySQL Server specific details
replicas := nc.GetMySQLServerNodeCount()
statefulSetSpec.Replicas = &replicas
// Set pod management policy to start MySQL Servers in parallel
statefulSetSpec.PodManagementPolicy = appsv1.ParallelPodManagement
// Update statefulset annotation
statefulSetAnnotations := statefulSet.GetAnnotations()
statefulSetAnnotations[RootPasswordSecret], _ = resources.GetMySQLRootPasswordSecretName(nc)
// Add VolumeClaimTemplate if data node PVC Spec exists
if nc.Spec.MysqlNode.PVCSpec != nil {
statefulSetSpec.VolumeClaimTemplates = []corev1.PersistentVolumeClaim{
// This PVC will be used as a template and an actual PVC will be created by the
// statefulset controller with name "<data-dir-vol-name(i.e mysqld-data-vol)>-<pod-name>"
*newPVC(nc, mss.getDataDirVolumeName(), nc.Spec.MysqlNode.PVCSpec),
}
}
// Update template pod spec
podSpec := &statefulSetSpec.Template.Spec
podSpec.InitContainers = append(podSpec.InitContainers, mss.getInitDBContainer(nc))
podSpec.Containers = mss.getContainers(nc)
podVolumes, err := mss.getPodVolumes(nc)
if err != nil {
klog.Errorf("Failed to get pod volumes for the statefulset %s", statefulSet.Name)
return nil, err
}
podSpec.Volumes = append(podSpec.Volumes, podVolumes...)
// Set default AntiAffinity rules
podSpec.Affinity = &corev1.Affinity{
PodAntiAffinity: mss.getPodAntiAffinity(),
}
// Copy down any podSpec specified via CRD
CopyPodSpecFromNdbPodSpec(podSpec, nc.Spec.MysqlNode.NdbPodSpec)
// Annotate the spec template with my.cnf version to trigger
// an update of MySQL Servers when my.cnf changes.
podAnnotations := statefulSetSpec.Template.GetAnnotations()
podAnnotations[LastAppliedMySQLServerConfigVersion] = strconv.FormatInt(int64(cs.MySQLServerConfigVersion), 10)
return statefulSet, nil
}