Skip to content

Commit

Permalink
Merge pull request #244 from dtrudg/issue243
Browse files Browse the repository at this point in the history
fix: honor hostname in library:// URI for `singularity delete`
  • Loading branch information
dtrudg authored Aug 12, 2021
2 parents aa3fd49 + 05da5ea commit e6988a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
value of `runtime.GOARCH`. E.g. `ppc64el -> ppc64le`.
- Ensure repeated `remote login` to same URI does not create duplicate entries
in `~/.singularity/remote.yaml`.
- `singularity delete` will use the correct library service when the hostname
is specified in the `library://` URI.

## v3.8.1 \[2021-07-20\]

Expand Down
14 changes: 13 additions & 1 deletion cmd/internal/cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ var deleteImageCmd = &cobra.Command{
sylog.Fatalf("Error parsing library ref: %v", err)
}

if deleteLibraryURI != "" && imageRef.Host != "" {
sylog.Fatalf("Conflicting arguments; do not use --library with a library URI containing host name")
}

var libraryURI string
if deleteLibraryURI != "" {
libraryURI = deleteLibraryURI
} else if imageRef.Host != "" {
// override libraryURI if ref contains host name
libraryURI = "https://" + imageRef.Host
}

r := fmt.Sprintf("%s:%s", imageRef.Path, imageRef.Tags[0])

if !deleteForce {
Expand All @@ -109,7 +121,7 @@ var deleteImageCmd = &cobra.Command{
}
}

libraryConfig, err := getLibraryClientConfig(deleteLibraryURI)
libraryConfig, err := getLibraryClientConfig(libraryURI)
if err != nil {
sylog.Fatalf("Error while getting library client config: %v", err)
}
Expand Down
10 changes: 9 additions & 1 deletion e2e/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (c ctx) testDeleteCmd(t *testing.T) {
args []string
agree string
expectExit int
expect e2e.SingularityCmdResultOp
}{
{
name: "delete unauthorized arch",
Expand Down Expand Up @@ -66,6 +67,13 @@ func (c ctx) testDeleteCmd(t *testing.T) {
agree: "y",
expectExit: 255,
},
{
name: "delete host in uri",
args: []string{"library://library.example.com/test/default/test:v0.0.3"},
agree: "y",
expectExit: 255,
expect: e2e.ExpectError(e2e.ContainMatch, "dial tcp: lookup library.example.com: no such host"),
},
}

for _, tt := range tests {
Expand All @@ -76,7 +84,7 @@ func (c ctx) testDeleteCmd(t *testing.T) {
e2e.WithCommand("delete"),
e2e.WithArgs(tt.args...),
e2e.WithStdin(bytes.NewBufferString(tt.agree)),
e2e.ExpectExit(tt.expectExit),
e2e.ExpectExit(tt.expectExit, tt.expect),
)
}
}
Expand Down

0 comments on commit e6988a2

Please sign in to comment.