Skip to content

Commit ec74284

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

6 files changed

Lines changed: 23 additions & 19 deletions

File tree

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
@@ -21,6 +21,7 @@ import (
2121
"github.com/netapp/trident/core/cache"
2222
"github.com/netapp/trident/frontend"
2323
controllerhelpers "github.com/netapp/trident/frontend/csi/controller_helpers"
24+
"github.com/netapp/trident/internal/fiji"
2425
. "github.com/netapp/trident/logging"
2526
persistentstore "github.com/netapp/trident/persistent_store"
2627
"github.com/netapp/trident/pkg/capacity"
@@ -47,6 +48,8 @@ const (
4748
AttachISCSIVolumeTimeoutLong = time.Second * 90
4849
)
4950

51+
var addVolumeAfterAddVolumeTxn = fiji.Register("addVolumeAfterAddVolumeTransaction", "orchestrator_core")
52+
5053
type TridentOrchestrator struct {
5154
backends map[string]storage.Backend // key is UUID, not name
5255
volumes map[string]*storage.Volume
@@ -1932,6 +1935,11 @@ func (o *TridentOrchestrator) addVolumeInitial(
19321935
return nil, err
19331936
}
19341937

1938+
// addVolumeAfterAddVolumeTxn allows fault injection for automated testing.
1939+
if err := addVolumeAfterAddVolumeTxn.Inject(); err != nil {
1940+
return nil, err
1941+
}
1942+
19351943
// Copy the volume config into a working copy should any backend mutate the config but fail to create the volume.
19361944
mutableConfig := volumeConfig.ConstructClone()
19371945

frontend/crd/crd_controller_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,12 @@ func TestCrdControllerTransactionFinalizerRemoval(t *testing.T) {
974974
"txn": savedTxn,
975975
}).Debug("Got transaction.")
976976

977-
// Ensure the CRD was saved with a Trident finalizer
978-
if !savedTxn.HasTridentFinalizers() {
979-
t.Fatalf("expected transaction CRD to have Trident finalizer")
977+
// Ensure the CRD was saved with no Trident finalizer
978+
if savedTxn.HasTridentFinalizers() {
979+
t.Fatalf("expected transaction CRD to not have Trident finalizer")
980+
Logc(ctx()).Debug("Deleting transaction.")
980981
}
981982

982-
Logc(ctx()).Debug("Deleting transaction.")
983-
984983
// Delete the CRD
985984
deleteErr := crdClient.TridentV1().TridentTransactions(tridentNamespace).Delete(ctx(), "vol1", deleteOptions)
986985
if deleteErr != nil {

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,8 +1157,7 @@ func (k *CRDClientV1) GetVolumeTransaction(
11571157
}
11581158

11591159
func (k *CRDClientV1) DeleteVolumeTransaction(ctx context.Context, volTxn *storage.VolumeTransaction) error {
1160-
err := k.crdClient.TridentV1().TridentTransactions(k.namespace).Delete(ctx, v1.NameFix(volTxn.Name()),
1161-
k.deleteOpts())
1160+
err := k.crdClient.TridentV1().TridentTransactions(k.namespace).Delete(ctx, v1.NameFix(volTxn.Name()), k.deleteOpts())
11621161

11631162
if k8sapierrors.IsNotFound(err) {
11641163
return nil

0 commit comments

Comments
 (0)