Skip to content

Commit b3c9173

Browse files
authored
Handle Late enbalement of shared disk capability (#3746)
1 parent e667792 commit b3c9173

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

pkg/csi/service/common/commonco/k8sorchestrator/k8sorchestrator_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ import (
2525

2626
cnstypes "github.com/vmware/govmomi/cns/types"
2727
v1 "k8s.io/api/core/v1"
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/runtime/schema"
2830

31+
"github.com/stretchr/testify/assert"
32+
"k8s.io/apimachinery/pkg/runtime"
33+
"sigs.k8s.io/controller-runtime/pkg/client/fake"
34+
wcpcapv1alph1 "sigs.k8s.io/vsphere-csi-driver/v3/pkg/apis/wcpcapabilities/v1alpha1"
2935
cnsconfig "sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/config"
36+
"sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service/common"
3037
)
3138

3239
var (
@@ -319,3 +326,45 @@ func TestIsFileVolume(t *testing.T) {
319326
})
320327
}
321328
}
329+
330+
func TestSetWcpCapabilitiesMap_Success(t *testing.T) {
331+
ctx := context.Background()
332+
WcpCapabilitiesMap = nil
333+
334+
scheme := runtime.NewScheme()
335+
gvk := schema.GroupVersionKind{
336+
Group: "wcp.vmware.com",
337+
Version: "v1alpha1",
338+
Kind: "Capabilities",
339+
}
340+
341+
scheme.AddKnownTypeWithName(
342+
gvk,
343+
&wcpcapv1alph1.Capabilities{},
344+
)
345+
cap := &wcpcapv1alph1.Capabilities{
346+
ObjectMeta: metav1.ObjectMeta{
347+
Name: common.WCPCapabilitiesCRName,
348+
},
349+
Status: wcpcapv1alph1.CapabilitiesStatus{
350+
Supervisor: map[wcpcapv1alph1.CapabilityName]wcpcapv1alph1.CapabilityStatus{
351+
"CapabilityA": {Activated: true},
352+
"CapabilityB": {Activated: false},
353+
},
354+
},
355+
}
356+
357+
cl := fake.NewClientBuilder().
358+
WithScheme(scheme).
359+
WithObjects(cap).
360+
Build()
361+
362+
err := SetWcpCapabilitiesMap(ctx, cl)
363+
assert.NoError(t, err)
364+
365+
val, _ := WcpCapabilitiesMap.Load("CapabilityA")
366+
assert.Equal(t, true, val)
367+
368+
val, _ = WcpCapabilitiesMap.Load("CapabilityB")
369+
assert.Equal(t, false, val)
370+
}

pkg/csi/service/wcp/controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ func (c *controller) Init(config *cnsconfig.Config, version string) error {
173173
return logger.LogNewErrorf(log, "failed to start zone informer. Error: %v", err)
174174
}
175175
}
176+
if !commonco.ContainerOrchestratorUtility.IsFSSEnabled(ctx,
177+
common.SharedDiskFss) {
178+
go commonco.ContainerOrchestratorUtility.HandleLateEnablementOfCapability(ctx, cnstypes.CnsClusterFlavorWorkload,
179+
common.SharedDiskFss, "", "")
180+
}
176181
if idempotencyHandlingEnabled {
177182
log.Info("CSI Volume manager idempotency handling feature flag is enabled.")
178183
operationStore, err = cnsvolumeoperationrequest.InitVolumeOperationRequestInterface(ctx,

pkg/syncer/admissionhandler/admissionhandler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func StartWebhookServer(ctx context.Context, enableWebhookClientCertVerification
157157
go containerOrchestratorUtility.HandleLateEnablementOfCapability(ctx, cnstypes.CnsClusterFlavorWorkload,
158158
common.LinkedCloneSupport, "", "")
159159
}
160+
if !featureIsSharedDiskEnabled {
161+
go containerOrchestratorUtility.HandleLateEnablementOfCapability(ctx, cnstypes.CnsClusterFlavorWorkload,
162+
common.SharedDiskFss, "", "")
163+
}
160164
if err := startCNSCSIWebhookManager(ctx, enableWebhookClientCertVerification,
161165
containerOrchestratorUtility); err != nil {
162166
return fmt.Errorf("unable to run the webhook manager: %w", err)

pkg/syncer/metadatasyncer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ func InitMetadataSyncer(ctx context.Context, clusterFlavor cnstypes.CnsClusterFl
359359
go commonco.ContainerOrchestratorUtility.HandleLateEnablementOfCapability(ctx, clusterFlavor,
360360
common.WCPMobilityNonDisruptiveImport, "", "")
361361
}
362+
if !isSharedDiskEabled {
363+
go commonco.ContainerOrchestratorUtility.HandleLateEnablementOfCapability(ctx,
364+
clusterFlavor, common.SharedDiskFss, "", "")
365+
}
362366
}
363367

364368
if metadataSyncer.clusterFlavor == cnstypes.CnsClusterFlavorGuest {

0 commit comments

Comments
 (0)