Skip to content

Commit

Permalink
Disable ACP
Browse files Browse the repository at this point in the history
  • Loading branch information
clintonk authored Sep 27, 2024
1 parent 1818e48 commit 1779f49
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 285 deletions.
16 changes: 0 additions & 16 deletions acp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,5 @@ func (c *client) GetVersionWithBackoff(ctx context.Context) (*version.Version, e
}

func (c *client) IsFeatureEnabled(ctx context.Context, feature string) error {
fields := LogFields{"feature": feature}
Logc(ctx).WithFields(fields).Debug("Checking if feature is enabled.")

if !c.Enabled() {
Logc(ctx).WithFields(fields).Warning("Feature requires Trident-ACP to be enabled.")
return errors.UnsupportedConfigError("acp is not enabled")
}

// Entitled will return different errors based on the response from the API call. Return the exact error
// so consumers of this client may act on certain error conditions.
if err := c.restClient.Entitled(ctx, feature); err != nil {
Logc(ctx).WithFields(fields).WithError(err).Error("Feature enablement failed.")
return err
}

Logc(ctx).WithFields(fields).Debug("Feature is enabled.")
return nil
}
34 changes: 1 addition & 33 deletions acp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,6 @@ func TestTridentACP_IsFeatureEnabled(t *testing.T) {
// Reset the package-level state after the test completes.
client := newClient(nil, false)
err := client.IsFeatureEnabled(ctx, FeatureSnapshotRestore)
assert.Error(t, err, "expected error")
assert.True(t, errors.IsUnsupportedConfigError(err), "should be unsupported config error")
assert.False(t, errors.IsUnlicensedError(err), "should not be unlicensed error")
})

t.Run("WithAPIErrorDuringFeatureEntitlementCheck", func(t *testing.T) {
// Reset the package-level state after the test completes.
testFeature := FeatureSnapshotRestore

mockCtrl := gomock.NewController(t)
mockRest := mock_acp.NewMockREST(mockCtrl)
mockRest.EXPECT().Entitled(ctx, testFeature).Return(fmt.Errorf("api error"))

client := newClient(mockRest, true)
err := client.IsFeatureEnabled(ctx, testFeature)
assert.Error(t, err, "expected error")
assert.False(t, errors.IsUnsupportedConfigError(err), "should not be unsupported config error")
assert.False(t, errors.IsUnlicensedError(err), "should not be unlicensed error")
})

