Skip to content

Commit

Permalink
Use regional subnets by default in quick-create. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlamillan authored Dec 16, 2019
1 parent 462dcaa commit 65cc8e7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 161 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.12

require (
github.com/gogo/protobuf v1.3.0 // indirect
github.com/oracle/oci-go-sdk v7.1.0+incompatible
github.com/oracle/oci-go-sdk v13.0.0+incompatible
github.com/pkg/errors v0.8.1
github.com/rancher/kontainer-engine v0.0.0-20190711161432-b98bad2201bb
github.com/rancher/rke v0.2.8 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ github.com/oracle/oci-go-sdk v5.7.0+incompatible h1:+boHw5Zvx75EzCjXHgVxajPxjU8A
github.com/oracle/oci-go-sdk v5.7.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888=
github.com/oracle/oci-go-sdk v7.1.0+incompatible h1:ul/J6rOlLTuVgAB9oSBMwse0U9q8tZj3xx/NjmjRM2g=
github.com/oracle/oci-go-sdk v7.1.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888=
github.com/oracle/oci-go-sdk v13.0.0+incompatible h1:ueAty9OrRXfWi+4gyPLKcOpzhf1OSK70mwt36sD/hf8=
github.com/oracle/oci-go-sdk v13.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888=
github.com/oracle/oci-go-sdk v13.1.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888=
github.com/oracle/oci-manager v0.0.0-20181210225140-b3f0fa436c6b h1:6HTjRyMR6s3eUEYvrM1nvQ3gIT0RcWOqMoBhzRuzZRM=
github.com/oracle/oci-manager v0.0.0-20181210225140-b3f0fa436c6b/go.mod h1:mu49MZKiWx61E+enfYwa8SO2eAcdumsr+eLbXCKfxbs=
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
Expand Down
33 changes: 15 additions & 18 deletions oke/oke_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (

const (
defaultNumNodes = 0
defaultNumNodeSubnets = 3
defaultVCNNamePrefix = "oke-"
defaultServiceSubnetPrefix = "oke-"
)
Expand Down Expand Up @@ -120,7 +119,7 @@ type NetworkConfiguration struct {
// Optional pre-existing load balancer subnets to host load balancers for services
ServiceLBSubnet1Name string
ServiceLBSubnet2Name string
// The number of subnets (each are created in different availability domains)
// The number of AD specific subnets (each are created in different availability domains)
QuantityOfSubnets int64
}

Expand Down Expand Up @@ -441,9 +440,8 @@ func (s *State) validate() error {
return fmt.Errorf(`"node-image " is required`)
} else if s.NodePool.NodeShape == "" {
return fmt.Errorf(`"node-shape " is required`)
} else if s.Network.VCNName != "" && (s.Network.ServiceLBSubnet1Name == "" ||
s.Network.ServiceLBSubnet2Name == "") {
return fmt.Errorf(`"vcn-name", "load-balancer-subnet-name-1", and "load-balancer-subnet-name-2" must all be set together"`)
} else if s.Network.VCNName != "" && (s.Network.ServiceLBSubnet1Name == "") {
return fmt.Errorf(`"vcn-name" and "load-balancer-subnet-name-1" must be set together"`)
}

return nil
Expand Down Expand Up @@ -480,11 +478,7 @@ func (d *OKEDriver) Create(ctx context.Context, opts *types.DriverOptions, _ *ty
if state.Network.VCNName == "" {
// Create a new Virtual Cloud Network with the default number of subnets
state.Network.VCNName = defaultVCNNamePrefix + state.Name
state.Network.ServiceLBSubnet1Name = defaultServiceSubnetPrefix + state.Name + "-1"
state.Network.ServiceLBSubnet2Name = defaultServiceSubnetPrefix + state.Name + "-2"
if state.Network.QuantityOfSubnets == 0 {
state.Network.QuantityOfSubnets = defaultNumNodeSubnets
}
state.Network.ServiceLBSubnet1Name = defaultServiceSubnetPrefix + state.Name

logrus.Infof("Creating a new VCN and required network resources for OKE cluster %s", state.Name)
vcnID, serviceSubnetIDs, nodeSubnetIds, err = oke.CreateVCNAndNetworkResources(&state)
Expand All @@ -510,12 +504,14 @@ func (d *OKEDriver) Create(ctx context.Context, opts *types.DriverOptions, _ *ty
}
serviceSubnetIDs = append(serviceSubnetIDs, serviceSubnet1Id)

serviceSubnet2Id, err := oke.GetSubnetIDByName(ctx, state.Network.VcnCompartmentID, vcnID, state.Network.ServiceLBSubnet2Name)
if err != nil {
logrus.Debugf("error looking up the Id of a Kubernetes service Subnet %s %v", state.Network.ServiceLBSubnet2Name, err)
return clusterInfo, err
if state.Network.ServiceLBSubnet2Name != "" {
serviceSubnet2Id, err := oke.GetSubnetIDByName(ctx, state.Network.VcnCompartmentID, vcnID, state.Network.ServiceLBSubnet2Name)
if err != nil {
logrus.Debugf("error looking up the Id of a Kubernetes service Subnet %s %v", state.Network.ServiceLBSubnet2Name, err)
return clusterInfo, err
}
serviceSubnetIDs = append(serviceSubnetIDs, serviceSubnet2Id)
}
serviceSubnetIDs = append(serviceSubnetIDs, serviceSubnet2Id)

// First, get all the subnet Ids in the VCN, then remove the service subnets which should leave the node subnets
nodeSubnetIds, _ = oke.ListSubnetIdsInVcn(ctx, state.Network.VcnCompartmentID, vcnID)
Expand All @@ -527,10 +523,11 @@ func (d *OKEDriver) Create(ctx context.Context, opts *types.DriverOptions, _ *ty
}
}

// When using an existing VCN, we require at least three subnets for node pool.
if len(nodeSubnetIds) < 3 {
return clusterInfo, fmt.Errorf("VCN must have at least 3 node subnets in different availability domains for node pool")
// When using an existing VCN, we require at least one subnet (preferably regional) for node pool.
if len(nodeSubnetIds) < 1 {
return clusterInfo, fmt.Errorf("VCN must have at least 1 node subnet for node pool")
}

state.Network.QuantityOfSubnets = int64(len(nodeSubnetIds))
}

Expand Down
Loading

0 comments on commit 65cc8e7

Please sign in to comment.