Skip to content

Commit

Permalink
cmapisrv-mock: make mocked IP addresses configurable
Browse files Browse the repository at this point in the history
To allow configuring different ranges in case they overlap with other
infrastructural addresses, and prevent breaking connectivity.

Signed-off-by: Marco Iorio <[email protected]>
  • Loading branch information
giorio94 committed Jun 25, 2024
1 parent 35f4fa8 commit e4850e6
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
6 changes: 6 additions & 0 deletions cmapisrv-mock/deploy/cmapisrv-mock/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ spec:
- --endpoints-qps={{ .Values.config.endpointsQPS }}
- --services={{ .Values.config.services }}
- --services-qps={{ .Values.config.servicesQPS }}
- --random-node-ip4={{ .Values.config.randomNodeIP4 }}
- --random-node-ip6={{ .Values.config.randomNodeIP6 }}
- --random-pod-ip4={{ .Values.config.randomPodIP4 }}
- --random-pod-ip6={{ .Values.config.randomPodIP6 }}
- --random-svc-ip4={{ .Values.config.randomSvcIP4 }}
- --random-svc-ip6={{ .Values.config.randomSvcIP6 }}
- --kvstore-opt=etcd.config=/var/lib/cilium/etcd-config.yaml
- --kvstore-opt=etcd.qps={{ .Values.config.etcdQPS }}
- --kvstore-opt=etcd.maxInflight={{ .Values.config.etcdMaxInflight }}
Expand Down
15 changes: 15 additions & 0 deletions cmapisrv-mock/deploy/cmapisrv-mock/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ config:
# Number of service create/update/delete operations per second at run-time.
servicesQPS: 5

# The first mocked node IPv4 address
randomNodeIP4: 172.16.0.0
# The first mocked node IPv6 address
randomNodeIP6: fc00::0

# The first mocked pod IPv4 address
randomPodIP4: 10.0.0.0
# The first mocked pod IPv6 address
randomPodIP6: fd00::0

# The first mocked service IPv4 address
randomSvcIP4: 172.252.0.0
# The first mocked service IPv6 address
randomSvcIP6: fdff::0

# Global etcd rate limiting settings.
etcdQPS: 1000
etcdMaxInflight: 100
Expand Down
1 change: 1 addition & 0 deletions cmapisrv-mock/internal/mocker/cells.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var Cell = cell.Module(
"Cilium Cluster Mesh Mocker",

cell.Config(defaultConfig),
cell.Config(defaultRndcfg),

controller.Cell,
job.Cell,
Expand Down
29 changes: 29 additions & 0 deletions cmapisrv-mock/internal/mocker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,32 @@ func (def config) Flags(flags *pflag.FlagSet) {
flags.Uint("services", def.Endpoints, "Number of services to mock (per cluster)")
flags.Float64("services-qps", def.EndpointsQPS, "Services QPS (per cluster)")
}

type rndcfg struct {
RandomNodeIP4 string
RandomNodeIP6 string
RandomPodIP4 string
RandomPodIP6 string
RandomSvcIP4 string
RandomSvcIP6 string
}

var defaultRndcfg = rndcfg{
RandomNodeIP4: "172.16.0.0",
RandomNodeIP6: "fc00::0",
RandomPodIP4: "10.0.0.0",
RandomPodIP6: "fd00::0",
RandomSvcIP4: "172.252.0.0",
RandomSvcIP6: "fdff::0",
}

func (def rndcfg) Flags(flags *pflag.FlagSet) {
flags.String("random-node-ip4", def.RandomNodeIP4, "The first mocked node IPv4 address")
flags.String("random-node-ip6", def.RandomNodeIP6, "The first mocked node IPv6 address")

flags.String("random-pod-ip4", def.RandomPodIP4, "The first mocked pod IPv4 address")
flags.String("random-pod-ip6", def.RandomPodIP6, "The first mocked pod IPv6 address")

flags.String("random-svc-ip4", def.RandomSvcIP4, "The first mocked service IPv4 address")
flags.String("random-svc-ip6", def.RandomSvcIP6, "The first mocked service IPv6 address")
}
26 changes: 16 additions & 10 deletions cmapisrv-mock/internal/mocker/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ type random struct {
cidr4, cidr6 prefix
}

func newRandom() *random {
func newRandom(cfg rndcfg) (rnd *random, err error) {
defer func() {
if got := recover(); got != nil {
err = got.(error)
}
}()

return &random{
nodeIP4: addr{addr: netip.MustParseAddr("172.16.0.0")},
nodeIP6: addr{addr: netip.MustParseAddr("fc00::0")},
podIP4: addr{addr: netip.MustParseAddr("10.0.0.0")},
podIP6: addr{addr: netip.MustParseAddr("fd00::0")},
svcIP4: addr{addr: netip.MustParseAddr("172.252.0.0")},
svcIP6: addr{addr: netip.MustParseAddr("fdff::0")},
cidr4: prefix{pfx: netip.MustParsePrefix("10.0.0.0/28")},
cidr6: prefix{pfx: netip.MustParsePrefix("fd00::0/120")},
}
nodeIP4: addr{addr: netip.MustParseAddr(cfg.RandomNodeIP4)},
nodeIP6: addr{addr: netip.MustParseAddr(cfg.RandomNodeIP6)},
podIP4: addr{addr: netip.MustParseAddr(cfg.RandomPodIP4)},
podIP6: addr{addr: netip.MustParseAddr(cfg.RandomPodIP6)},
svcIP4: addr{addr: netip.MustParseAddr(cfg.RandomSvcIP4)},
svcIP6: addr{addr: netip.MustParseAddr(cfg.RandomSvcIP6)},
cidr4: prefix{pfx: netip.MustParsePrefix(cfg.RandomPodIP4 + "/28")},
cidr6: prefix{pfx: netip.MustParsePrefix(cfg.RandomPodIP6 + "/120")},
}, nil
}

func (r *random) Name() string { return petname.Generate(2, "-") }
Expand Down

0 comments on commit e4850e6

Please sign in to comment.