Skip to content

Commit

Permalink
PLT-851: Fixed get cluster by name API context.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikchern committed Nov 29, 2023
1 parent 8cbb4d1 commit 357cb9a
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions client/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ func getClusterFilter(extraFilters []*models.V1SearchFilterItem) *models.V1Searc
{
Conjunction: and(),
Filters: []*models.V1SearchFilterItem{
{
Condition: &models.V1SearchFilterCondition{
String: &models.V1SearchFilterStringCondition{
Match: &models.V1SearchFilterStringConditionMatch{
Conjunction: or(),
Values: []string{"nested"},
},
Negation: true,
Operator: models.V1SearchFilterStringOperatorEq,
},
},
Property: "environment",
Type: models.V1SearchFilterPropertyTypeString,
},
{
Condition: &models.V1SearchFilterCondition{
Bool: &models.V1SearchFilterBoolCondition{
Expand All @@ -37,40 +51,44 @@ func getClusterFilter(extraFilters []*models.V1SearchFilterItem) *models.V1Searc
},
}

filter.FilterGroups[0].Filters = append(filter.FilterGroups[0].Filters, extraFilters...)
filter.FilterGroups = append(filter.FilterGroups, &models.V1SearchFilterGroup{Conjunction: and(), Filters: extraFilters})

return filter
}

func nameFilter(name string) *models.V1SearchFilterItem {
func clusterNameEqFilter(name string) *models.V1SearchFilterItem {
return &models.V1SearchFilterItem{
Condition: &models.V1SearchFilterCondition{
String: &models.V1SearchFilterStringCondition{
Match: &models.V1SearchFilterStringConditionMatch{
Conjunction: or(),
Values: []string{name},
},
Operator: models.V1SearchFilterStringOperatorEq,
Operator: models.V1SearchFilterStringOperatorEq,
Negation: false,
IgnoreCase: false,
},
},
Property: "name",
Property: "clusterName",
Type: models.V1SearchFilterPropertyTypeString,
}
}

func (h *V1Client) SearchClusterSummariesNonVirtual(filter *models.V1SearchFilterSpec, sort []*models.V1SearchFilterSortSpec) ([]*models.V1SpectroClusterSummary, error) {
return h.SearchClusterSummaries("tenant", filter, sort) // regular clusters search is working only in tenant context.
}

func (h *V1Client) GetClusterByName(name, clusterContext string) (*models.V1SpectroCluster, error) {
filters := []*models.V1SearchFilterItem{nameFilter(name)}
clusterSummaries, err := h.SearchClusterSummaries(
clusterContext, getClusterFilter(filters), nil,
)
filters := []*models.V1SearchFilterItem{clusterNameEqFilter(name)}
clusterSummaries, err := h.SearchClusterSummariesNonVirtual(getClusterFilter(filters), nil)
if err != nil {
return nil, err
}
if len(clusterSummaries) != 1 {
return nil, fmt.Errorf("expected 1 cluster: %v in %v, got %d", name, clusterContext, len(clusterSummaries))
}

cluster, err := h.GetCluster(clusterContext, clusterSummaries[0].Metadata.UID)
cluster, err := h.GetCluster(clusterSummaries[0].Metadata.Annotations["scope"], clusterSummaries[0].Metadata.UID)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 357cb9a

Please sign in to comment.