forked from LaconicNetwork/kompose
Infer storage type using label (#1456)
Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
This commit is contained in:
+7
-2
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -132,8 +133,12 @@ func ValidateFlags(args []string, cmd *cobra.Command, opt *kobject.ConvertOption
|
||||
log.Fatalf("YAML and JSON format cannot be provided at the same time")
|
||||
}
|
||||
|
||||
if opt.Volumes != "persistentVolumeClaim" && opt.Volumes != "emptyDir" && opt.Volumes != "hostPath" && opt.Volumes != "configMap" {
|
||||
log.Fatal("Unknown Volume type: ", opt.Volumes, ", possible values are: persistentVolumeClaim, hostPath, configMap and emptyDir")
|
||||
if _, ok := kubernetes.ValidVolumeSet[opt.Volumes]; !ok {
|
||||
validVolumesTypes := make([]string, 0)
|
||||
for validVolumeType := range kubernetes.ValidVolumeSet {
|
||||
validVolumesTypes = append(validVolumesTypes, fmt.Sprintf("'%s'", validVolumeType))
|
||||
}
|
||||
log.Fatal("Unknown Volume type: ", opt.Volumes, ", possible values are: ", strings.Join(validVolumesTypes, " "))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ type Kubernetes struct {
|
||||
// PVCRequestSize (Persistent Volume Claim) has default size
|
||||
const PVCRequestSize = "100Mi"
|
||||
|
||||
var ValidVolumeSet = map[string]struct{}{"emptyDir": {}, "hostPath": {}, "configMap": {}, "persistentVolumeClaim": {}}
|
||||
|
||||
const (
|
||||
// DeploymentController is controller type for Deployment
|
||||
DeploymentController = "deployment"
|
||||
@@ -837,11 +839,20 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) (
|
||||
useEmptyVolumes := k.Opt.EmptyVols
|
||||
useHostPath := k.Opt.Volumes == "hostPath"
|
||||
useConfigMap := k.Opt.Volumes == "configMap"
|
||||
|
||||
if k.Opt.Volumes == "emptyDir" {
|
||||
useEmptyVolumes = true
|
||||
}
|
||||
|
||||
// Override volume type if specified in service labels.
|
||||
if vt, ok := service.Labels["kompose.volume.type"]; ok {
|
||||
if _, okk := ValidVolumeSet[vt]; !okk {
|
||||
return nil, nil, nil, nil, fmt.Errorf("invalid volume type %s specified in label 'kompose.volume.type' in service %s", vt, service.Name)
|
||||
}
|
||||
useEmptyVolumes = vt == "emptyDir"
|
||||
useHostPath = vt == "hostPath"
|
||||
useConfigMap = vt == "configMap"
|
||||
}
|
||||
|
||||
// config volumes from secret if present
|
||||
secretsVolumeMounts, secretsVolumes := k.ConfigSecretVolumes(name, service)
|
||||
volumeMounts = append(volumeMounts, secretsVolumeMounts...)
|
||||
@@ -852,7 +863,6 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) (
|
||||
for _, volume := range service.Volumes {
|
||||
// check if ro/rw mode is defined, default rw
|
||||
readonly := len(volume.Mode) > 0 && volume.Mode == "ro"
|
||||
|
||||
if volume.VolumeName == "" {
|
||||
if useEmptyVolumes {
|
||||
volumeName = strings.Replace(volume.PVCName, "claim", "empty", 1)
|
||||
|
||||
Reference in New Issue
Block a user