runtime: add WithVolume options and k8s support (#2032)
* runtime: add WithVolume option * Fix pointer * k8s: fix template * k8s: fix template * k8s: fix template
This commit is contained in:
@@ -119,6 +119,20 @@ func newService(s *runtime.Service, c runtime.CreateOptions) *service {
|
||||
kdeploy.Spec.Template.PodSpec.Containers[0].Resources = &client.ResourceRequirements{Limits: resLimits}
|
||||
}
|
||||
|
||||
// mount volumes
|
||||
var volumes []client.Volume
|
||||
var mounts []client.VolumeMount
|
||||
for name, path := range c.Volumes {
|
||||
volumes = append(volumes, client.Volume{
|
||||
Name: name,
|
||||
PersistentVolumeClaim: client.PersistentVolumeClaimVolumeSource{ClaimName: name},
|
||||
})
|
||||
|
||||
mounts = append(mounts, client.VolumeMount{Name: name, MountPath: path})
|
||||
}
|
||||
kdeploy.Spec.Template.PodSpec.Volumes = volumes
|
||||
kdeploy.Spec.Template.PodSpec.Containers[0].VolumeMounts = mounts
|
||||
|
||||
return &service{
|
||||
Service: s,
|
||||
kservice: kservice,
|
||||
|
||||
@@ -86,6 +86,8 @@ type CreateOptions struct {
|
||||
Secrets map[string]string
|
||||
// Resources to allocate the service
|
||||
Resources *Resources
|
||||
// Volumes to mount
|
||||
Volumes map[string]string
|
||||
}
|
||||
|
||||
// ReadOptions queries runtime services
|
||||
@@ -178,6 +180,17 @@ func WithOutput(out io.Writer) CreateOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithVolume adds a volume to be mounted
|
||||
func WithVolume(name, path string) CreateOption {
|
||||
return func(o *CreateOptions) {
|
||||
if o.Volumes == nil {
|
||||
o.Volumes = map[string]string{name: path}
|
||||
} else {
|
||||
o.Volumes[name] = path
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ResourceLimits sets the resources for the service to use
|
||||
func ResourceLimits(r *Resources) CreateOption {
|
||||
return func(o *CreateOptions) {
|
||||
|
||||
Reference in New Issue
Block a user