t.Run("WhenFeatureIsNotSupported", func(t *testing.T) {
// Reset the package-level state after the test completes.
testFeature := FeatureSnapshotRestore

mockCtrl := gomock.NewController(t)
mockRest := mock_acp.NewMockREST(mockCtrl)
mockRest.EXPECT().Entitled(ctx, testFeature).Return(errors.UnlicensedError("unlicensed error"))

client := newClient(mockRest, true)
err := client.IsFeatureEnabled(ctx, testFeature)
assert.Error(t, err, "expected error")
assert.False(t, errors.IsUnsupportedConfigError(err), "should be unsupported config error")
assert.True(t, errors.IsUnlicensedError(err), "should be unlicensed error")
assert.NoError(t, err, "expected no error")
})
}
23 changes: 8 additions & 15 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,14 @@ func writeVersionTable(version *api.ClientVersionResponse) {

func writeVersionsTable(versions *api.VersionResponse) {
table := tablewriter.NewWriter(os.Stdout)
if versions.ACPServer != nil {
table.SetHeader([]string{"Server Version", "Client Version", "ACP Version"})
table.Append([]string{
versions.Server.Version,
versions.Client.Version,
versions.ACPServer.Version,
})
} else {
table.SetHeader([]string{"Server Version", "Client Version"})

table.Append([]string{
versions.Server.Version,
versions.Client.Version,
})
}

table.SetHeader([]string{"Server Version", "Client Version"})

table.Append([]string{
versions.Server.Version,
versions.Client.Version,
})

table.Render()
}

Expand Down
78 changes: 0 additions & 78 deletions frontend/crd/snapshot_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,84 +247,6 @@ func TestHandleActionSnapshotRestore(t *testing.T) {
assert.True(t, apierrors.IsNotFound(err), "TASR should not have been found")
}

func TestHandleActionSnapshotRestore_Disabled(t *testing.T) {
// Reset the package-level state after the test completes.
defer acp.SetAPI(acp.API())

mockCtrl := gomock.NewController(t)
mockACP := mockacp.NewMockTridentACP(mockCtrl)
acp.SetAPI(mockACP)
orchestrator := mockcore.NewMockOrchestrator(mockCtrl)

tridentNamespace := "trident"
kubeClient := GetTestKubernetesClientset()
snapClient := GetTestSnapshotClientset()
crdClient := GetTestCrdClientset()
crdController, err := newTridentCrdControllerImpl(orchestrator, tridentNamespace, kubeClient, snapClient, crdClient)
if err != nil {
t.Fatalf("cannot create Trident CRD controller frontend; %v", err)
}

// Mock out any expected calls on the ACP API.
// This test expects the feature call to return false / unsupported.
err = errors.UnsupportedError("unsupported feature")
mockACP.EXPECT().IsFeatureEnabled(gomock.Any(), acp.FeatureSnapshotRestore).Return(err).AnyTimes()

// Activate the CRD controller and start monitoring
if err = crdController.Activate(); err != nil {
t.Fatalf("error while activating; %v", err)
}
time.Sleep(250 * time.Millisecond)

pvc := fakeSnapRestorePVC(snapRestorePVC1, namespace1, snapRestorePV1)
_, _ = kubeClient.CoreV1().PersistentVolumeClaims(namespace1).Create(ctx(), pvc, createOpts)

pv := fakePV(snapRestorePVC1, namespace1, snapRestorePV1)
_, _ = kubeClient.CoreV1().PersistentVolumes().Create(ctx(), pv, createOpts)

vs1Time := time.Now()
vs2Time := vs1Time.Add(1 * time.Second)
vs3Time := vs2Time.Add(1 * time.Second)

vs1 := fakeVS(snapRestoreSnap1, namespace1, snapRestoreVSC1, snapRestorePVC1, vs1Time)
_, _ = snapClient.SnapshotV1().VolumeSnapshots(namespace1).Create(ctx(), vs1, createOpts)

vsc1 := fakeVSC(snapRestoreSnap1, namespace1, snapRestoreVSC1, snapRestoreSnapHandle1, vs1Time)
_, _ = snapClient.SnapshotV1().VolumeSnapshotContents().Create(ctx(), vsc1, createOpts)

vs2 := fakeVS(snapRestoreSnap2, namespace1, snapRestoreVSC2, snapRestorePVC1, vs2Time)
_, _ = snapClient.SnapshotV1().VolumeSnapshots(namespace1).Create(ctx(), vs2, createOpts)

vsc2 := fakeVSC(snapRestoreSnap2, namespace1, snapRestoreVSC2, snapRestoreSnapHandle2, vs2Time)
_, _ = snapClient.SnapshotV1().VolumeSnapshotContents().Create(ctx(), vsc2, createOpts)

vs3 := fakeVS(snapRestoreSnap3, namespace1, snapRestoreVSC3, snapRestorePVC1, vs3Time)
_, _ = snapClient.SnapshotV1().VolumeSnapshots(namespace1).Create(ctx(), vs3, createOpts)

vsc3 := fakeVSC(snapRestoreSnap3, namespace1, snapRestoreVSC3, snapRestoreSnapHandle3, vs3Time)
_, _ = snapClient.SnapshotV1().VolumeSnapshotContents().Create(ctx(), vsc3, createOpts)

tasr := fakeTASR(tasr1, namespace1, snapRestorePVC1, snapRestoreSnap3)
_, _ = crdClient.TridentV1().TridentActionSnapshotRestores(namespace1).Create(ctx(), tasr, createOpts)

// Wait until the operation completes
for i := 0; i < 20; i++ {
time.Sleep(250 * time.Millisecond)

tasr, err = crdClient.TridentV1().TridentActionSnapshotRestores(namespace1).Get(ctx(), tasr1, getOpts)
if err != nil {
if apierrors.IsNotFound(err) {
continue
}
break
} else if tasr.IsComplete() {
break
}
}

assert.True(t, tasr.Failed(), "TASR operation did not fail")
}

func TestHandleActionSnapshotRestore_InProgressError(t *testing.T) {
// Reset the package-level state after the test completes.
defer acp.SetAPI(acp.API())
Expand Down
55 changes: 0 additions & 55 deletions frontend/crd/trident_action_mirror_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,61 +338,6 @@ func TestHandleActionMirrorUpdate_InProgress(t *testing.T) {
assert.True(t, tamu.Succeeded(), "TAMU operation failed")
}

func TestHandleActionMirrorUpdate_InProgress_Disabled(t *testing.T) {
// Reset the package-level state after the test completes.
defer acp.SetAPI(acp.API())

mockCtrl := gomock.NewController(t)
mockACP := mockacp.NewMockTridentACP(mockCtrl)
acp.SetAPI(mockACP)
orchestrator := mockcore.NewMockOrchestrator(mockCtrl)

tridentNamespace := "trident"
kubeClient := GetTestKubernetesClientset()
snapClient := GetTestSnapshotClientset()
crdClient := GetTestCrdClientset()
crdController, err := newTridentCrdControllerImpl(orchestrator, tridentNamespace, kubeClient, snapClient, crdClient)
if err != nil {
t.Fatalf("cannot create Trident CRD controller frontend, error: %v", err.Error())
}

// Mock out any expected calls on the ACP API.
err = errors.UnsupportedError("unsupported")
mockACP.EXPECT().IsFeatureEnabled(gomock.Any(), acp.FeatureSnapshotMirrorUpdate).Return(err).AnyTimes()

// Activate the CRD controller and start monitoring
if err = crdController.Activate(); err != nil {
t.Fatalf("error while activating: %v", err.Error())
}
delaySeconds(1)

pvc := fakePVC(pvc1, namespace1, pv1)
_, _ = kubeClient.CoreV1().PersistentVolumeClaims(namespace1).Create(ctx(), pvc, createOpts)

tmr := fakeTMR(tmrName1, namespace1, pvc1)
_, _ = crdClient.TridentV1().TridentMirrorRelationships(namespace1).Create(ctx(), tmr, createOpts)

tamu := fakeTAMU(tamu1, namespace1, tmrName1, snapHandle1)
_, _ = crdClient.TridentV1().TridentActionMirrorUpdates(namespace1).Create(ctx(), tamu, createOpts)

// Wait until the operation completes
for i := 0; i < 5; i++ {
time.Sleep(250 * time.Millisecond)

tamu, err = crdClient.TridentV1().TridentActionMirrorUpdates(namespace1).Get(ctx(), tamu1, getOpts)
if err != nil {
if apierrors.IsNotFound(err) {
continue
}
break
} else if tamu.IsComplete() {
break
}
}

assert.True(t, tamu.Failed(), "TAMU operation was not disabled")
}

func TestHandleActionMirrorUpdate_InProgressAtStartup(t *testing.T) {
// Reset the package-level state after the test completes.
defer acp.SetAPI(acp.API())
Expand Down
3 changes: 1 addition & 2 deletions frontend/rest/controller_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ func GetVersion(w http.ResponseWriter, r *http.Request) {
response.Error = err.Error()
}
response.Version = version

response.ACPVersion = GetACPVersion(ctx)
response.ACPVersion = version
return httpStatusCodeForGetUpdateList(err)
},
)
Expand Down
2 changes: 1 addition & 1 deletion operator/controllers/orchestrator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ func (c *Controller) updateTridentOrchestratorCRStatus(
Version: version,
Namespace: namespace,
CurrentInstallationParams: installParams,
ACPVersion: acpVersion,
ACPVersion: version,
}

if reflect.DeepEqual(tridentCR.Status, newStatusDetails) {
Expand Down
38 changes: 0 additions & 38 deletions storage/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,44 +149,6 @@ func TestDeleteSnapshot_NotManaged(t *testing.T) {
assert.Errorf(t, err, "expected err")
}

func TestCloneVolume_FeatureDisabled(t *testing.T) {
// Reset the package-level state after the test completes.
defer acp.SetAPI(acp.API())

mockCtrl := gomock.NewController(t)
mockACP := mockacp.NewMockTridentACP(mockCtrl)
acp.SetAPI(mockACP)

// Mock out any expected calls on the ACP API.
err := errors.UnsupportedError("unsupported")
mockACP.EXPECT().IsFeatureEnabled(gomock.Any(), acp.FeatureReadOnlyClone).Return(err)

volumeName := "pvc-e9748b6b-8240-4fd8-97bc-868bf064ecd4"
volumeInternalName := "trident_pvc_e9748b6b_8240_4fd8_97bc_868bf064ecd4"
volumeConfig := &VolumeConfig{
Version: "",
Name: volumeName,
InternalName: volumeInternalName,
}
volumeConfigDest := &VolumeConfig{
Version: "",
Name: "pvc-deadbeef-8240-4fd8-97bc-868bf064ecd4",
InternalName: "trident_pvc_deadbeef_8240_4fd8_97bc_868bf064ecd4",
ReadOnlyClone: true,
}

backend := &StorageBackend{
state: Offline,
}
pool := NewStoragePool(nil, "test-pool1")

// Both volume and snapshot not managed
_, err = backend.CloneVolume(context.Background(), volumeConfig, volumeConfigDest, pool, false)

assert.Error(t, err, "expected err")
assert.True(t, errors.IsUnsupportedError(err))
}

func TestCloneVolume_BackendOffline(t *testing.T) {
// Reset the package-level state after the test completes.
defer acp.SetAPI(acp.API())
Expand Down
10 changes: 1 addition & 9 deletions storage_drivers/azure/azure_anf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8723,14 +8723,6 @@ func TestUpdateSnapshotDirectory_Failure(t *testing.T) {

volConfig, _, _, _, filesystem := getStructsForCreateNFSVolume(ctx, driver, storagePool)

// CASE: ACP is not enabled
mockACP.EXPECT().IsFeatureEnabled(gomock.Any(), acp.FeatureReadOnlyClone).Return(errors.New("mock error"))
result, err := driver.updateSnapshotDirectory(
ctx, volConfig.InternalName, filesystem, "TRUE", map[string]*storage.Volume{})

assert.Nil(t, result)
assert.NotNil(t, err)

// CASE: Error while modifying volume
mockACP.EXPECT().IsFeatureEnabled(gomock.Any(), acp.FeatureReadOnlyClone).Return(nil).AnyTimes()
mockAPI.EXPECT().RefreshAzureResources(ctx).Return(nil).AnyTimes()
Expand All @@ -8749,7 +8741,7 @@ func TestUpdateSnapshotDirectory_Failure(t *testing.T) {
},
}

result, err = driver.updateSnapshotDirectory(
result, err := driver.updateSnapshotDirectory(
ctx, volConfig.InternalName, filesystem, "TRUE", allVolumes)

assert.Nil(t, result)
Expand Down
39 changes: 1 addition & 38 deletions storage_drivers/ontap/ontap_nas_qtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4506,35 +4506,6 @@ func TestCanSnapshot_InvalidSnapshotDir(t *testing.T) {
assert.NotNil(t, result, "result is nil")
}

func TestCreateSnapshot_Disabled(t *testing.T) {
// Reset the package-level state after the test completes.
defer acp.SetAPI(acp.API())

mockCtrl := gomock.NewController(t)
mockACP := mockacp.NewMockTridentACP(mockCtrl)
acp.SetAPI(mockACP)
// Mock out any expected calls on the ACP API.
err := errors.UnsupportedError("unsupported")
mockACP.EXPECT().IsFeatureEnabled(gomock.Any(), acp.FeatureReadOnlyClone).Return(err)

_, driver := newMockOntapNasQtreeDriver(t)
volConfig := &storage.VolumeConfig{
Size: "1g",
Encryption: "false",
FileSystem: "nfs",
InternalName: flexvol,
InternalID: volInternalID,
}

snapConfig := &storage.SnapshotConfig{
InternalName: "snap1",
VolumeInternalName: "vol1",
}
_, err = driver.CreateSnapshot(ctx, snapConfig, volConfig)

assert.Error(t, err, "no error occurred")
}

func TestCreateSnapshot_Success(t *testing.T) {
// Reset the package-level state after the test completes.
defer acp.SetAPI(acp.API())
Expand Down Expand Up @@ -5327,18 +5298,10 @@ func TestNASQtreeStorageDriver_UpdateSnapshotDirectory_Failure(t *testing.T) {
"pvc-99138d85-6259-4830-ada0-30e45e21f843": mockVol3,
}

// CASE: ACP is not enabled for this feature
mockACP.EXPECT().IsFeatureEnabled(gomock.Any(), acp.FeatureReadOnlyClone).Return(errors.UnsupportedError("unsupported"))

result, resultErr := driver.updateSnapshotDirectory(ctx, mockVol1.Config, "invalid", true, "", allVolumes)

assert.Error(t, resultErr)
assert.Nil(t, result)

// CASE: Invalid snapshot dir value
mockACP.EXPECT().IsFeatureEnabled(gomock.Any(), acp.FeatureReadOnlyClone).Return(nil).AnyTimes()

result, resultErr = driver.updateSnapshotDirectory(ctx, mockVol1.Config, "invalid", true, "", allVolumes)
result, resultErr := driver.updateSnapshotDirectory(ctx, mockVol1.Config, "invalid", true, "", allVolumes)

assert.Error(t, resultErr)
assert.True(t, errors.IsInvalidInputError(resultErr))
Expand Down

0 comments on commit 1779f49

Please sign in to comment.