-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8571 from Luap99/podman-network-reload
Implement pod-network-reload
- Loading branch information
Showing
14 changed files
with
376 additions
and
13 deletions.
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/containers/podman/v2/cmd/podman/common" | ||
"github.com/containers/podman/v2/cmd/podman/registry" | ||
"github.com/containers/podman/v2/cmd/podman/utils" | ||
"github.com/containers/podman/v2/cmd/podman/validate" | ||
"github.com/containers/podman/v2/pkg/domain/entities" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
var ( | ||
networkReloadDescription = `reload container networks, recreating firewall rules` | ||
networkReloadCommand = &cobra.Command{ | ||
Use: "reload [options] [CONTAINER...]", | ||
Short: "Reload firewall rules for one or more containers", | ||
Long: networkReloadDescription, | ||
RunE: networkReload, | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
return validate.CheckAllLatestAndCIDFile(cmd, args, false, false) | ||
}, | ||
ValidArgsFunction: common.AutocompleteContainers, | ||
Example: `podman network reload --latest | ||
podman network reload 3c13ef6dd843 | ||
podman network reload test1 test2`, | ||
Annotations: map[string]string{ | ||
registry.ParentNSRequired: "", | ||
}, | ||
} | ||
) | ||
|
||
var ( | ||
reloadOptions entities.NetworkReloadOptions | ||
) | ||
|
||
func reloadFlags(flags *pflag.FlagSet) { | ||
flags.BoolVarP(&reloadOptions.All, "all", "a", false, "Reload network configuration of all containers") | ||
} | ||
|
||
func init() { | ||
registry.Commands = append(registry.Commands, registry.CliCommand{ | ||
Mode: []entities.EngineMode{entities.ABIMode}, | ||
Command: networkReloadCommand, | ||
Parent: networkCmd, | ||
}) | ||
reloadFlags(networkReloadCommand.Flags()) | ||
validate.AddLatestFlag(networkReloadCommand, &reloadOptions.Latest) | ||
} | ||
|
||
func networkReload(cmd *cobra.Command, args []string) error { | ||
responses, err := registry.ContainerEngine().NetworkReload(registry.Context(), args, reloadOptions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var errs utils.OutputErrors | ||
for _, r := range responses { | ||
if r.Err == nil { | ||
fmt.Println(r.Id) | ||
} else { | ||
errs = append(errs, r.Err) | ||
} | ||
} | ||
|
||
return errs.PrintErrors() | ||
} |
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,62 @@ | ||
% podman-network-reload(1) | ||
|
||
## NAME | ||
podman\-network\-reload - Reload network configuration for containers | ||
|
||
## SYNOPSIS | ||
**podman network reload** [*options*] [*container...*] | ||
|
||
## DESCRIPTION | ||
Reload one or more container network configurations. | ||
|
||
Rootful Podman relies on iptables rules in order to provide network connectivity. If the iptables rules are deleted, | ||
this happens for example with `firewall-cmd --reload`, the container loses network connectivity. This command restores | ||
the network connectivity. | ||
|
||
This command is not available for rootless users since rootless containers are not affected by such connectivity problems. | ||
|
||
## OPTIONS | ||
#### **--all**, **-a** | ||
|
||
Reload network configuration of all containers. | ||
|
||
#### **--latest**, **-l** | ||
|
||
Instead of providing the container name or ID, use the last created container. If you use methods other than Podman | ||
to run containers such as CRI-O, the last started container could be from either of those methods. | ||
|
||
The latest option is not supported on the remote client. | ||
|
||
## EXAMPLE | ||
|
||
Reload the network configuration after a firewall reload. | ||
|
||
``` | ||
# podman run -p 80:80 -d nginx | ||
b1b538e8bc4078fc3ee1c95b666ebc7449b9a97bacd15bcbe464a29e1be59c1c | ||
# curl 127.0.0.1 | ||
works | ||
# sudo firewall-cmd --reload | ||
success | ||
# curl 127.0.0.1 | ||
hangs | ||
# podman network reload b1b538e8bc40 | ||
b1b538e8bc4078fc3ee1c95b666ebc7449b9a97bacd15bcbe464a29e1be59c1c | ||
# curl 127.0.0.1 | ||
works | ||
``` | ||
|
||
Reload the network configuration for all containers. | ||
|
||
``` | ||
# podman network reload --all | ||
b1b538e8bc4078fc3ee1c95b666ebc7449b9a97bacd15bcbe464a29e1be59c1c | ||
fe7e8eca56f844ec33af10f0aa3b31b44a172776e3277b9550a623ed5d96e72b | ||
``` | ||
|
||
|
||
## SEE ALSO | ||
podman(1), podman-network(1) | ||
|
||
## HISTORY | ||
December 2020, Originally compiled by Paul Holzinger <[email protected]> |
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
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
Oops, something went wrong.