Skip to content

Commit a12483d

Browse files
jharrodjwebster7
andauthored
25.10 Address volume creations failures caused by stale transactions from Trident restarts
Co-authored-by: Joe Webster <31218426+jwebster7@users.noreply.github.com>
1 parent 05e0ac5 commit a12483d

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

cli/k8s_client/k8s_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 NetApp, Inc. All Rights Reserved.
1+
// Copyright 2025 NetApp, Inc. All Rights Reserved.
22

33
package k8sclient
44

core/orchestrator_core.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/netapp/trident/core/metrics"
2323
"github.com/netapp/trident/frontend"
2424
controllerhelpers "github.com/netapp/trident/frontend/csi/controller_helpers"
25+
"github.com/netapp/trident/internal/fiji"
2526
. "github.com/netapp/trident/logging"
2627
persistentstore "github.com/netapp/trident/persistent_store"
2728
"github.com/netapp/trident/pkg/capacity"
@@ -42,6 +43,8 @@ import (
4243
"github.com/netapp/trident/utils/nvme"
4344
)
4445

46+
var addVolumeAfterAddVolumeTxn = fiji.Register("addVolumeAfterAddVolumeTransaction", "orchestrator_core")
47+
4548
type TridentOrchestrator struct {
4649
backends map[string]storage.Backend // key is UUID, not name
4750
volumes map[string]*storage.Volume
@@ -2005,6 +2008,11 @@ func (o *TridentOrchestrator) addVolumeInitial(
20052008
return nil, err
20062009
}
20072010

2011+
// addVolumeAfterAddVolumeTxn allows fault injection for automated testing.
2012+
if err := addVolumeAfterAddVolumeTxn.Inject(); err != nil {
2013+
return nil, err
2014+
}
2015+
20082016
// Copy the volume config into a working copy should any backend mutate the config but fail to create the volume.
20092017
mutableConfig := volumeConfig.ConstructClone()
20102018

frontend/crd/crd_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,9 +1056,9 @@ func TestCrdControllerTransactionFinalizerRemoval(t *testing.T) {
10561056
"txn": savedTxn,
10571057
}).Debug("Got transaction.")
10581058

1059-
// Ensure the CRD was saved with a Trident finalizer
1060-
if !savedTxn.HasTridentFinalizers() {
1061-
t.Fatalf("expected transaction CRD to have Trident finalizer")
1059+
// Ensure the CRD was saved with no Trident finalizer
1060+
if savedTxn.HasTridentFinalizers() {
1061+
t.Fatalf("expected transaction CRD to not have Trident finalizer")
10621062
}
10631063

10641064
Logc(ctx()).Debug("Deleting transaction.")

persistent_store/crd/apis/netapp/v1/transaction.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ func NewTridentTransaction(txn *storage.VolumeTransaction) (*TridentTransaction,
1919
Kind: "TridentTransaction",
2020
},
2121
ObjectMeta: metav1.ObjectMeta{
22-
Name: NameFix(txn.Name()),
23-
Finalizers: GetTridentFinalizers(),
22+
Name: NameFix(txn.Name()),
2423
},
2524
}
2625

persistent_store/crd/apis/netapp/v1/transaction_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 NetApp, Inc. All Rights Reserved.
1+
// Copyright 2025 NetApp, Inc. All Rights Reserved.
22

33
package v1
44

@@ -7,6 +7,7 @@ import (
77
"reflect"
88
"testing"
99

10+
"github.com/stretchr/testify/assert"
1011
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112
"k8s.io/apimachinery/pkg/runtime"
1213

@@ -41,8 +42,7 @@ func TestNewTransaction(t *testing.T) {
4142
Kind: "TridentTransaction",
4243
},
4344
ObjectMeta: metav1.ObjectMeta{
44-
Name: NameFix(volConfig.Name),
45-
Finalizers: GetTridentFinalizers(),
45+
Name: NameFix(volConfig.Name),
4646
},
4747
Transaction: runtime.RawExtension{
4848
Raw: MustEncode(json.Marshal(txn)),
@@ -53,6 +53,7 @@ func TestNewTransaction(t *testing.T) {
5353
if !reflect.DeepEqual(volumeTransaction, expected) {
5454
t.Fatalf("TridentTransaction does not match expected result, got %v expected %v", volumeTransaction, expected)
5555
}
56+
assert.Empty(t, volumeTransaction.Finalizers) // Transactions should never have finalizers.
5657
}
5758

5859
func TestNewSnapshotTransaction(t *testing.T) {
@@ -88,8 +89,7 @@ func TestNewSnapshotTransaction(t *testing.T) {
8889
Kind: "TridentTransaction",
8990
},
9091
ObjectMeta: metav1.ObjectMeta{
91-
Name: NameFix(volConfig.Name),
92-
Finalizers: GetTridentFinalizers(),
92+
Name: NameFix(volConfig.Name),
9393
},
9494
Transaction: runtime.RawExtension{
9595
Raw: MustEncode(json.Marshal(txn)),
@@ -100,6 +100,7 @@ func TestNewSnapshotTransaction(t *testing.T) {
100100
if !reflect.DeepEqual(volumeTransaction, expected) {
101101
t.Fatalf("TridentTransaction does not match expected result, got %v expected %v", volumeTransaction, expected)
102102
}
103+
assert.Empty(t, volumeTransaction.Finalizers) // Transactions should never have finalizers.
103104
}
104105

105106
func TestTransaction_Persistent(t *testing.T) {
@@ -123,8 +124,7 @@ func TestTransaction_Persistent(t *testing.T) {
123124
Kind: "TridentTransaction",
124125
},
125126
ObjectMeta: metav1.ObjectMeta{
126-
Name: NameFix(volConfig.Name),
127-
Finalizers: GetTridentFinalizers(),
127+
Name: NameFix(volConfig.Name),
128128
},
129129
Transaction: runtime.RawExtension{
130130
Raw: MustEncode(json.Marshal(txn)),
@@ -180,8 +180,7 @@ func TestSnapshotTransaction_Persistent(t *testing.T) {
180180
Kind: "TridentTransaction",
181181
},
182182
ObjectMeta: metav1.ObjectMeta{
183-
Name: NameFix(volConfig.Name),
184-
Finalizers: GetTridentFinalizers(),
183+
Name: NameFix(volConfig.Name),
185184
},
186185
Transaction: runtime.RawExtension{
187186
Raw: MustEncode(json.Marshal(txn)),

persistent_store/crdv1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ func (k *CRDClientV1) GetVolumeTransaction(
11631163
}
11641164

11651165
func (k *CRDClientV1) DeleteVolumeTransaction(ctx context.Context, volTxn *storage.VolumeTransaction) error {
1166-
ctx = context.WithoutCancel(ctx) // Transactions should not be cancelled
1166+
ctx = context.WithoutCancel(ctx) // Transactions should not be canceled
11671167

11681168
err := k.crdClient.TridentV1().TridentTransactions(k.namespace).Delete(ctx, v1.NameFix(volTxn.Name()),
11691169
k.deleteOpts())

0 commit comments

Comments
 (0)