本文整理汇总了Golang中k8s/io/kubernetes/pkg/api.ContainerPort类的典型用法代码示例。如果您正苦于以下问题:Golang ContainerPort类的具体用法?Golang ContainerPort怎么用?Golang ContainerPort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContainerPort类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: buildContainerPorts
func buildContainerPorts(userPorts []interface{}) []api.ContainerPort {
if len(userPorts) == 0 {
return nil
}
var ports []api.ContainerPort
for _, p := range userPorts {
userPort := p.(map[string]interface{})
port := api.ContainerPort{
ContainerPort: userPort["container_port"].(int),
}
if _, ok := userPort["host_port"]; ok {
port.HostPort = userPort["host_port"].(int)
}
if _, ok := userPort["name"]; ok {
port.Name = userPort["name"].(string)
}
if _, ok := userPort["protocol"]; ok {
port.Protocol = api.Protocol(userPort["protocol"].(string))
}
if _, ok := userPort["host_ip"]; ok {
port.HostIP = userPort["host_ip"].(string)
}
ports = append(ports, port)
}
return ports
}
开发者ID:kelcecil,项目名称:terraform-provider-kubernetes,代码行数:31,代码来源:build_kubernetes_resource_controller.go
示例2: deepCopy_api_ContainerPort
func deepCopy_api_ContainerPort(in api.ContainerPort, out *api.ContainerPort, c *conversion.Cloner) error {
out.Name = in.Name
out.HostPort = in.HostPort
out.ContainerPort = in.ContainerPort
out.Protocol = in.Protocol
out.HostIP = in.HostIP
return nil
}
示例3: writeContainerPort
func writeContainerPort(m map[string]interface{}, item *api.ContainerPort) {
if x, ok := m["name"].(string); ok {
item.Name = x
}
if x, ok := m["host_port"].(int); ok {
item.HostPort = x
}
if x, ok := m["host_ip"].(string); ok {
item.HostIP = x
}
if x, ok := m["container_port"].(int); ok {
item.ContainerPort = x
}
if x, ok := m["protocol"].(string); ok {
item.Protocol = api.Protocol(x)
}
}
示例4: RunCmdRouter
// RunCmdRouter contains all the necessary functionality for the
// OpenShift CLI router command.
func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out io.Writer, cfg *RouterConfig, args []string) error {
switch len(args) {
case 0:
// uses default value
case 1:
cfg.Name = args[0]
default:
return kcmdutil.UsageError(cmd, "You may pass zero or one arguments to provide a name for the router")
}
name := cfg.Name
var defaultOutputErr error
if len(cfg.StatsUsername) > 0 {
if strings.Contains(cfg.StatsUsername, ":") {
return kcmdutil.UsageError(cmd, "username %s must not contain ':'", cfg.StatsUsername)
}
}
if len(cfg.Subdomain) > 0 && len(cfg.ForceSubdomain) > 0 {
return kcmdutil.UsageError(cmd, "only one of --subdomain, --force-subdomain can be specified")
}
ports, err := app.ContainerPortsFromString(cfg.Ports)
if err != nil {
return fmt.Errorf("unable to parse --ports: %v", err)
}
// HostNetwork overrides HostPorts
if cfg.HostNetwork {
cfg.HostPorts = false
}
// For the host networking case, ensure the ports match.
if cfg.HostNetwork {
for i := 0; i < len(ports); i++ {
if ports[i].HostPort != 0 && ports[i].ContainerPort != ports[i].HostPort {
return fmt.Errorf("when using host networking mode, container port %d and host port %d must be equal", ports[i].ContainerPort, ports[i].HostPort)
}
}
}
if cfg.StatsPort > 0 {
port := kapi.ContainerPort{
Name: "stats",
ContainerPort: cfg.StatsPort,
Protocol: kapi.ProtocolTCP,
}
if cfg.HostPorts {
port.HostPort = cfg.StatsPort
}
ports = append(ports, port)
}
label := map[string]string{"router": name}
if cfg.Labels != defaultLabel {
valid, remove, err := app.LabelsFromSpec(strings.Split(cfg.Labels, ","))
if err != nil {
glog.Fatal(err)
}
if len(remove) > 0 {
return kcmdutil.UsageError(cmd, "You may not pass negative labels in %q", cfg.Labels)
}
label = valid
}
nodeSelector := map[string]string{}
if len(cfg.Selector) > 0 {
valid, remove, err := app.LabelsFromSpec(strings.Split(cfg.Selector, ","))
if err != nil {
glog.Fatal(err)
}
if len(remove) > 0 {
return kcmdutil.UsageError(cmd, "You may not pass negative labels in selector %q", cfg.Selector)
}
nodeSelector = valid
}
image := cfg.ImageTemplate.ExpandOrDie(cfg.Type)
namespace, _, err := f.OpenShiftClientConfig.Namespace()
if err != nil {
return fmt.Errorf("error getting client: %v", err)
}
_, kClient, err := f.Clients()
if err != nil {
return fmt.Errorf("error getting client: %v", err)
}
_, output, err := kcmdutil.PrinterForCommand(cmd)
if err != nil {
return fmt.Errorf("unable to configure printer: %v", err)
}
generate := output
if !generate {
_, err = kClient.Services(namespace).Get(name)
if err != nil {
//.........这里部分代码省略.........