add --mac-address to podman play kube

Add a new --mac-address flag to podman play kube. This is used to specify
a static MAC address which should be used for the pod. This option can be
specified several times because play kube can create more than one pod.

Fixes #9731

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
Paul Holzinger
2021-05-04 17:06:57 +02:00
parent dea6189982
commit fb7d16c7a8
10 changed files with 92 additions and 16 deletions

View File

@ -21,11 +21,12 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
decoder := r.Context().Value("decoder").(*schema.Decoder)
query := struct {
Network string `schema:"network"`
TLSVerify bool `schema:"tlsVerify"`
LogDriver string `schema:"logDriver"`
Start bool `schema:"start"`
StaticIPs []string `schema:"staticIPs"`
Network string `schema:"network"`
TLSVerify bool `schema:"tlsVerify"`
LogDriver string `schema:"logDriver"`
Start bool `schema:"start"`
StaticIPs []string `schema:"staticIPs"`
StaticMACs []string `schema:"staticMACs"`
}{
TLSVerify: true,
Start: true,
@ -48,6 +49,17 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
staticIPs = append(staticIPs, ip)
}
staticMACs := make([]net.HardwareAddr, 0, len(query.StaticMACs))
for _, macString := range query.StaticMACs {
mac, err := net.ParseMAC(macString)
if err != nil {
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
err)
return
}
staticMACs = append(staticMACs, mac)
}
// Fetch the K8s YAML file from the body, and copy it to a temp file.
tmpfile, err := ioutil.TempFile("", "libpod-play-kube.yml")
if err != nil {
@ -78,13 +90,14 @@ func PlayKube(w http.ResponseWriter, r *http.Request) {
containerEngine := abi.ContainerEngine{Libpod: runtime}
options := entities.PlayKubeOptions{
Authfile: authfile,
Username: username,
Password: password,
Network: query.Network,
Quiet: true,
LogDriver: query.LogDriver,
StaticIPs: staticIPs,
Authfile: authfile,
Username: username,
Password: password,
Network: query.Network,
Quiet: true,
LogDriver: query.LogDriver,
StaticIPs: staticIPs,
StaticMACs: staticMACs,
}
if _, found := r.URL.Query()["tlsVerify"]; found {
options.SkipTLSVerify = types.NewOptionalBool(!query.TLSVerify)

View File

@ -40,6 +40,12 @@ func (s *APIServer) registerPlayHandlers(r *mux.Router) error {
// description: Static IPs used for the pods.
// items:
// type: string
// - in: query
// name: staticMACs
// type: array
// description: Static MACs used for the pods.
// items:
// type: string
// - in: body
// name: request
// description: Kubernetes YAML file.