-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Use noninteractive sudo when running podman #7959
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
934ad06
Use noninteractive sudo when running podman
afbjorklund c1be173
Also delete podman containers and volumes
afbjorklund 9673b42
Skip deleting leftovers if bin not available
afbjorklund 1bd56a4
Don't use cached credentials for sudo podman
afbjorklund 3fa4b91
The podman volume prune does not support filter
afbjorklund 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,26 +90,31 @@ func init() { | |
} | ||
|
||
// shotgun cleanup to delete orphaned docker container data | ||
func deleteContainersAndVolumes() { | ||
if _, err := exec.LookPath(oci.Docker); err != nil { | ||
glog.Infof("skipping deleteContainersAndVolumes for %s: %v", oci.Docker, err) | ||
func deleteContainersAndVolumes(ociBin string) { | ||
if _, err := exec.LookPath(ociBin); err != nil { | ||
glog.Infof("skipping deleteContainersAndVolumes for %s: %v", ociBin, err) | ||
return | ||
} | ||
|
||
glog.Infof("deleting containers and volumes ...") | ||
|
||
delLabel := fmt.Sprintf("%s=%s", oci.CreatedByLabelKey, "true") | ||
errs := oci.DeleteContainersByLabel(oci.Docker, delLabel) | ||
errs := oci.DeleteContainersByLabel(ociBin, delLabel) | ||
if len(errs) > 0 { // it will error if there is no container to delete | ||
glog.Infof("error delete containers by label %q (might be okay): %+v", delLabel, errs) | ||
} | ||
|
||
errs = oci.DeleteAllVolumesByLabel(oci.Docker, delLabel) | ||
errs = oci.DeleteAllVolumesByLabel(ociBin, delLabel) | ||
if len(errs) > 0 { // it will not error if there is nothing to delete | ||
glog.Warningf("error delete volumes by label %q (might be okay): %+v", delLabel, errs) | ||
} | ||
|
||
errs = oci.PruneAllVolumesByLabel(oci.Docker, delLabel) | ||
if ociBin == oci.Podman { | ||
// podman prune does not support --filter | ||
return | ||
} | ||
|
||
errs = oci.PruneAllVolumesByLabel(ociBin, delLabel) | ||
if len(errs) > 0 { // it will not error if there is nothing to delete | ||
glog.Warningf("error pruning volumes by label %q (might be okay): %+v", delLabel, errs) | ||
} | ||
|
@@ -137,7 +142,8 @@ func runDelete(cmd *cobra.Command, args []string) { | |
} | ||
|
||
if deleteAll { | ||
deleteContainersAndVolumes() | ||
deleteContainersAndVolumes(oci.Docker) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe do them in parallel ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. possibly, the theory is that one of them will be "empty" |
||
deleteContainersAndVolumes(oci.Podman) | ||
|
||
errs := DeleteProfiles(profilesToDelete) | ||
if len(errs) > 0 { | ||
|
@@ -167,6 +173,7 @@ func runDelete(cmd *cobra.Command, args []string) { | |
if orphan { | ||
// TODO: generalize for non-KIC drivers: #8040 | ||
deletePossibleKicLeftOver(cname, driver.Docker) | ||
deletePossibleKicLeftOver(cname, driver.Podman) | ||
} | ||
} | ||
|
||
|
@@ -209,8 +216,6 @@ func DeleteProfiles(profiles []*config.Profile) []error { | |
|
||
// TODO: remove and/or move to delete package: #8040 | ||
func deletePossibleKicLeftOver(cname string, driverName string) { | ||
glog.Infof("deleting possible KIC leftovers for %s (driver=%s) ...", cname, driverName) | ||
|
||
bin := "" | ||
switch driverName { | ||
case driver.Docker: | ||
|
@@ -221,6 +226,13 @@ func deletePossibleKicLeftOver(cname string, driverName string) { | |
return | ||
} | ||
|
||
if _, err := exec.LookPath(bin); err != nil { | ||
glog.Infof("skipping deletePossibleKicLeftOver for %s: %v", bin, err) | ||
return | ||
} | ||
|
||
glog.Infof("deleting possible KIC leftovers for %s (driver=%s) ...", cname, driverName) | ||
|
||
delLabel := fmt.Sprintf("%s=%s", oci.ProfileLabelKey, cname) | ||
cs, err := oci.ListContainersByLabel(bin, delLabel) | ||
if err == nil && len(cs) > 0 { | ||
|
@@ -239,6 +251,11 @@ func deletePossibleKicLeftOver(cname string, driverName string) { | |
glog.Warningf("error deleting volumes (might be okay).\nTo see the list of volumes run: 'docker volume ls'\n:%v", errs) | ||
} | ||
|
||
if bin == oci.Podman { | ||
// podman prune does not support --filter | ||
return | ||
} | ||
|
||
errs = oci.PruneAllVolumesByLabel(bin, delLabel) | ||
if len(errs) > 0 { // it will not error if there is nothing to delete | ||
glog.Warningf("error pruning volume (might be okay):\n%v", errs) | ||
|
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
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.
in this line it seems to return and wont go to the deleteall process?
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.
The operation is not supported (volume prune) on podman, so we can only list-and-delete