flannel: allow input ipam parameters as basis for delegate
This change allows providing an 'ipam' section as part of the input network configuration for flannel. It is then used as basis to construct the ipam parameters provided to the delegate. All parameters from the input ipam are preserved except: * 'subnet' which is set to the flannel host subnet * 'routes' which is complemented by a route to the flannel network. One use case of this feature is to allow adding back the routes to the cluster services and/or to the hosts (HostPort) when using isDefaultGateway=false. In that case, the bridge plugin does not install a default route and, as a result, only pod-to-pod connectivity would be available. Example: { "name": "cbr0", "cniVersion": "0.3.1", "type": "flannel", "ipam": { "routes": [ { "dst": "192.168.242.0/24" }, { "dst": "10.96.0.0/12" } ], "unknown-param": "value" }, "delegate": { "hairpinMode": true, "isDefaultGateway": false } ... } This results in the following 'ipam' being provided to the delegate: { "routes" : [ { "dst": "192.168.242.0/24" }, { "dst": "10.96.0.0/12" }, { "dst" : "10.1.0.0/16" } ], "subnet" : "10.1.17.0/24", "type" : "host-local" "unknown-param": "value" } where "10.1.0.0/16" is the flannel network and "10.1.17.0/24" is the host flannel subnet. Note that this also allows setting a different ipam 'type' than "host-local". Signed-off-by: David Verbeiren <david.verbeiren@tessares.net>
This commit is contained in:
@ -46,6 +46,8 @@ const (
|
||||
type NetConf struct {
|
||||
types.NetConf
|
||||
|
||||
// IPAM field "replaces" that of types.NetConf which is incomplete
|
||||
IPAM map[string]interface{} `json:"ipam,omitempty"`
|
||||
SubnetFile string `json:"subnetFile"`
|
||||
DataDir string `json:"dataDir"`
|
||||
Delegate map[string]interface{} `json:"delegate"`
|
||||
@ -89,6 +91,18 @@ func loadFlannelNetConf(bytes []byte) (*NetConf, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func getIPAMRoutes(n *NetConf) ([]types.Route, error) {
|
||||
rtes := []types.Route{}
|
||||
|
||||
if n.IPAM != nil && hasKey(n.IPAM, "routes") {
|
||||
buf, _ := json.Marshal(n.IPAM["routes"])
|
||||
if err := json.Unmarshal(buf, &rtes); err != nil {
|
||||
return rtes, fmt.Errorf("failed to parse ipam.routes: %w", err)
|
||||
}
|
||||
}
|
||||
return rtes, nil
|
||||
}
|
||||
|
||||
func loadFlannelSubnetEnv(fn string) (*subnetEnv, error) {
|
||||
f, err := os.Open(fn)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user