Skip to content

Commit 195e023

Browse files
authored
Update the client compatibility check to support cases where the clients have a newer version (#2320)
* Update the client compatibility check to support cases where the clients have a newer version
1 parent a39fc2d commit 195e023

File tree

5 files changed

+159
-27
lines changed

5 files changed

+159
-27
lines changed

api/v1beta2/foundationdbcluster_types.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,7 +1902,14 @@ func (cluster *FoundationDBCluster) CheckReconciliation(log logr.Logger) (bool,
19021902
}
19031903
}
19041904

1905-
if reconciled {
1905+
if reconciled && cluster.Status.Generations.Reconciled != cluster.Generation {
1906+
logger.Info(
1907+
"Update reconciled generation",
1908+
"previousGeneration",
1909+
cluster.Status.Generations.Reconciled,
1910+
"currentGeneration",
1911+
cluster.Generation,
1912+
)
19061913
cluster.Status.Generations.Reconciled = cluster.Generation
19071914
}
19081915

controllers/check_client_compatibility.go

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,46 +117,68 @@ func (c checkClientCompatibility) reconcile(
117117
return nil
118118
}
119119

120+
// foundationDBClient represents a client of the FoundationDBCluster
121+
type foundationDBClient struct {
122+
// description represents the client description.
123+
description string
124+
// supportedVersions is a map of all supported versions of this client.
125+
supportedVersions map[string]fdbv1beta2.None
126+
}
127+
120128
func getUnsupportedClients(
121129
status *fdbv1beta2.FoundationDBStatus,
122130
protocolVersion string,
123131
ignoredLogGroups map[fdbv1beta2.LogGroup]fdbv1beta2.None,
124132
) []string {
125-
var unsupportedClients []string
126-
127133
processAddresses := map[string]fdbv1beta2.None{}
128134
for _, process := range status.Cluster.Processes {
129135
processAddresses[process.Address.MachineAddress()] = fdbv1beta2.None{}
130136
}
131137

138+
var unsupportedClients []string
139+
clientSupportedVersions := map[string]*foundationDBClient{}
132140
for _, versionInfo := range status.Cluster.Clients.SupportedVersions {
133141
if versionInfo.ProtocolVersion == "Unknown" {
134142
continue
135143
}
136144

137-
if versionInfo.ProtocolVersion != protocolVersion {
138-
for _, client := range versionInfo.MaxProtocolClients {
139-
if _, ok := ignoredLogGroups[client.LogGroup]; ok {
140-
continue
141-
}
145+
for _, client := range versionInfo.ConnectedClients {
146+
if _, ok := ignoredLogGroups[client.LogGroup]; ok {
147+
continue
148+
}
142149

143-
addr, err := fdbv1beta2.ParseProcessAddress(client.Address)
144-
// In case we are not able to parse the address, we assume it is an unsupported client.
145-
if err != nil {
146-
unsupportedClients = append(unsupportedClients, client.Description())
147-
continue
148-
}
150+
addr, err := fdbv1beta2.ParseProcessAddress(client.Address)
151+
// In case we are not able to parse the address, we assume it is an unsupported client.
152+
if err != nil {
153+
unsupportedClients = append(unsupportedClients, client.Description())
154+
continue
155+
}
149156

150-
// If the address is from a running process, it's probably something running in one of the FoundationDB
151-
// Pods, like someone manually ran `fdbcli`.
152-
if _, ok := processAddresses[addr.MachineAddress()]; ok {
153-
continue
154-
}
157+
// If the address is from a running process, it's probably something running in one of the FoundationDB
158+
// Pods, like someone manually ran `fdbcli`.
159+
if _, ok := processAddresses[addr.MachineAddress()]; ok {
160+
continue
161+
}
155162

156-
unsupportedClients = append(unsupportedClients, client.Description())
163+
if currentClient, ok := clientSupportedVersions[addr.String()]; ok {
164+
currentClient.supportedVersions[versionInfo.ProtocolVersion] = fdbv1beta2.None{}
165+
} else {
166+
clientSupportedVersions[addr.String()] = &foundationDBClient{
167+
description: client.Description(),
168+
supportedVersions: map[string]fdbv1beta2.None{
169+
versionInfo.ProtocolVersion: {},
170+
},
171+
}
157172
}
158173
}
159174
}
160175

176+
// Validate for all clients that they support the requested version.
177+
for _, client := range clientSupportedVersions {
178+
if _, ok := client.supportedVersions[protocolVersion]; !ok {
179+
unsupportedClients = append(unsupportedClients, client.description)
180+
}
181+
}
182+
161183
return unsupportedClients
162184
}

controllers/check_client_compatibility_test.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,5 +348,112 @@ var _ = Describe("check client compatibility", func() {
348348
})
349349
})
350350
})
351+
352+
When("the status contains newer versions and the desired version is present", func() {
353+
BeforeEach(func() {
354+
status = &fdbv1beta2.FoundationDBStatus{
355+
Cluster: fdbv1beta2.FoundationDBStatusClusterInfo{
356+
Clients: fdbv1beta2.FoundationDBStatusClusterClientInfo{
357+
SupportedVersions: []fdbv1beta2.FoundationDBStatusSupportedVersion{
358+
{
359+
ClientVersion: "Unknown",
360+
ConnectedClients: []fdbv1beta2.FoundationDBStatusConnectedClient{
361+
{
362+
Address: "10.1.38.92:52762",
363+
LogGroup: "default",
364+
},
365+
{
366+
Address: "10.1.38.103:43346",
367+
LogGroup: "default",
368+
},
369+
},
370+
MaxProtocolClients: nil,
371+
ProtocolVersion: "Unknown",
372+
SourceVersion: "Unknown",
373+
},
374+
{
375+
ClientVersion: "6.1.8",
376+
ConnectedClients: []fdbv1beta2.FoundationDBStatusConnectedClient{
377+
{
378+
Address: "10.1.38.92:52762",
379+
LogGroup: "default",
380+
},
381+
{
382+
Address: "10.1.38.103:43346",
383+
LogGroup: "default",
384+
},
385+
},
386+
MaxProtocolClients: nil,
387+
ProtocolVersion: "fdb00b061060001",
388+
SourceVersion: "bd6b10cbcee08910667194e6388733acd3b80549",
389+
},
390+
{
391+
ClientVersion: "6.2.15",
392+
ConnectedClients: []fdbv1beta2.FoundationDBStatusConnectedClient{
393+
{
394+
Address: "10.1.38.92:52762",
395+
LogGroup: "default",
396+
},
397+
{
398+
Address: "10.1.38.103:43346",
399+
LogGroup: "default",
400+
},
401+
},
402+
MaxProtocolClients: nil,
403+
ProtocolVersion: "fdb00b062010002",
404+
SourceVersion: "20566f2ff06a7e822b30e8cfd91090fbd863a393",
405+
},
406+
407+
{
408+
ClientVersion: "6.3.15",
409+
ConnectedClients: []fdbv1beta2.FoundationDBStatusConnectedClient{
410+
{
411+
Address: "10.1.38.92:52762",
412+
LogGroup: "default",
413+
},
414+
{
415+
Address: "10.1.38.103:43346",
416+
LogGroup: "default",
417+
},
418+
},
419+
MaxProtocolClients: nil,
420+
ProtocolVersion: "fdb00b063010001",
421+
SourceVersion: "20566f2ff06a7e822b30e8cfd91090fbd863a393",
422+
},
423+
{
424+
ClientVersion: "7.4.2",
425+
ConnectedClients: []fdbv1beta2.FoundationDBStatusConnectedClient{
426+
{
427+
Address: "10.1.38.92:52762",
428+
LogGroup: "default",
429+
},
430+
{
431+
Address: "10.1.38.103:43346",
432+
LogGroup: "default",
433+
},
434+
},
435+
MaxProtocolClients: []fdbv1beta2.FoundationDBStatusConnectedClient{
436+
{
437+
Address: "10.1.38.92:52762",
438+
LogGroup: "default",
439+
},
440+
{
441+
Address: "10.1.38.103:43346",
442+
LogGroup: "default",
443+
},
444+
},
445+
ProtocolVersion: "fdb00b074000000",
446+
SourceVersion: "eb4d3fe30ecf8481e1ab966b7ef6345eb66efcf8",
447+
},
448+
},
449+
},
450+
},
451+
}
452+
})
453+
454+
It("should detect everything correctly", func() {
455+
Expect(unsupportedClients).To(BeEmpty())
456+
})
457+
})
351458
})
352459
})

