Skip to content

Commit 5578468

Browse files
authored
Ensure that IP based environment variables are passed down as the correct argument type (#2326)
* Ensure that IP based environment variables are passed down as the correct argument type
1 parent c023235 commit 5578468

File tree

3 files changed

+141
-10
lines changed

3 files changed

+141
-10
lines changed

internal/monitor_conf.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,11 @@ func GetMonitorProcessConfiguration(
350350

351351
configuration.Arguments = append(configuration.Arguments, monitorapi.Argument{
352352
ArgumentType: monitorapi.ConcatenateArgumentType,
353-
Values: generateMonitorArgumentFromCustomParameter(argument),
353+
Values: generateMonitorArgumentFromCustomParameter(
354+
argument,
355+
cluster.GetPodIPFamily(),
356+
imageType,
357+
),
354358
})
355359
}
356360

@@ -402,6 +406,8 @@ func GetMonitorProcessConfiguration(
402406
// Generate the monitor API configuration based on the provided custom parameter
403407
func generateMonitorArgumentFromCustomParameter(
404408
argument fdbv1beta2.FoundationDBCustomParameter,
409+
podIPFamily int,
410+
imageType fdbv1beta2.ImageType,
405411
) []monitorapi.Argument {
406412
splitArgument := strings.Split(string(argument), "=")
407413
knob := strings.TrimSpace(splitArgument[0])
@@ -414,11 +420,22 @@ func generateMonitorArgumentFromCustomParameter(
414420

415421
// If the value starts with an $ we assume that the value is an environment variable and should be replaced
416422
// with the actual value.
417-
if strings.HasPrefix(splitArgument[1], "$") {
418-
customParameterArgument[1] = monitorapi.Argument{
423+
if strings.HasPrefix(knobValue, "$") {
424+
value := strings.Trim(knobValue, "$")
425+
newArgument := monitorapi.Argument{
419426
ArgumentType: monitorapi.EnvironmentArgumentType,
420-
Source: strings.Trim(knobValue, "$"),
427+
Source: value,
428+
}
429+
430+
// If a user specifies the fdbv1beta2.EnvNamePodIP or fdbv1beta2.EnvNamePublicIP environment variables in the
431+
// custom parameters, e.g. to add a new locality, we should pass this as the proper type.
432+
if podIPFamily != fdbv1beta2.PodIPFamilyUnset && imageType == fdbv1beta2.ImageTypeUnified &&
433+
(value == fdbv1beta2.EnvNamePodIP || value == fdbv1beta2.EnvNamePublicIP) {
434+
newArgument.ArgumentType = monitorapi.IPListArgumentType
435+
newArgument.IPFamily = podIPFamily
421436
}
437+
438+
customParameterArgument[1] = newArgument
422439
} else {
423440
customParameterArgument[1] = monitorapi.Argument{
424441
ArgumentType: monitorapi.LiteralArgumentType,
@@ -497,7 +514,6 @@ func buildIPArgument(
497514
)
498515

499516
flags := address.SortedFlags()
500-
501517
if len(flags) > 0 {
502518
arguments = append(
503519
arguments,

internal/monitor_conf_test.go

Lines changed: 119 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var _ = Describe("monitor_conf", func() {
5353
})
5454

5555
When("there is no connection string", func() {
56-
It("generates conf with an no processes", func() {
56+
It("generates conf with no processes", func() {
5757
Expect(cluster).NotTo(BeNil())
5858
cluster.Status.ConnectionString = ""
5959
config := GetMonitorProcessConfiguration(
@@ -595,9 +595,125 @@ var _ = Describe("monitor_conf", func() {
595595
})
596596
})
597597

598+
When("there are parameters in the general section that use the public IP", func() {
599+
BeforeEach(func() {
600+
cluster.Spec.Processes = map[fdbv1beta2.ProcessClass]fdbv1beta2.ProcessSettings{
601+
fdbv1beta2.ProcessClassGeneral: {
602+
CustomParameters: fdbv1beta2.FoundationDBCustomParameters{
603+
"locality_my_fancy_ip = $FDB_PUBLIC_IP",
604+
},
605+
},
606+
}
607+
})
608+
609+
It("includes the custom parameters", func() {
610+
config := GetMonitorProcessConfiguration(
611+
cluster,
612+
fdbv1beta2.ProcessClassStorage,
613+
1,
614+
fdbv1beta2.ImageTypeUnified,
615+
)
616+
Expect(config.Arguments).To(HaveLen(baseArgumentLength + 1))
617+
Expect(config.Arguments[10]).To(Equal(monitorapi.Argument{
618+
ArgumentType: monitorapi.ConcatenateArgumentType,
619+
Values: []monitorapi.Argument{
620+
{
621+
ArgumentType: monitorapi.LiteralArgumentType,
622+
Value: "--locality_my_fancy_ip=",
623+
},
624+
{
625+
ArgumentType: monitorapi.EnvironmentArgumentType,
626+
Source: "FDB_PUBLIC_IP",
627+
},
628+
}}))
629+
})
630+
631+
When("using IPv6 as PodIPFamily", func() {
632+
BeforeEach(func() {
633+
cluster.Spec.Routing.PodIPFamily = pointer.Int(fdbv1beta2.PodIPFamilyIPv6)
634+
})
635+
636+
It("specifies the IP family for the public address", func() {
637+
config := GetMonitorProcessConfiguration(
638+
cluster,
639+
fdbv1beta2.ProcessClassStorage,
640+
1,
641+
fdbv1beta2.ImageTypeUnified,
642+
)
643+
Expect(config.Arguments).To(HaveLen(baseArgumentLength + 1))
644+
Expect(config.Arguments[10]).To(Equal(monitorapi.Argument{
645+
ArgumentType: monitorapi.ConcatenateArgumentType,
646+
Values: []monitorapi.Argument{
647+
{
648+
ArgumentType: monitorapi.LiteralArgumentType,
649+
Value: "--locality_my_fancy_ip=",
650+
},
651+
{
652+
ArgumentType: monitorapi.IPListArgumentType,
653+
Source: "FDB_PUBLIC_IP",
654+
IPFamily: fdbv1beta2.PodIPFamilyIPv6,
655+
},
656+
}}))
657+
658+
commandLineArgs, err := config.GenerateArguments(1,
659+
map[string]string{
660+
"FDB_PUBLIC_IP": "2001:db8:dead:beef::1,192.168.0.2",
661+
"FDB_INSTANCE_ID": "test",
662+
"FDB_MACHINE_ID": "test",
663+
"FDB_ZONE_ID": "test",
664+
"FDB_DNS_NAME": "test",
665+
})
666+
Expect(err).NotTo(HaveOccurred())
667+
Expect(
668+
commandLineArgs[10],
669+
).To(Equal("--locality_my_fancy_ip=2001:db8:dead:beef::1"))
670+
})
671+
})
672+
673+
When("using IPv4 as PodIPFamily", func() {
674+
BeforeEach(func() {
675+
cluster.Spec.Routing.PodIPFamily = pointer.Int(fdbv1beta2.PodIPFamilyIPv4)
676+
})
677+
678+
It("specifies the IP family for the public address", func() {
679+
config := GetMonitorProcessConfiguration(
680+
cluster,
681+
fdbv1beta2.ProcessClassStorage,
682+
1,
683+
fdbv1beta2.ImageTypeUnified,
684+
)
685+
Expect(config.Arguments).To(HaveLen(baseArgumentLength + 1))
686+
Expect(config.Arguments[10]).To(Equal(monitorapi.Argument{
687+
ArgumentType: monitorapi.ConcatenateArgumentType,
688+
Values: []monitorapi.Argument{
689+
{
690+
ArgumentType: monitorapi.LiteralArgumentType,
691+
Value: "--locality_my_fancy_ip=",
692+
},
693+
{
694+
ArgumentType: monitorapi.IPListArgumentType,
695+
Source: "FDB_PUBLIC_IP",
696+
IPFamily: fdbv1beta2.PodIPFamilyIPv4,
697+
},
698+
}}))
699+
700+
commandLineArgs, err := config.GenerateArguments(1,
701+
map[string]string{
702+
"FDB_PUBLIC_IP": "2001:db8:dead:beef::1,192.168.0.2",
703+
"FDB_INSTANCE_ID": "test",
704+
"FDB_MACHINE_ID": "test",
705+
"FDB_ZONE_ID": "test",
706+
"FDB_DNS_NAME": "test",
707+
})
708+
Expect(err).NotTo(HaveOccurred())
709+
Expect(commandLineArgs[10]).To(Equal("--locality_my_fancy_ip=192.168.0.2"))
710+
})
711+
})
712+
})
713+
598714
When("using IPv6 as PodIPFamily", func() {
599715
BeforeEach(func() {
600-
cluster.Spec.Routing.PodIPFamily = pointer.Int(6)
716+
cluster.Spec.Routing.PodIPFamily = pointer.Int(fdbv1beta2.PodIPFamilyIPv6)
601717
})
602718

603719
It("specifies the IP family for the public address", func() {
@@ -629,7 +745,7 @@ var _ = Describe("monitor_conf", func() {
629745

630746
When("using IPv4 as PodIPFamily", func() {
631747
BeforeEach(func() {
632-
cluster.Spec.Routing.PodIPFamily = pointer.Int(4)
748+
cluster.Spec.Routing.PodIPFamily = pointer.Int(fdbv1beta2.PodIPFamilyIPv4)
633749
})
634750

635751
It("specifies the IP family for the public address", func() {

internal/pod_client_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ var _ = Describe("pod_client", func() {
3636

3737
BeforeEach(func() {
3838
cluster = CreateDefaultCluster()
39-
err := NormalizeClusterSpec(cluster, DeprecationOptions{})
40-
Expect(err).NotTo(HaveOccurred())
39+
Expect(NormalizeClusterSpec(cluster, DeprecationOptions{})).To(Succeed())
4140
})
4241

4342
Context("with TLS disabled", func() {

0 commit comments

Comments
 (0)