Skip to content

Commit

Permalink
Add optional state options for controlling names of subnet resources (#…
Browse files Browse the repository at this point in the history
…10)

* add support to override default values of node and security names

* parameterize dns domain names
  • Loading branch information
mgianatagh authored Feb 13, 2020
1 parent 6895a9f commit 552968a
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 21 deletions.
85 changes: 78 additions & 7 deletions oke/oke_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ package oke
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/oracle/oci-go-sdk/common"
"github.com/pkg/errors"
"github.com/rancher/kontainer-engine/drivers/options"
"github.com/rancher/kontainer-engine/types"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
"gopkg.in/yaml.v2"
"io/ioutil"
"k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"os"
)

const (
Expand Down Expand Up @@ -121,6 +122,16 @@ type NetworkConfiguration struct {
ServiceLBSubnet2Name string
// The number of AD specific subnets (each are created in different availability domains)
QuantityOfSubnets int64
// Optional name of node pool subnet
NodePoolSubnetName string
// Optional name of node pool subnet security list
NodePoolSubnetSecurityListName string
// Optional name of node pool dns domain name
NodePoolSubnetDnsDomainName string
// Optional name of the service subnet security list
ServiceSubnetSecurityListName string
// Optional name of the service subnet dns domain name
ServiceSubnetDnsDomainName string
}

// Elements that make up the configuration of each node in the OKE cluster
Expand Down Expand Up @@ -330,6 +341,41 @@ func (d *OKEDriver) GetDriverCreateOptions(ctx context.Context) (*types.DriverFl
Type: types.StringType,
Usage: "Additional CIDR from which to allow ingress to worker nodes",
}
driverFlag.Options["node-pool-subnet-name"] = &types.Flag{
Type: types.StringType,
Usage: "Optional name for node pool subnet",
Default: &types.Default{
DefaultString: nodeSubnetName,
},
}
driverFlag.Options["node-pool-security-list-name"] = &types.Flag{
Type: types.StringType,
Usage: "Optional name for security list of node pool subnet",
Default: &types.Default{
DefaultString: nodePoolSubnetSecurityListName,
},
}
driverFlag.Options["node-pool-dns-domain-name"] = &types.Flag{
Type: types.StringType,
Usage: "Optional name for DNS domain of node pool subnet",
Default: &types.Default{
DefaultString: nodeSubnetName,
},
}
driverFlag.Options["service-security-list-name"] = &types.Flag{
Type: types.StringType,
Usage: "Optional name for security list of service subnet",
Default: &types.Default{
DefaultString: serviceSubnetSecurityListName,
},
}
driverFlag.Options["service-dns-domain-name"] = &types.Flag{
Type: types.StringType,
Usage: "Optional name for DNS domain of service subnet",
Default: &types.Default{
DefaultString: serviceSubnetName,
},
}

return &driverFlag, nil
}
Expand Down Expand Up @@ -390,11 +436,36 @@ func GetStateFromOpts(driverOptions *types.DriverOptions) (State, error) {
}

state.Network = NetworkConfiguration{
VcnCompartmentID: options.GetValueFromDriverOptions(driverOptions, types.StringType, "vcn-compartment-id", "vcnCompartmentId").(string),
VCNName: options.GetValueFromDriverOptions(driverOptions, types.StringType, "vcn-name", "vcnName").(string),
ServiceLBSubnet1Name: options.GetValueFromDriverOptions(driverOptions, types.StringType, "load-balancer-subnet-name-1", "loadBalancerSubnetName1").(string),
ServiceLBSubnet2Name: options.GetValueFromDriverOptions(driverOptions, types.StringType, "load-balancer-subnet-name-2", "loadBalancerSubnetName2").(string),
QuantityOfSubnets: options.GetValueFromDriverOptions(driverOptions, types.IntType, "quantity-of-node-subnets", "quantityOfNodeSubnets").(int64),
VcnCompartmentID: options.GetValueFromDriverOptions(driverOptions, types.StringType, "vcn-compartment-id", "vcnCompartmentId").(string),
VCNName: options.GetValueFromDriverOptions(driverOptions, types.StringType, "vcn-name", "vcnName").(string),
ServiceLBSubnet1Name: options.GetValueFromDriverOptions(driverOptions, types.StringType, "load-balancer-subnet-name-1", "loadBalancerSubnetName1").(string),
ServiceLBSubnet2Name: options.GetValueFromDriverOptions(driverOptions, types.StringType, "load-balancer-subnet-name-2", "loadBalancerSubnetName2").(string),
QuantityOfSubnets: options.GetValueFromDriverOptions(driverOptions, types.IntType, "quantity-of-node-subnets", "quantityOfNodeSubnets").(int64),
NodePoolSubnetName: options.GetValueFromDriverOptions(driverOptions, types.StringType, "node-pool-subnet-name", "nodePoolSubnetName").(string),
NodePoolSubnetSecurityListName: options.GetValueFromDriverOptions(driverOptions, types.StringType, "node-pool-subnet-security-list-name", "nodePoolSubnetSecurityListName").(string),
NodePoolSubnetDnsDomainName: options.GetValueFromDriverOptions(driverOptions, types.StringType, "node-pool-dns-domain-list-name", "nodePoolSubnetDnsDomainName").(string),
ServiceSubnetSecurityListName: options.GetValueFromDriverOptions(driverOptions, types.StringType, "service-subnet-security-list-name", "serviceSubnetSecurityListName").(string),
ServiceSubnetDnsDomainName: options.GetValueFromDriverOptions(driverOptions, types.StringType, "service-subnet-dns-domain-name", "serviceSubnetDnsDomainName").(string),
}

