mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 19:13:34 +00:00
chore: introduce VolumeSpec supporting different volume types (bind, volume, tmpfs)
This commit is contained in:
@@ -68,8 +68,8 @@ func NewRunCommand() *cobra.Command {
|
|||||||
cmd.Flags().StringSliceVarP(&opts.publish, "publish", "p", nil,
|
cmd.Flags().StringSliceVarP(&opts.publish, "publish", "p", nil,
|
||||||
"Publish a service port to make it accessible outside the cluster. Can be specified multiple times.\n"+
|
"Publish a service port to make it accessible outside the cluster. Can be specified multiple times.\n"+
|
||||||
"Format: [hostname:][load_balancer_port:]container_port[/protocol] or [host_ip:]:host_port:container_port[/protocol]@host\n"+
|
"Format: [hostname:][load_balancer_port:]container_port[/protocol] or [host_ip:]:host_port:container_port[/protocol]@host\n"+
|
||||||
"Supported protocols: tcp, udp, http, https (default is tcp). If a hostname for http(s) port is not specified,\n"+
|
"Supported protocols: tcp, udp, http, https (default is tcp). If a hostname for http(s) port is not specified\n"+
|
||||||
"service-name.cluster-domain will be used as the hostname.\n"+
|
"and a cluster domain is reserved, service-name.cluster-domain will be used as the hostname.\n"+
|
||||||
"Examples:\n"+
|
"Examples:\n"+
|
||||||
" -p 8080/https Publish port 8080 as HTTPS via load balancer with default service-name.cluster-domain hostname\n"+
|
" -p 8080/https Publish port 8080 as HTTPS via load balancer with default service-name.cluster-domain hostname\n"+
|
||||||
" -p app.example.com:8080/https Publish port 8080 as HTTPS via load balancer with custom hostname\n"+
|
" -p app.example.com:8080/https Publish port 8080 as HTTPS via load balancer with custom hostname\n"+
|
||||||
|
|||||||
+2
-1
@@ -115,7 +115,8 @@ type ContainerSpec struct {
|
|||||||
// PullPolicy determines when to pull the image from the registry or use the image already available in the cluster.
|
// PullPolicy determines when to pull the image from the registry or use the image already available in the cluster.
|
||||||
// Default is PullPolicyMissing if empty.
|
// Default is PullPolicyMissing if empty.
|
||||||
PullPolicy string
|
PullPolicy string
|
||||||
// List of volumes to bind mount into the container.
|
// Volumes is list of data volumes to mount into the container.
|
||||||
|
// TODO: replace with []VolumeSpec
|
||||||
Volumes []string
|
Volumes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types/mount"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// VolumeTypeBind is the type for mounting a host path.
|
||||||
|
VolumeTypeBind = "bind"
|
||||||
|
// VolumeTypeVolume is the type for mounting a managed volume.
|
||||||
|
VolumeTypeVolume = "volume"
|
||||||
|
// VolumeTypeTmpfs is the type for mounting a temporary file system stored in the host memory.
|
||||||
|
VolumeTypeTmpfs = "tmpfs"
|
||||||
|
|
||||||
|
// SELinuxShared share the volume content.
|
||||||
|
SELinuxShared = "z"
|
||||||
|
// SELinuxUnshared label content as private unshared.
|
||||||
|
SELinuxUnshared = "Z"
|
||||||
|
)
|
||||||
|
|
||||||
|
type VolumeSpec struct {
|
||||||
|
Type string
|
||||||
|
Source string
|
||||||
|
Target string
|
||||||
|
ReadOnly bool
|
||||||
|
Bind *VolumeBind
|
||||||
|
// TODO: add options for tmpfs.
|
||||||
|
}
|
||||||
|
|
||||||
|
type VolumeBind struct {
|
||||||
|
CreateHostPath bool
|
||||||
|
Propagation mount.Propagation
|
||||||
|
SELinux string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *VolumeSpec) Validate() error {
|
||||||
|
switch v.Type {
|
||||||
|
case VolumeTypeBind, VolumeTypeVolume:
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid volume type: '%s'", v.Type)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(v.Target, "/") {
|
||||||
|
return fmt.Errorf("invalid volume target: '%s', must be an absolute path in the container", v.Target)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user