-
Notifications
You must be signed in to change notification settings - Fork 949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add volumes-from for container #1131
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package opts | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/alibaba/pouch/apis/types" | ||
) | ||
|
||
// CheckBind is used to check the volume bind information. | ||
func CheckBind(b string) ([]string, error) { | ||
if strings.Count(b, ":") > 2 { | ||
return nil, fmt.Errorf("unknown volume bind: %s", b) | ||
} | ||
|
||
arr := strings.SplitN(b, ":", 3) | ||
switch len(arr) { | ||
case 1: | ||
if arr[0] == "" { | ||
return nil, fmt.Errorf("unknown volume bind: %s", b) | ||
} | ||
if arr[0][:1] != "/" { | ||
return nil, fmt.Errorf("invalid bind path: %s", arr[0]) | ||
} | ||
case 2, 3: | ||
if arr[1] == "" { | ||
return nil, fmt.Errorf("unknown volume bind: %s", b) | ||
} | ||
if arr[1][:1] != "/" { | ||
return nil, fmt.Errorf("invalid bind path: %s", arr[1]) | ||
} | ||
default: | ||
return nil, fmt.Errorf("unknown volume bind: %s", b) | ||
} | ||
|
||
return arr, nil | ||
} | ||
|
||
// ParseVolumesFrom is used to parse the parameter of VolumesFrom. | ||
func ParseVolumesFrom(volume string) (string, string, error) { | ||
if len(volume) == 0 { | ||
return "", "", fmt.Errorf("invalid argument volumes-from") | ||
} | ||
|
||
parts := strings.Split(volume, ":") | ||
containerID := parts[0] | ||
mode := "" | ||
if len(parts) > 1 { | ||
mode = parts[1] | ||
} | ||
|
||
if containerID == "" { | ||
return "", "", fmt.Errorf("failed to parse container's id") | ||
} | ||
|
||
return containerID, mode, nil | ||
} | ||
|
||
// ParseBindMode is used to parse the bind's mode. | ||
func ParseBindMode(mp *types.MountPoint, mode string) error { | ||
mp.RW = true | ||
mp.CopyData = true | ||
|
||
defaultMode := 0 | ||
rwMode := 0 | ||
labelMode := 0 | ||
replaceMode := 0 | ||
copyMode := 0 | ||
propagationMode := 0 | ||
|
||
for _, m := range strings.Split(mode, ",") { | ||
switch m { | ||
case "": | ||
defaultMode++ | ||
case "ro": | ||
mp.RW = false | ||
rwMode++ | ||
case "rw": | ||
mp.RW = true | ||
rwMode++ | ||
case "dr", "rr": | ||
// direct replace mode, random replace mode | ||
mp.Replace = m | ||
replaceMode++ | ||
case "z", "Z": | ||
labelMode++ | ||
case "nocopy": | ||
mp.CopyData = false | ||
copyMode++ | ||
case "private", "rprivate", "slave", "rslave", "shared", "rshared": | ||
mp.Propagation = m | ||
propagationMode++ | ||
default: | ||
return fmt.Errorf("unknown bind mode: %s", mode) | ||
} | ||
} | ||
|
||
if defaultMode > 1 || rwMode > 1 || replaceMode > 1 || copyMode > 1 || propagationMode > 1 { | ||
return fmt.Errorf("invalid bind mode: %s", mode) | ||
} | ||
|
||
mp.Mode = mode | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is
other container
, since we cannot set volumes for multiple containers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, the api
VolumesFrom
is a slice, it means it can use more than one container's volumes.