Skip to content

Commit

Permalink
fix(bug): Remove FIQL based filters from list calls (#485)
Browse files Browse the repository at this point in the history
* fix(bug): Remove FIQL based filters from list calls

FIQL filtering has been deprecated by the APIs for some time now.
We should avoid using it altogether.

* use strings.EqualFold for string comparison after list calls
  • Loading branch information
thunderboltsid authored Oct 2, 2024
1 parent 78f61d1 commit b983688
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,15 @@ func GetPEUUID(ctx context.Context, client *prismclientv3.Client, peName, peUUID
}
return *peIntentResponse.Metadata.UUID, nil
} else if peName != nil && *peName != "" {
filter := getFilterForName(*peName)
responsePEs, err := client.V3.ListAllCluster(ctx, filter)
responsePEs, err := client.V3.ListAllCluster(ctx, "")
if err != nil {
return "", err
}
// Validate filtered PEs
foundPEs := make([]*prismclientv3.ClusterIntentResponse, 0)
for _, s := range responsePEs.Entities {
peSpec := s.Spec
if *peSpec.Name == *peName && hasPEClusterServiceEnabled(s, serviceNamePECluster) {
if strings.EqualFold(*peSpec.Name, *peName) && hasPEClusterServiceEnabled(s, serviceNamePECluster) {
foundPEs = append(foundPEs, s)
}
}
Expand Down Expand Up @@ -261,10 +260,9 @@ func GetSubnetUUID(ctx context.Context, client *prismclientv3.Client, peUUID str
}
}
foundSubnetUUID = *subnetIntentResponse.Metadata.UUID
} else if subnetName != nil {
filter := getFilterForName(*subnetName)
} else { // else search by name
// Not using additional filtering since we want to list overlay and vlan subnets
responseSubnets, err := client.V3.ListAllSubnet(ctx, filter, nil)
responseSubnets, err := client.V3.ListAllSubnet(ctx, "", nil)
if err != nil {
return "", err
}
Expand All @@ -274,7 +272,7 @@ func GetSubnetUUID(ctx context.Context, client *prismclientv3.Client, peUUID str
if subnet == nil || subnet.Spec == nil || subnet.Spec.Name == nil || subnet.Spec.Resources == nil || subnet.Spec.Resources.SubnetType == nil {
continue
}
if *subnet.Spec.Name == *subnetName {
if strings.EqualFold(*subnet.Spec.Name, *subnetName) {
if *subnet.Spec.Resources.SubnetType == subnetTypeOverlay {
// Overlay subnets are present on all PEs managed by PC.
foundSubnets = append(foundSubnets, subnet)
Expand Down Expand Up @@ -315,17 +313,16 @@ func GetImageUUID(ctx context.Context, client *prismclientv3.Client, imageName,
}
}
foundImageUUID = *imageIntentResponse.Metadata.UUID
} else if imageName != nil {
filter := getFilterForName(*imageName)
responseImages, err := client.V3.ListAllImage(ctx, filter)
} else { // else search by name
responseImages, err := client.V3.ListAllImage(ctx, "")
if err != nil {
return "", err
}
// Validate filtered Images
foundImages := make([]*prismclientv3.ImageIntentResponse, 0)
for _, s := range responseImages.Entities {
imageSpec := s.Spec
if *imageSpec.Name == *imageName {
if strings.EqualFold(*imageSpec.Name, *imageName) {
foundImages = append(foundImages, s)
}
}
Expand Down Expand Up @@ -636,16 +633,15 @@ func GetProjectUUID(ctx context.Context, client *prismclientv3.Client, projectNa
}
}
foundProjectUUID = *projectIntentResponse.Metadata.UUID
} else if projectName != nil {
filter := getFilterForName(*projectName)
responseProjects, err := client.V3.ListAllProject(ctx, filter)
} else { // else search by name
responseProjects, err := client.V3.ListAllProject(ctx, "")
if err != nil {
return "", err
}
foundProjects := make([]*prismclientv3.Project, 0)
for _, s := range responseProjects.Entities {
projectSpec := s.Spec
if projectSpec.Name == *projectName {
if strings.EqualFold(projectSpec.Name, *projectName) {
foundProjects = append(foundProjects, s)
}
}
Expand All @@ -663,10 +659,6 @@ func GetProjectUUID(ctx context.Context, client *prismclientv3.Client, projectNa
return foundProjectUUID, nil
}

func getFilterForName(name string) string {
return fmt.Sprintf("name==%s", name)
}

func hasPEClusterServiceEnabled(peCluster *prismclientv3.ClusterIntentResponse, serviceName string) bool {
if peCluster.Status == nil ||
peCluster.Status.Resources == nil ||
Expand Down

0 comments on commit b983688

Please sign in to comment.