mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Compose routes for on-prem nodes
Compose faked routes for unmanaged nodes so that node controller would assume the routes for them have already been created.
This commit is contained in:
parent
19d7d85a67
commit
919058b315
@ -159,7 +159,7 @@ type Cloud struct {
|
|||||||
metadata *InstanceMetadata
|
metadata *InstanceMetadata
|
||||||
vmSet VMSet
|
vmSet VMSet
|
||||||
|
|
||||||
// Lock for access to node caches
|
// Lock for access to node caches, includes nodeZones, nodeResourceGroups, and unmanagedNodes.
|
||||||
nodeCachesLock sync.Mutex
|
nodeCachesLock sync.Mutex
|
||||||
// nodeZones is a mapping from Zone to a sets.String of Node's names in the Zone
|
// nodeZones is a mapping from Zone to a sets.String of Node's names in the Zone
|
||||||
// it is updated by the nodeInformer
|
// it is updated by the nodeInformer
|
||||||
@ -171,6 +171,11 @@ type Cloud struct {
|
|||||||
// nodeInformerSynced is for determining if the informer has synced.
|
// nodeInformerSynced is for determining if the informer has synced.
|
||||||
nodeInformerSynced cache.InformerSynced
|
nodeInformerSynced cache.InformerSynced
|
||||||
|
|
||||||
|
// routeCIDRsLock holds lock for routeCIDRs cache.
|
||||||
|
routeCIDRsLock sync.Mutex
|
||||||
|
// routeCIDRs holds cache for route CIDRs.
|
||||||
|
routeCIDRs map[string]string
|
||||||
|
|
||||||
// Clients for vmss.
|
// Clients for vmss.
|
||||||
VirtualMachineScaleSetsClient VirtualMachineScaleSetsClient
|
VirtualMachineScaleSetsClient VirtualMachineScaleSetsClient
|
||||||
VirtualMachineScaleSetVMsClient VirtualMachineScaleSetVMsClient
|
VirtualMachineScaleSetVMsClient VirtualMachineScaleSetVMsClient
|
||||||
@ -270,6 +275,7 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
|
|||||||
nodeZones: map[string]sets.String{},
|
nodeZones: map[string]sets.String{},
|
||||||
nodeResourceGroups: map[string]string{},
|
nodeResourceGroups: map[string]string{},
|
||||||
unmanagedNodes: sets.NewString(),
|
unmanagedNodes: sets.NewString(),
|
||||||
|
routeCIDRs: map[string]string{},
|
||||||
|
|
||||||
DisksClient: newAzDisksClient(azClientConfig),
|
DisksClient: newAzDisksClient(azClientConfig),
|
||||||
RoutesClient: newAzRoutesClient(azClientConfig),
|
RoutesClient: newAzRoutesClient(azClientConfig),
|
||||||
|
@ -32,7 +32,29 @@ import (
|
|||||||
func (az *Cloud) ListRoutes(ctx context.Context, clusterName string) ([]*cloudprovider.Route, error) {
|
func (az *Cloud) ListRoutes(ctx context.Context, clusterName string) ([]*cloudprovider.Route, error) {
|
||||||
glog.V(10).Infof("ListRoutes: START clusterName=%q", clusterName)
|
glog.V(10).Infof("ListRoutes: START clusterName=%q", clusterName)
|
||||||
routeTable, existsRouteTable, err := az.getRouteTable()
|
routeTable, existsRouteTable, err := az.getRouteTable()
|
||||||
return processRoutes(routeTable, existsRouteTable, err)
|
routes, err := processRoutes(routeTable, existsRouteTable, err)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compose routes for unmanaged routes so that node controller won't retry creating routes for them.
|
||||||
|
unmanagedNodes, err := az.GetUnmanagedNodes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
az.routeCIDRsLock.Lock()
|
||||||
|
defer az.routeCIDRsLock.Unlock()
|
||||||
|
for _, nodeName := range unmanagedNodes.List() {
|
||||||
|
if cidr, ok := az.routeCIDRs[nodeName]; ok {
|
||||||
|
routes = append(routes, &cloudprovider.Route{
|
||||||
|
Name: nodeName,
|
||||||
|
TargetNode: mapRouteNameToNodeName(nodeName),
|
||||||
|
DestinationCIDR: cidr,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return routes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Injectable for testing
|
// Injectable for testing
|
||||||
@ -108,12 +130,16 @@ func (az *Cloud) createRouteTable() error {
|
|||||||
// to create a more user-meaningful name.
|
// to create a more user-meaningful name.
|
||||||
func (az *Cloud) CreateRoute(ctx context.Context, clusterName string, nameHint string, kubeRoute *cloudprovider.Route) error {
|
func (az *Cloud) CreateRoute(ctx context.Context, clusterName string, nameHint string, kubeRoute *cloudprovider.Route) error {
|
||||||
// Returns for unmanaged nodes because azure cloud provider couldn't fetch information for them.
|
// Returns for unmanaged nodes because azure cloud provider couldn't fetch information for them.
|
||||||
unmanaged, err := az.IsNodeUnmanaged(string(kubeRoute.TargetNode))
|
nodeName := string(kubeRoute.TargetNode)
|
||||||
|
unmanaged, err := az.IsNodeUnmanaged(nodeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if unmanaged {
|
if unmanaged {
|
||||||
glog.V(2).Infof("CreateRoute: omitting unmanaged node %q", kubeRoute.TargetNode)
|
glog.V(2).Infof("CreateRoute: omitting unmanaged node %q", kubeRoute.TargetNode)
|
||||||
|
az.routeCIDRsLock.Lock()
|
||||||
|
defer az.routeCIDRsLock.Unlock()
|
||||||
|
az.routeCIDRs[nodeName] = kubeRoute.DestinationCIDR
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,12 +187,16 @@ func (az *Cloud) CreateRoute(ctx context.Context, clusterName string, nameHint s
|
|||||||
// Route should be as returned by ListRoutes
|
// Route should be as returned by ListRoutes
|
||||||
func (az *Cloud) DeleteRoute(ctx context.Context, clusterName string, kubeRoute *cloudprovider.Route) error {
|
func (az *Cloud) DeleteRoute(ctx context.Context, clusterName string, kubeRoute *cloudprovider.Route) error {
|
||||||
// Returns for unmanaged nodes because azure cloud provider couldn't fetch information for them.
|
// Returns for unmanaged nodes because azure cloud provider couldn't fetch information for them.
|
||||||
unmanaged, err := az.IsNodeUnmanaged(string(kubeRoute.TargetNode))
|
nodeName := string(kubeRoute.TargetNode)
|
||||||
|
unmanaged, err := az.IsNodeUnmanaged(nodeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if unmanaged {
|
if unmanaged {
|
||||||
glog.V(2).Infof("DeleteRoute: omitting unmanaged node %q", kubeRoute.TargetNode)
|
glog.V(2).Infof("DeleteRoute: omitting unmanaged node %q", kubeRoute.TargetNode)
|
||||||
|
az.routeCIDRsLock.Lock()
|
||||||
|
defer az.routeCIDRsLock.Unlock()
|
||||||
|
delete(az.routeCIDRs, nodeName)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user