if state.Network.NodePoolSubnetName == "" {
state.Network.NodePoolSubnetName = nodeSubnetName
}

if state.Network.NodePoolSubnetSecurityListName == "" {
state.Network.NodePoolSubnetSecurityListName = nodePoolSubnetSecurityListName
}

if state.Network.NodePoolSubnetDnsDomainName == "" {
state.Network.NodePoolSubnetDnsDomainName = nodeSubnetName
}

if state.Network.ServiceSubnetSecurityListName == "" {
state.Network.ServiceSubnetSecurityListName = serviceSubnetSecurityListName
}

if state.Network.ServiceSubnetDnsDomainName == "" {
state.Network.ServiceSubnetDnsDomainName = serviceSubnetName
}

if state.NodePool.QuantityPerSubnet == 0 {
Expand Down
29 changes: 15 additions & 14 deletions oke/oke_manager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ import (

const (
// TODO VCN block only needs to be large enough for the subnets below
vcnCIDRBlock = "10.0.0.0/16"
nodeCIDRBlock = "10.0.10.0/24"
bastionCIDRBlock = "10.0.16.0/24"
serviceCIDRBlock = "10.0.20.0/24"
nodeSubnetName = "nodedns"
serviceSubnetName = "svcdns"
bastionSubnetName = "bastion"
vcnCIDRBlock = "10.0.0.0/16"
nodeCIDRBlock = "10.0.10.0/24"
bastionCIDRBlock = "10.0.16.0/24"
serviceCIDRBlock = "10.0.20.0/24"
nodeSubnetName = "nodedns"
serviceSubnetName = "svcdns"
bastionSubnetName = "bastion"
nodePoolSubnetSecurityListName = "Node Security List"
serviceSubnetSecurityListName = "Service Security List"
)

// Defines / contains the OCI/OKE/Identity clients and operations.
Expand Down Expand Up @@ -945,11 +947,10 @@ func (mgr *ClusterManagerClient) CreateNodeSubnets(ctx context.Context, state *S
req.CompartmentId = &state.CompartmentID

// Create regional subnet
nodeSubnetName := nodeSubnetName
subnet1, err := mgr.CreateSubnetWithDetails(
common.String(nodeSubnetName),
common.String(state.Network.NodePoolSubnetName),
common.String(nodeCIDRBlock),
common.String(nodeSubnetName),
common.String(state.Network.NodePoolSubnetDnsDomainName),
nil,
common.String(vcnID), common.String(subnetRouteID), isPrivate, securityListIds, state)
if err != nil {
Expand All @@ -974,14 +975,14 @@ func (mgr *ClusterManagerClient) CreateServiceSubnets(ctx context.Context, state
// Create regional subnet for services
var svcSubnetName = ""
if state.Network.ServiceLBSubnet1Name == "" {
svcSubnetName = serviceSubnetName
svcSubnetName = state.Network.ServiceSubnetDnsDomainName
} else {
svcSubnetName = state.Network.ServiceLBSubnet1Name
}
// Create regional subnet
subnet, err := mgr.CreateSubnetWithDetails(common.String(svcSubnetName),
common.String(serviceCIDRBlock),
common.String(serviceSubnetName),
common.String(state.Network.ServiceSubnetDnsDomainName),
nil,
common.String(vcnID), nil, isPrivate, securityListIds, state)
if err != nil {
Expand Down Expand Up @@ -1200,12 +1201,12 @@ func (mgr *ClusterManagerClient) CreateVCNAndNetworkResources(state *State) (str
}

// Create the node security list
nodeSecurityListIds, err := mgr.CreateNodeSecurityList(ctx, state, r.Vcn.Id, nodeCIDRBlock, serviceCIDRBlock, "Node Security List")
nodeSecurityListIds, err := mgr.CreateNodeSecurityList(ctx, state, r.Vcn.Id, nodeCIDRBlock, serviceCIDRBlock, state.Network.NodePoolSubnetSecurityListName)

nodeSubnet, err := mgr.CreateNodeSubnets(ctx, state, *r.Vcn.Id, *subnetRouteID, state.PrivateNodes, nodeSecurityListIds)
helpers.FatalIfError(err)

serviceSecurityListIds, err := mgr.CreateServiceSecurityList(ctx, state, r.Vcn.Id, "Service Security List")
serviceSecurityListIds, err := mgr.CreateServiceSecurityList(ctx, state, r.Vcn.Id, state.Network.ServiceSubnetSecurityListName)

serviceSubnet, err := mgr.CreateServiceSubnets(ctx, state, *r.Vcn.Id, "", false, serviceSecurityListIds)
helpers.FatalIfError(err)
Expand Down

0 comments on commit 552968a

Please sign in to comment.