controllers/cluster_controller_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,9 +2969,7 @@ var _ = Describe("cluster_controller", func() {
29692969

29702970
It("should set the image on the pods", func() {
29712971
pods := &corev1.PodList{}
2972-
err = k8sClient.List(context.TODO(), pods, getListOptions(cluster)...)
2973-
Expect(err).NotTo(HaveOccurred())
2974-
2972+
Expect(k8sClient.List(context.TODO(), pods)).To(Succeed())
29752973
for _, pod := range pods.Items {
29762974
Expect(
29772975
pod.Spec.Containers[0].Image,
@@ -2995,17 +2993,14 @@ var _ = Describe("cluster_controller", func() {
29952993
events := &corev1.EventList{}
29962994
var matchingEvents []corev1.Event
29972995

2998-
err = k8sClient.List(context.TODO(), events)
2999-
Expect(err).NotTo(HaveOccurred())
3000-
2996+
Expect(k8sClient.List(context.TODO(), events)).To(Succeed())
30012997
for _, event := range events.Items {
30022998
if event.InvolvedObject.UID == cluster.ObjectMeta.UID &&
30032999
event.Reason == "UnsupportedClient" {
30043000
matchingEvents = append(matchingEvents, event)
30053001
}
30063002
}
30073003
Expect(len(matchingEvents)).NotTo(Equal(0))
3008-
30093004
Expect(matchingEvents[0].Message).To(Equal(
30103005
fmt.Sprintf(
30113006
"1 clients do not support version 7.2.0: 127.0.0.2:3687 (%s)",

pkg/fdbadminclient/mock/admin_client_mock.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ func (client *AdminClient) GetStatus() (*fdbv1beta2.FoundationDBStatus, error) {
417417
fdbv1beta2.FoundationDBStatusSupportedVersion{
418418
ClientVersion: version,
419419
ProtocolVersion: protocolVersion,
420+
ConnectedClients: protocolClients,
420421
MaxProtocolClients: protocolClients,
421422
},
422423
)

0 commit comments

Comments
 (0)