Skip to content

Commit daee8bd

Browse files
authored
Improve capabilities check for case when TKR is newer than supervisor (#3514)
1 parent 44c8987 commit daee8bd

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ func (c *K8sOrchestrator) HandleLateEnablementOfCapability(ctx context.Context,
11271127
_, err = apiextensionsClientSet.ApiextensionsV1().CustomResourceDefinitions().Get(ctx,
11281128
"capabilities.iaas.vmware.com", metav1.GetOptions{})
11291129
if err != nil {
1130-
if apierrors.IsNotFound(err) {
1130+
if apierrors.IsNotFound(err) || apierrors.IsForbidden(err) {
11311131
// If capabilities CR is not registered on supervisor, then sleep for some time and check
11321132
// again if CR has been registered on supervisor. If TKR is new, but supervisor is old, then
11331133
// it could happen that capabilities CR is not registered on the supervisor cluster.
@@ -1343,6 +1343,32 @@ func (c *K8sOrchestrator) IsFSSEnabled(ctx context.Context, featureName string)
13431343
}
13441344
// Get rest client config for supervisor.
13451345
restClientConfig := k8s.GetRestClientConfigForSupervisor(ctx, cfg.GC.Endpoint, cfg.GC.Port)
1346+
// Check if CRD for capabilities exists
1347+
// If CRD does not exist on supervisor then skip further capability check
1348+
// this is case when tkr is newer and supervisor is older where capabilities CRD does not exist.
1349+
apiextensionsClientSet, err := apiextensionsclientset.NewForConfig(restClientConfig)
1350+
if err != nil {
1351+
log.Errorf("failed to create apiextension clientset using config. Err: %+v", err)
1352+
return false
1353+
}
1354+
_, err = apiextensionsClientSet.ApiextensionsV1().CustomResourceDefinitions().Get(ctx,
1355+
"capabilities.iaas.vmware.com", metav1.GetOptions{})
1356+
if err != nil {
1357+
if featureName == common.WorkloadDomainIsolationFSS {
1358+
// prefer CSI internal feature-state configmap for workload-domain-isolation feature
1359+
// in case capabilities CRD is not registred on supervisor
1360+
log.Info("CSI workload-domain-isolation is set to true in pvcsi fss configmap. " +
1361+
"check if it is enabled in cns-csi fss")
1362+
return c.IsCNSCSIFSSEnabled(ctx, featureName)
1363+
}
1364+
if apierrors.IsNotFound(err) || apierrors.IsForbidden(err) {
1365+
log.Info("CR instance capabilities.iaas.vmware.com is not registered on supervisor, " +
1366+
"considering feature to be false")
1367+
return false
1368+
}
1369+
log.Errorf("failed to check if Capabilities CR is registered. Err: %v", err)
1370+
return false
1371+
}
13461372
wcpCapabilityApiClient, err := k8s.NewClientForGroup(ctx, restClientConfig, wcpcapapis.GroupName)
13471373
if err != nil {
13481374
log.Errorf("failed to create wcpCapabilityApi client. Err: %+v", err)

0 commit comments

Comments
 (0)