allow setting api-port

pull/227/head
iwilltry42 5 years ago
parent 0ed9e9ae6b
commit a14854502e
  1. 18
      cmd/create/createCluster.go
  2. 10
      pkg/runtimes/docker/translate.go

@ -22,6 +22,8 @@ THE SOFTWARE.
package create
import (
"fmt"
"github.com/spf13/cobra"
k3dCluster "github.com/rancher/k3d/pkg/cluster"
@ -88,6 +90,11 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string) (runtimes.Runtime,
log.Fatalln(err)
}
// TODO: allow more than one master
if masterCount > 1 {
log.Fatalln("Only one master node supported right now!")
}
// --workers
workerCount, err := cmd.Flags().GetInt("workers")
if err != nil {
@ -107,10 +114,10 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string) (runtimes.Runtime,
}
// --api-port // TODO:
/*apiPort, err := cmd.Flags().GetString("api-port")
apiPort, err := cmd.Flags().GetString("api-port")
if err != nil {
log.Fatalln(err)
}*/
}
/* generate cluster */
cluster := &k3d.Cluster{
@ -121,14 +128,21 @@ func parseCreateClusterCmd(cmd *cobra.Command, args []string) (runtimes.Runtime,
// generate list of nodes
cluster.Nodes = []k3d.Node{}
// -> master nodes
for i := 0; i < masterCount; i++ {
node := k3d.Node{
Role: k3d.MasterRole,
Image: image,
}
if i == 0 {
node.Ports = append(node.Ports, fmt.Sprintf("0.0.0.0:%s:6443/tcp", apiPort)) // TODO: update (choose interface, enable more than one master) and get '6443' from defaultport variable
node.Labels["k3d.master.apiPort"] = apiPort
}
cluster.Nodes = append(cluster.Nodes, node)
}
// -> worker nodes
for i := 0; i < workerCount; i++ {
node := k3d.Node{
Role: k3d.WorkerRole,

@ -28,6 +28,7 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/go-connections/nat"
k3d "github.com/rancher/k3d/pkg/types"
log "github.com/sirupsen/logrus"
)
// TranslateNodeToContainer translates a k3d node specification to a docker container representation
@ -78,8 +79,13 @@ func TranslateNodeToContainer(node *k3d.Node) (*NodeInDocker, error) {
// containerConfig.Volumes = map[string]struct{}{} // TODO: do we need this? We only used binds before
/* Ports */
containerConfig.ExposedPorts = nat.PortSet{} // TODO: translate from node.Ports to nat.PortSet
hostConfig.PortBindings = nat.PortMap{} // TODO: this and exposedPorts required?
exposedPorts, portBindings, err := nat.ParsePortSpecs(node.Ports)
if err != nil {
log.Errorln("Failed to parse port specs")
return nil, err
}
containerConfig.ExposedPorts = exposedPorts
hostConfig.PortBindings = portBindings
/* Network */
networkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{

Loading…
Cancel
Save