Skip to content

Commit 0bcca53

Browse files
committed
Update tests to work with Kubebuilder 2.
1 parent 5aef772 commit 0bcca53

14 files changed

+3280
-3269
lines changed

api/v1beta1/foundationdbcluster_types.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import (
3232
)
3333

3434
// +kubebuilder:object:root=true
35+
// +kubebuilder:subresource:status
36+
// +kubebuilder:printcolumn:name="Generation",type="integer",JSONPath=".metadata.generation",description="Latest generation of the spec",priority=0
37+
// +kubebuilder:printcolumn:name="Reconciled",type="integer",JSONPath=".status.generations.reconciled",description="Last reconciled generation of the spec",priority=0
38+
// +kubebuilder:printcolumn:name="Healthy",type="boolean",JSONPath=".status.health.healthy",description="Database health",priority=0
3539

3640
// FoundationDBCluster is the Schema for the foundationdbclusters API
3741
type FoundationDBCluster struct {
@@ -837,7 +841,7 @@ func (cluster *FoundationDBCluster) GetFullAddressList(ipAddress string, primary
837841
addressMap[fmt.Sprintf("%s:4501", ipAddress)] = !cluster.Spec.MainContainer.EnableTLS
838842
}
839843

840-
addresses := make([]string, 1, len(addressMap))
844+
addresses := make([]string, 1, 1+len(addressMap))
841845
for address, primary := range addressMap {
842846
if primary {
843847
addresses[0] = address

api/v1beta1/zz_generated.deepcopy.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/apps.foundationdb.org_foundationdbclusters.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,28 @@ metadata:
88
creationTimestamp: null
99
name: foundationdbclusters.apps.foundationdb.org
1010
spec:
11+
additionalPrinterColumns:
12+
- JSONPath: .metadata.generation
13+
description: Latest generation of the spec
14+
name: Generation
15+
type: integer
16+
- JSONPath: .status.generations.reconciled
17+
description: Last reconciled generation of the spec
18+
name: Reconciled
19+
type: integer
20+
- JSONPath: .status.health.healthy
21+
description: Database health
22+
name: Healthy
23+
type: boolean
1124
group: apps.foundationdb.org
1225
names:
1326
kind: FoundationDBCluster
1427
listKind: FoundationDBClusterList
1528
plural: foundationdbclusters
1629
singular: foundationdbcluster
1730
scope: Namespaced
31+
subresources:
32+
status: {}
1833
validation:
1934
openAPIV3Schema:
2035
description: FoundationDBCluster is the Schema for the foundationdbclusters

controllers/admin_client.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ type MockAdminClient struct {
335335
KubeClient client.Client
336336
DatabaseConfiguration *fdbtypes.DatabaseConfiguration
337337
ExcludedAddresses []string
338-
ReincludedAddresses []string
338+
ReincludedAddresses map[string]bool
339339
KilledAddresses []string
340340
frozenStatus *fdbtypes.FoundationDBStatus
341341
}
@@ -352,7 +352,11 @@ func NewMockAdminClient(cluster *fdbtypes.FoundationDBCluster, kubeClient client
352352
func newMockAdminClientUncast(cluster *fdbtypes.FoundationDBCluster, kubeClient client.Client) (*MockAdminClient, error) {
353353
client := adminClientCache[cluster.Name]
354354
if client == nil {
355-
client = &MockAdminClient{Cluster: cluster, KubeClient: kubeClient}
355+
client = &MockAdminClient{
356+
Cluster: cluster,
357+
KubeClient: kubeClient,
358+
ReincludedAddresses: make(map[string]bool),
359+
}
356360
adminClientCache[cluster.Name] = client
357361
} else {
358362
client.Cluster = cluster
@@ -371,7 +375,7 @@ func (client *MockAdminClient) GetStatus() (*fdbtypes.FoundationDBStatus, error)
371375
return client.frozenStatus, nil
372376
}
373377
pods := &corev1.PodList{}
374-
err := client.KubeClient.List(context.TODO(), pods, nil)
378+
err := client.KubeClient.List(context.TODO(), pods)
375379
if err != nil {
376380
return nil, err
377381
}
@@ -478,7 +482,7 @@ func (client *MockAdminClient) IncludeInstances(addresses []string) error {
478482
for _, address := range addresses {
479483
if address == excludedAddress {
480484
included = true
481-
client.ReincludedAddresses = append(client.ReincludedAddresses, address)
485+
client.ReincludedAddresses[address] = true
482486
break
483487
}
484488
}

controllers/controller.go

+11
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ func (r *FoundationDBClusterReconciler) Reconcile(request ctrl.Request) (ctrl.Re
122122
if err != nil {
123123
log.Error(err, "Error in reconciliation", "subReconciler", fmt.Sprintf("%T", subReconciler), "namespace", cluster.Namespace, "cluster", cluster.Name)
124124
return r.checkRetryableError(err)
125+
} else if cluster.ObjectMeta.Generation != originalGeneration {
126+
log.Info("Ending reconciliation early because cluster has been updated")
127+
return ctrl.Result{}, nil
125128
} else if !canContinue {
126129
log.Info("Requeuing reconciliation", "subReconciler", fmt.Sprintf("%T", subReconciler), "namespace", cluster.Namespace, "cluster", cluster.Name)
127130
return ctrl.Result{Requeue: true, RequeueAfter: subReconciler.RequeueAfter()}, nil
@@ -139,6 +142,14 @@ func (r *FoundationDBClusterReconciler) Reconcile(request ctrl.Request) (ctrl.Re
139142
}
140143

141144
func (r *FoundationDBClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
145+
mgr.GetFieldIndexer().IndexField(&corev1.Pod{}, "metadata.name", func(o runtime.Object) []string {
146+
return []string{o.(*corev1.Pod).Name}
147+
})
148+
149+
mgr.GetFieldIndexer().IndexField(&corev1.PersistentVolumeClaim{}, "metadata.name", func(o runtime.Object) []string {
150+
return []string{o.(*corev1.PersistentVolumeClaim).Name}
151+
})
152+
142153
return ctrl.NewControllerManagedBy(mgr).
143154
For(&fdbtypes.FoundationDBCluster{}).
144155
Complete(r)

0 commit comments

Comments
 (0)