Migration to CRDs
Custom Resources Generator
Up until release v0.12 MetalLB was configured via MetalLB’s ConfigMap. Deprecating the ConfigMap impacts on the users’ current configurations. To mitigate this, the MetalLB resource generator is an offline tool to convert the ConfigMap into the new CRDs.
Procedure
In order to use the tool, the following container must be run with the ConfigMap config.yaml mapped into the /var/input folder. On success it will generate a resources.yaml file containing the new MetalLB CRD based config. This example assumes MetalLB was installed in the metallb-system namespace and the ConfigMap was named config:
kubectl get configmap -n metallb-system -o yaml config > config.yaml
docker run -d -v $(pwd):/var/input quay.io/metallb/configmaptocrs
Example
For this MetalLB ConfigMap named config.yaml:
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
peers:
- my-asn: 64512
peer-asn: 64512
peer-address: 10.96.0.100
address-pools:
- name: my-ip-space
protocol: bgp
addresses:
- 198.51.100.0/24
bgp-advertisements:
- aggregation-length: 32
localpref: 100
communities:
- 64512:1234
The generator will generate a resources.yaml
file that looks like:
# This was autogenerated by MetalLB's custom resource generator.
apiVersion: metallb.io/v1beta2
kind: BGPPeer
metadata:
creationTimestamp: null
name: peer1
namespace: metallb-system
spec:
holdTime: 1m30s
keepaliveTime: 0s
myASN: 64512
passwordSecret: {}
peerASN: 64512
peerAddress: 10.96.0.100
status: {}
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
creationTimestamp: null
name: my-ip-space
namespace: metallb-system
spec:
addresses:
- 198.51.100.0/24
status: {}
---
apiVersion: metallb.io/v1beta1
kind: BGPAdvertisement
metadata:
creationTimestamp: null
name: bgpadvertisement1
namespace: metallb-system
spec:
aggregationLength: 32
communities:
- 64512:1234
ipAddressPools:
- my-ip-space
localPref: 100
status: {}
---
Running directly against a cluster
Configmaptocrs tool can also run directly against a cluster, and print the CRs corresponding to the ConfigMap deployed on the cluster to the standard output.
kubectl run configmaptocrs -n metallb-system --restart=Never -it --rm --image overriden --overrides '
{
"spec": {
"containers": [
{
"name": "configmaptocrs",
"image": "quay.io/metallb/configmaptocrs",
"command": [
"/configmaptocrs",
"-source",
"config",
"-only-data",
"-stdout"
],
"volumeMounts": [
{
"name": "config",
"mountPath": "/var/input"
}
]
}
],
"volumes": [
{
"name": "config",
"configMap": {
"name": "config"
}
}
]
}
}'
In this case, for the same ConfigMap as above, the output should look like:
2022/09/11 19:58:19 MetalLB generator starting. commit: fb96318 branch: main goversion: gc / go1.18.3 / amd64
2022/09/11 19:58:19 Reading configmap
2022/09/11 19:58:19 Decoding configmap
2022/09/11 19:58:19 Creating custom resources
2022/09/11 19:58:19 Checking the resources are parsed correctly
2022/09/11 19:58:19 Creating the output YAML
# This was autogenerated by MetalLB's custom resource generator.
apiVersion: metallb.io/v1beta2
kind: BGPPeer
metadata:
creationTimestamp: null
name: peer1
namespace: metallb-system
spec:
holdTime: 1m30s
keepaliveTime: 0s
myASN: 64512
passwordSecret: {}
peerASN: 64512
peerAddress: 10.96.0.100
status: {}
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
creationTimestamp: null
name: my-ip-space
namespace: metallb-system
spec:
addresses:
- 198.51.100.0/24
status: {}
---
apiVersion: metallb.io/v1beta1
kind: BGPAdvertisement
metadata:
creationTimestamp: null
name: bgpadvertisement1
namespace: metallb-system
spec:
aggregationLength: 32
communities:
- 64512:1234
ipAddressPools:
- my-ip-space
localPref: 100
status: {}
---
pod "configmaptocrs" deleted
Options of configmaptocrs:
-source string
name of the input file to convert (default "./config.yaml")
-only-data bool
set this to true if the input file is only the configMap data
-stdout bool
set this to true to output the crds to stdout