Skip to content

Commit 5c9da3f

Browse files
fix(bug): Remove crude check for prism central version (#509) (#512)
Earlier we had a crude check on prism central version which checked if prism central version is higher than 2024.1. We remove this check and assume that the underlying prism central is within support lifespan. This fixes the false positive issues when this check failed for newer PC versioning scheme of following AOS version i.e. PC7.3.
1 parent 5b61bb1 commit 5c9da3f

File tree

4 files changed

+4
-171
lines changed

4 files changed

+4
-171
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ The API itself is shared across multiple cloud providers allowing for true Nutan
2020
## How to Deploy a Kubernetes Cluster on Nutanix Cloud Infrastucture
2121
Check out the [getting started guide](https://opendocs.nutanix.com/capx/latest/getting_started/) for launching a cluster on Nutanix Cloud Infrastructure.
2222

23-
## Features
23+
## Compatibility with Prism Central & Prism Element
2424

25-
## Compatibility with Cluster API and Kubernetes Versions
25+
| CAPX Version | Min. Prism Central Version | Min. Prism Element Version |
26+
|--------------|----------------------------|----------------------------|
27+
| 1.5.x | pc2024.1+ | 6.5+ |
2628

2729
## Documentation
2830
Visit the `Cluster API Provider: Nutanix (CAPX)` section on [opendocs.nutanix.com](https://opendocs.nutanix.com/) for all documentation related to CAPX.

controllers/helpers.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ package controllers
1818

1919
import (
2020
"context"
21-
"errors"
2221
"fmt"
2322
"reflect"
24-
"strconv"
2523
"strings"
2624
"time"
2725

@@ -812,67 +810,6 @@ func getPrismCentralV4ClientForCluster(ctx context.Context, cluster *infrav1.Nut
812810
return client, nil
813811
}
814812

815-
// isPrismCentralV4Compatible checks if the Prism Central is v4 API compatible
816-
func isPrismCentralV4Compatible(ctx context.Context, v3Client *prismclientv3.Client) (bool, error) {
817-
log := ctrl.LoggerFrom(ctx)
818-
internalPCNames := []string{"master", "fraser"}
819-
pcVersion, err := getPrismCentralVersion(ctx, v3Client)
820-
if err != nil {
821-
return false, fmt.Errorf("failed to get Prism Central version: %w", err)
822-
}
823-
824-
// Check if the version is v4 compatible
825-
// PC versions look like pc.2024.1.0.1
826-
// We can check if the version is greater than or equal to 2024
827-
828-
if pcVersion == "" {
829-
return false, errors.New("prism central version is empty")
830-
}
831-
832-
for _, internalPCName := range internalPCNames {
833-
// TODO(sid): This is a naive check to see if the PC version is an internal build. This can potentially lead to failures
834-
// if internal fraser build is not v4 compatible.
835-
if strings.Contains(pcVersion, internalPCName) {
836-
log.Info(fmt.Sprintf("Prism Central version %s is an internal build; assuming it is v4 compatible", pcVersion))
837-
return true, nil
838-
}
839-
}
840-
841-
// Remove the prefix "pc."
842-
version := strings.TrimPrefix(pcVersion, "pc.")
843-
// Split the version string by "." to extract the year part
844-
parts := strings.Split(version, ".")
845-
if len(parts) < 1 {
846-
return false, errors.New("invalid version format")
847-
}
848-
849-
// Convert the year part to an integer
850-
year, err := strconv.Atoi(parts[0])
851-
if err != nil {
852-
return false, errors.New("invalid version: failed to parse year from PC version")
853-
}
854-
855-
if year >= 2024 {
856-
return true, nil
857-
}
858-
859-
return false, nil
860-
}
861-
862-
// getPrismCentralVersion returns the version of the Prism Central instance
863-
func getPrismCentralVersion(ctx context.Context, v3Client *prismclientv3.Client) (string, error) {
864-
pcInfo, err := v3Client.V3.GetPrismCentral(ctx)
865-
if err != nil {
866-
return "", err
867-
}
868-
869-
if pcInfo.Resources == nil || pcInfo.Resources.Version == nil {
870-
return "", fmt.Errorf("failed to get Prism Central version")
871-
}
872-
873-
return *pcInfo.Resources.Version, nil
874-
}
875-
876813
func detachVolumeGroupsFromVM(ctx context.Context, v4Client *prismclientv4.Client, vmName string, vmUUID string, vmDiskList []*prismclientv3.VMDisk) error {
877814
log := ctrl.LoggerFrom(ctx)
878815
volumeGroupsToDetach := make([]string, 0)

controllers/nutanixmachine_controller.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,6 @@ func (r *NutanixMachineReconciler) reconcileDelete(rctx *nctx.MachineContext) (r
404404
}
405405

406406
func (r *NutanixMachineReconciler) detachVolumeGroups(rctx *nctx.MachineContext, vmName string, vmUUID string, vmDiskList []*prismclientv3.VMDisk) error {
407-
createV4Client, err := isPrismCentralV4Compatible(rctx.Context, rctx.NutanixClient)
408-
if err != nil {
409-
return fmt.Errorf("error occurred while checking compatibility for Prism Central v4 APIs: %w", err)
410-
}
411-
412-
if !createV4Client {
413-
return nil
414-
}
415-
416407
v4Client, err := getPrismCentralV4ClientForCluster(rctx.Context, rctx.NutanixCluster, r.SecretInformer, r.ConfigMapInformer)
417408
if err != nil {
418409
return fmt.Errorf("error occurred while fetching Prism Central v4 client: %w", err)

controllers/nutanixmachine_controller_test.go

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
credentialTypes "github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
2626
prismclientv3 "github.com/nutanix-cloud-native/prism-go-client/v3"
27-
"github.com/nutanix-cloud-native/prism-go-client/v3/models"
2827
. "github.com/onsi/ginkgo/v2"
2928
. "github.com/onsi/gomega"
3029
"github.com/stretchr/testify/assert"
@@ -241,102 +240,6 @@ func TestNutanixMachineReconciler(t *testing.T) {
241240
g.Expect(err).To(HaveOccurred())
242241
})
243242
})
244-
245-
Context("Detaches a volume group on deletion", func() {
246-
It("should error if get prism central returns error", func() {
247-
mockctrl := gomock.NewController(t)
248-
mockv3Service := mocknutanixv3.NewMockService(mockctrl)
249-
mockv3Service.EXPECT().GetPrismCentral(gomock.Any()).Return(nil, errors.New("error"))
250-
251-
v3Client := &prismclientv3.Client{
252-
V3: mockv3Service,
253-
}
254-
err := reconciler.detachVolumeGroups(&nctx.MachineContext{
255-
NutanixClient: v3Client,
256-
},
257-
"",
258-
ntnxMachine.Status.VmUUID,
259-
[]*prismclientv3.VMDisk{},
260-
)
261-
g.Expect(err).To(HaveOccurred())
262-
})
263-
264-
It("should error if prism central version is empty", func() {
265-
mockctrl := gomock.NewController(t)
266-
mockv3Service := mocknutanixv3.NewMockService(mockctrl)
267-
mockv3Service.EXPECT().GetPrismCentral(gomock.Any()).Return(&models.PrismCentral{Resources: &models.PrismCentralResources{
268-
Version: ptr.To(""),
269-
}}, nil)
270-
271-
v3Client := &prismclientv3.Client{
272-
V3: mockv3Service,
273-
}
274-
err := reconciler.detachVolumeGroups(&nctx.MachineContext{
275-
NutanixClient: v3Client,
276-
}, "",
277-
ntnxMachine.Status.VmUUID,
278-
[]*prismclientv3.VMDisk{},
279-
)
280-
g.Expect(err).To(HaveOccurred())
281-
})
282-
283-
It("should error if prism central version value is absent", func() {
284-
mockctrl := gomock.NewController(t)
285-
mockv3Service := mocknutanixv3.NewMockService(mockctrl)
286-
mockv3Service.EXPECT().GetPrismCentral(gomock.Any()).Return(&models.PrismCentral{Resources: &models.PrismCentralResources{
287-
Version: ptr.To("pc."),
288-
}}, nil)
289-
290-
v3Client := &prismclientv3.Client{
291-
V3: mockv3Service,
292-
}
293-
err := reconciler.detachVolumeGroups(&nctx.MachineContext{
294-
NutanixClient: v3Client,
295-
}, "",
296-
ntnxMachine.Status.VmUUID,
297-
[]*prismclientv3.VMDisk{},
298-
)
299-
g.Expect(err).To(HaveOccurred())
300-
})
301-
302-
It("should error if prism central version is invalid", func() {
303-
mockctrl := gomock.NewController(t)
304-
mockv3Service := mocknutanixv3.NewMockService(mockctrl)
305-
mockv3Service.EXPECT().GetPrismCentral(gomock.Any()).Return(&models.PrismCentral{Resources: &models.PrismCentralResources{
306-
Version: ptr.To("not.a.valid.version"),
307-
}}, nil)
308-
309-
v3Client := &prismclientv3.Client{
310-
V3: mockv3Service,
311-
}
312-
err := reconciler.detachVolumeGroups(&nctx.MachineContext{
313-
NutanixClient: v3Client,
314-
}, "",
315-
ntnxMachine.Status.VmUUID,
316-
[]*prismclientv3.VMDisk{},
317-
)
318-
g.Expect(err).To(HaveOccurred())
319-
})
320-
321-
It("should not error if prism central is not v4 compatible", func() {
322-
mockctrl := gomock.NewController(t)
323-
mockv3Service := mocknutanixv3.NewMockService(mockctrl)
324-
mockv3Service.EXPECT().GetPrismCentral(gomock.Any()).Return(&models.PrismCentral{Resources: &models.PrismCentralResources{
325-
Version: ptr.To("pc.2023.4.0.1"),
326-
}}, nil)
327-
328-
v3Client := &prismclientv3.Client{
329-
V3: mockv3Service,
330-
}
331-
err := reconciler.detachVolumeGroups(&nctx.MachineContext{
332-
NutanixClient: v3Client,
333-
}, "",
334-
ntnxMachine.Status.VmUUID,
335-
[]*prismclientv3.VMDisk{},
336-
)
337-
g.Expect(err).To(Not(HaveOccurred()))
338-
})
339-
})
340243
})
341244
}
342245

0 commit comments

Comments
 (0)