diff --git a/cmapisrv-mock/deploy/cmapisrv-mock/templates/deployment.yaml b/cmapisrv-mock/deploy/cmapisrv-mock/templates/deployment.yaml index 67b4dcc3..c1fdf5ff 100644 --- a/cmapisrv-mock/deploy/cmapisrv-mock/templates/deployment.yaml +++ b/cmapisrv-mock/deploy/cmapisrv-mock/templates/deployment.yaml @@ -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 }} diff --git a/cmapisrv-mock/deploy/cmapisrv-mock/values.yaml b/cmapisrv-mock/deploy/cmapisrv-mock/values.yaml index 4c1c73b2..e48b92f4 100644 --- a/cmapisrv-mock/deploy/cmapisrv-mock/values.yaml +++ b/cmapisrv-mock/deploy/cmapisrv-mock/values.yaml @@ -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 diff --git a/cmapisrv-mock/internal/mocker/cells.go b/cmapisrv-mock/internal/mocker/cells.go index f9385c48..356ce6f9 100644 --- a/cmapisrv-mock/internal/mocker/cells.go +++ b/cmapisrv-mock/internal/mocker/cells.go @@ -23,6 +23,7 @@ var Cell = cell.Module( "Cilium Cluster Mesh Mocker", cell.Config(defaultConfig), + cell.Config(defaultRndcfg), controller.Cell, job.Cell, diff --git a/cmapisrv-mock/internal/mocker/config.go b/cmapisrv-mock/internal/mocker/config.go index 53aca7ee..5b68c9a3 100644 --- a/cmapisrv-mock/internal/mocker/config.go +++ b/cmapisrv-mock/internal/mocker/config.go @@ -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") +} diff --git a/cmapisrv-mock/internal/mocker/random.go b/cmapisrv-mock/internal/mocker/random.go index db87cc19..fac3f63d 100644 --- a/cmapisrv-mock/internal/mocker/random.go +++ b/cmapisrv-mock/internal/mocker/random.go @@ -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, "-") }