Skip to content
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

add static ip to kube play #8617

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/podman/play/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pods

import (
"fmt"
"net"
"os"

"github.com/containers/common/pkg/auth"
Expand All @@ -23,6 +24,7 @@ type playKubeOptionsWrapper struct {
TLSVerifyCLI bool
CredentialsCLI string
StartCLI bool
StaticIPCLI string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed see other comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flags will make things much easier, will update that

}

var (
Expand Down Expand Up @@ -75,6 +77,10 @@ func init() {
flags.StringVar(&kubeOptions.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
_ = kubeCmd.RegisterFlagCompletionFunc(authfileFlagName, completion.AutocompleteDefault)

staticIPFlagName := "ip"
flags.StringVar(&kubeOptions.StaticIPCLI, staticIPFlagName, "", "Static IP address to assign to this pod")
_ = kubeCmd.RegisterFlagCompletionFunc(staticIPFlagName, completion.AutocompleteDefault)

Comment on lines +80 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use an IP flag. No need for the extra parsing logic

Suggested change
staticIPFlagName := "ip"
flags.StringVar(&kubeOptions.StaticIPCLI, staticIPFlagName, "", "Static IP address to assign to this pod")
_ = kubeCmd.RegisterFlagCompletionFunc(staticIPFlagName, completion.AutocompleteDefault)
staticIPFlagName := "ip"
flags.IPVar(&kubeOptions.StaticIP, staticIPFlagName, nil, "Static IP address to assign to this pod")
_ = kubeCmd.RegisterFlagCompletionFunc(staticIPFlagName, completion.AutocompleteNone)

if !registry.IsRemote() {

certDirFlagName := "cert-dir"
Expand Down Expand Up @@ -119,6 +125,14 @@ func kube(cmd *cobra.Command, args []string) error {
kubeOptions.Password = creds.Password
}

if kubeOptions.StaticIPCLI != "" {
ipAddress := net.ParseIP(kubeOptions.StaticIPCLI)
if ipAddress == nil {
return fmt.Errorf("failed parsing ip address: %s", kubeOptions.StaticIPCLI)
}
kubeOptions.StaticIP = ipAddress
}

Comment on lines +128 to +135
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed see other comment

report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), args[0], kubeOptions.PlayKubeOptions)
if err != nil {
return err
Expand Down
8 changes: 7 additions & 1 deletion pkg/domain/entities/play.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package entities

import "github.com/containers/image/v5/types"
import (
"net"

"github.com/containers/image/v5/types"
)

// PlayKubeOptions controls playing kube YAML files.
type PlayKubeOptions struct {
Expand Down Expand Up @@ -30,6 +34,8 @@ type PlayKubeOptions struct {
LogDriver string
// Start - don't start the pod if false
Start types.OptionalBool
// StaticIP - a static ip address that will be assigned to the pod
StaticIP net.IP
}

// PlayKubePod represents a single pod and associated containers created by play kube
Expand Down
5 changes: 5 additions & 0 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
}
}

// Assign a static ip if it was specified
if options.StaticIP != nil {
p.StaticIP = &options.StaticIP
}

// Create the Pod
pod, err := generate.MakePod(p, ic.Libpod)
if err != nil {
Expand Down