create named volume

pull/83/head
iwilltry42 5 years ago
parent deccb0122a
commit cbdeea3bfa
  1. 18
      cli/commands.go
  2. 14
      cli/container.go
  3. 6
      cli/image.go
  4. 2
      vendor/modules.txt

@ -135,6 +135,15 @@ func CreateCluster(c *cli.Context) error {
log.Fatal(err)
}
// create a docker volume for sharing image tarballs with the cluster
imageVolume, err := createImageVolume(c.String("name"))
log.Println("Created docker volume ", imageVolume.Name)
if err != nil {
return err
}
volumes := c.StringSlice("volume")
volumes = append(volumes, fmt.Sprintf("%s:/images", imageVolume.Name))
clusterSpec := &ClusterSpec{
AgentArgs: []string{},
APIPort: *apiPort,
@ -146,7 +155,7 @@ func CreateCluster(c *cli.Context) error {
PortAutoOffset: c.Int("port-auto-offset"),
ServerArgs: k3sServerArgs,
Verbose: c.GlobalBool("verbose"),
Volumes: c.StringSlice("volume"),
Volumes: volumes,
}
// create the server
@ -241,8 +250,8 @@ func DeleteCluster(c *cli.Context) error {
}
}
}
log.Println("...Removing server")
deleteClusterDir(cluster.name)
log.Println("...Removing server")
if err := removeContainer(cluster.server.ID); err != nil {
return fmt.Errorf("ERROR: Couldn't remove server for cluster %s\n%+v", cluster.name, err)
}
@ -251,6 +260,11 @@ func DeleteCluster(c *cli.Context) error {
log.Printf("WARNING: couldn't delete cluster network for cluster %s\n%+v", cluster.name, err)
}
log.Println("...Removing docker image volume")
if err := deleteImageVolume(cluster.name); err != nil {
log.Printf("WARNING: couldn't delete image docker volume for cluster %s\n%+v", cluster.name, err)
}
log.Printf("SUCCESS: removed cluster [%s]", cluster.name)
}

@ -123,13 +123,6 @@ func createServer(spec *ClusterSpec) (string, error) {
hostConfig.Binds = spec.Volumes
}
// we need to mount the clusterDir subdirectory `clusterDir/images` to enable importing images without the need for `docker cp`
clusterDir, err := getClusterDir(spec.ClusterName)
if err != nil {
return "", fmt.Errorf("ERROR: couldn't get cluster dir for mounting\n%+v", err)
}
hostConfig.Binds = append(hostConfig.Binds, fmt.Sprintf("%s:/images", clusterDir+"/images"))
networkingConfig := &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
k3dNetworkName(spec.ClusterName): {
@ -199,13 +192,6 @@ func createWorker(spec *ClusterSpec, postfix int) (string, error) {
hostConfig.Binds = spec.Volumes
}
// we need to mount the clusterDir subdirectory `clusterDir/images` to enable importing images without the need for `docker cp`
clusterDir, err := getClusterDir(spec.ClusterName)
if err != nil {
return "", fmt.Errorf("ERROR: couldn't get cluster dir for mounting\n%+v", err)
}
hostConfig.Binds = append(hostConfig.Binds, fmt.Sprintf("%s:/images", clusterDir+"/images"))
networkingConfig := &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
k3dNetworkName(spec.ClusterName): {

@ -25,11 +25,11 @@ func importImage(clusterName string, images []string) error {
}
// get cluster directory to temporarily save the image tarball there
imageBasePathLocal, err := getClusterDir(clusterName)
imageBasePathLocal = imageBasePathLocal + "/images/"
imageVolume, err := getImageVolume(clusterName)
if err != nil {
return fmt.Errorf("ERROR: couldn't get cluster directory for cluster [%s]\n%+v", clusterName, err)
return fmt.Errorf("ERROR: couldn't get image volume for cluster [%s]\n%+v", clusterName, err)
}
imageBasePathLocal := imageVolume.Mountpoint + "/"
//*** first, save the images using the local docker daemon
log.Printf("INFO: Saving images [%s] from local docker daemon...", images)

@ -8,6 +8,7 @@ github.com/docker/docker/api/types
github.com/docker/docker/api/types/container
github.com/docker/docker/api/types/filters
github.com/docker/docker/api/types/network
github.com/docker/docker/api/types/volume
github.com/docker/docker/client
github.com/docker/docker/api/types/mount
github.com/docker/docker/api/types/registry
@ -18,7 +19,6 @@ github.com/docker/docker/api/types/versions
github.com/docker/docker/api/types/events
github.com/docker/docker/api/types/reference
github.com/docker/docker/api/types/time
github.com/docker/docker/api/types/volume
github.com/docker/docker/pkg/tlsconfig
# github.com/docker/go-connections v0.4.0
github.com/docker/go-connections/nat

Loading…
Cancel
Save