From 552968a6a4a34f389095737b115325a45f4fd943 Mon Sep 17 00:00:00 2001 From: Michael Gianatassio <31552226+mgianatagh@users.noreply.github.com> Date: Thu, 13 Feb 2020 11:51:41 -0800 Subject: [PATCH] Add optional state options for controlling names of subnet resources (#10) * add support to override default values of node and security names * parameterize dns domain names --- oke/oke_driver.go | 85 +++++++++++++++++++++++++++++++++++---- oke/oke_manager_client.go | 29 ++++++------- 2 files changed, 93 insertions(+), 21 deletions(-) diff --git a/oke/oke_driver.go b/oke/oke_driver.go index d00b3f9..9ccc98a 100644 --- a/oke/oke_driver.go +++ b/oke/oke_driver.go @@ -22,6 +22,9 @@ 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" @@ -29,13 +32,11 @@ import ( "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 ( @@ -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 @@ -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 } @@ -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 { diff --git a/oke/oke_manager_client.go b/oke/oke_manager_client.go index 4e754f4..3a8a346 100644 --- a/oke/oke_manager_client.go +++ b/oke/oke_manager_client.go @@ -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. @@ -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 { @@ -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 { @@ -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)