in pkg/resources/statefulset/mysqld_statefulset.go [60:165]
func (mss *mysqldStatefulSet) getPodVolumes(ndb *v1.NdbCluster) ([]corev1.Volume, error) {
podVolumes := []corev1.Volume{
// Load the healthcheck script via a volume
{
Name: helperScriptsVolName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: ndb.GetConfigMapName(),
},
Items: []corev1.KeyToPath{
{
Key: constants.MysqldInitScript,
Path: constants.MysqldInitScript,
Mode: &ownerCanExecMode,
},
{
Key: constants.MysqldHealthCheckScript,
Path: constants.MysqldHealthCheckScript,
},
},
},
},
},
}
// Create a projected volume source to load all custom init scripts
var initScriptPvs corev1.ProjectedVolumeSource
// Create projections for all the scripts and append it to the initScriptPvs
for configMapName, configMapKeys := range ndb.Spec.MysqlNode.InitScripts {
cm, err := mss.configMapLister.ConfigMaps(ndb.Namespace).Get(configMapName)
if err != nil {
klog.Errorf("Failed to get configMap '%s/%s' : %s", ndb.Namespace, configMapName, err)
return nil, err
}
// Create a VolumeProjection with the configMap name
volProjection := corev1.VolumeProjection{
ConfigMap: &corev1.ConfigMapProjection{
LocalObjectReference: corev1.LocalObjectReference{
Name: configMapName,
},
},
}
appendKeyToPathFromConfigMapKey := func(configMapName, key string, projection *corev1.ConfigMapProjection) {
projection.Items = append(projection.Items, corev1.KeyToPath{
Key: key,
// The configmap name is prefixed to the key name to ensure
// that all scripts run in alphabetical order across config maps.
Path: configMapName + "_" + key + ".sql",
})
}
if len(configMapKeys) == 0 {
// Keys not mentioned - extract all keys
for key := range cm.Data {
appendKeyToPathFromConfigMapKey(configMapName, key, volProjection.ConfigMap)
}
} else {
// Keys from which the sql scripts have to be loaded are given.
for _, key := range configMapKeys {
appendKeyToPathFromConfigMapKey(configMapName, key, volProjection.ConfigMap)
}
}
initScriptPvs.Sources = append(initScriptPvs.Sources, volProjection)
}
// Append the custom init script volume to the podVolumes
podVolumes = append(podVolumes, corev1.Volume{
Name: mysqldInitScriptsVolName,
VolumeSource: corev1.VolumeSource{
Projected: &initScriptPvs,
},
})
if len(ndb.GetMySQLCnf()) > 0 {
// Load the cnf configmap key as a volume
podVolumes = append(podVolumes, corev1.Volume{
Name: mysqldCnfVolName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: ndb.GetConfigMapName(),
},
Items: []corev1.KeyToPath{
{
Key: constants.MySQLConfigKey,
Path: constants.MySQLConfigKey,
},
},
},
},
})
}
// An empty directory volume needs to be provided to the mysql server
// pods if the NdbCluster resource doesn't have any PVCs defined to
// be used with the mysql servers.
if ndb.Spec.MysqlNode.PVCSpec == nil {
podVolumes = append(podVolumes, *mss.getEmptyDirPodVolume(mss.getDataDirVolumeName()))
}
return podVolumes, nil
}