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
}
コード例 #2
0
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
}
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)
	}
}