route controller + azure v6 routes
This commit is contained in:
@@ -21,6 +21,7 @@ limitations under the License.
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -31,6 +32,10 @@ import (
|
||||
cloudcontrollers "k8s.io/kubernetes/pkg/controller/cloud"
|
||||
routecontroller "k8s.io/kubernetes/pkg/controller/route"
|
||||
servicecontroller "k8s.io/kubernetes/pkg/controller/service"
|
||||
netutils "k8s.io/utils/net"
|
||||
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
kubefeatures "k8s.io/kubernetes/pkg/features"
|
||||
)
|
||||
|
||||
func startCloudNodeController(ctx *cloudcontrollerconfig.CompletedConfig, cloud cloudprovider.Interface, stopCh <-chan struct{}) (http.Handler, bool, error) {
|
||||
@@ -98,13 +103,26 @@ func startRouteController(ctx *cloudcontrollerconfig.CompletedConfig, cloud clou
|
||||
klog.Warning("configure-cloud-routes is set, but cloud provider does not support routes. Will not configure cloud provider routes.")
|
||||
return nil, false, nil
|
||||
}
|
||||
var clusterCIDR *net.IPNet
|
||||
var err error
|
||||
if len(strings.TrimSpace(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)) != 0 {
|
||||
_, clusterCIDR, err = net.ParseCIDR(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)
|
||||
if err != nil {
|
||||
klog.Warningf("Unsuccessful parsing of cluster CIDR %v: %v", ctx.ComponentConfig.KubeCloudShared.ClusterCIDR, err)
|
||||
}
|
||||
|
||||
// failure: bad cidrs in config
|
||||
clusterCIDRs, dualStack, err := processCIDRs(ctx.ComponentConfig.KubeCloudShared.ClusterCIDR)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
// failure: more than one cidr and dual stack is not enabled
|
||||
if len(clusterCIDRs) > 1 && !utilfeature.DefaultFeatureGate.Enabled(kubefeatures.IPv6DualStack) {
|
||||
return nil, false, fmt.Errorf("len of ClusterCIDRs==%v and dualstack feature is not enabled", len(clusterCIDRs))
|
||||
}
|
||||
|
||||
// failure: more than one cidr but they are not configured as dual stack
|
||||
if len(clusterCIDRs) > 1 && !dualStack {
|
||||
return nil, false, fmt.Errorf("len of ClusterCIDRs==%v and they are not configured as dual stack (at least one from each IPFamily", len(clusterCIDRs))
|
||||
}
|
||||
|
||||
// failure: more than cidrs is not allowed even with dual stack
|
||||
if len(clusterCIDRs) > 2 {
|
||||
return nil, false, fmt.Errorf("length of clusterCIDRs is:%v more than max allowed of 2", len(clusterCIDRs))
|
||||
}
|
||||
|
||||
routeController := routecontroller.New(
|
||||
@@ -112,9 +130,28 @@ func startRouteController(ctx *cloudcontrollerconfig.CompletedConfig, cloud clou
|
||||
ctx.ClientBuilder.ClientOrDie("route-controller"),
|
||||
ctx.SharedInformers.Core().V1().Nodes(),
|
||||
ctx.ComponentConfig.KubeCloudShared.ClusterName,
|
||||
clusterCIDR,
|
||||
clusterCIDRs,
|
||||
)
|
||||
go routeController.Run(stopCh, ctx.ComponentConfig.KubeCloudShared.RouteReconciliationPeriod.Duration)
|
||||
|
||||
return nil, true, nil
|
||||
}
|
||||
|
||||
// processCIDRs is a helper function that works on a comma separated cidrs and returns
|
||||
// a list of typed cidrs
|
||||
// a flag if cidrs represents a dual stack
|
||||
// error if failed to parse any of the cidrs
|
||||
func processCIDRs(cidrsList string) ([]*net.IPNet, bool, error) {
|
||||
cidrsSplit := strings.Split(strings.TrimSpace(cidrsList), ",")
|
||||
|
||||
cidrs, err := netutils.ParseCIDRs(cidrsSplit)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
// if cidrs has an error then the previous call will fail
|
||||
// safe to ignore error checking on next call
|
||||
dualstack, _ := netutils.IsDualStackCIDRs(cidrs)
|
||||
|
||||
return cidrs, dualstack, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user