|
9 | 9 | "github.com/openshift/console/pkg/auth"
|
10 | 10 | "github.com/openshift/console/pkg/serverutils"
|
11 | 11 | "github.com/operator-framework/kubectl-operator/pkg/action"
|
| 12 | + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" |
12 | 13 | "k8s.io/client-go/rest"
|
13 | 14 | "k8s.io/klog/v2"
|
14 | 15 |
|
@@ -71,6 +72,8 @@ func (o *OLMHandler) OperandsList(user *auth.User, w http.ResponseWriter, r *htt
|
71 | 72 | return
|
72 | 73 | }
|
73 | 74 |
|
| 75 | + operandsList = deduplicateOperands(operandsList) |
| 76 | + |
74 | 77 | w.Header().Set("Content-Type", "application/json")
|
75 | 78 | resp, err := json.Marshal(operandsList)
|
76 | 79 | if err != nil {
|
@@ -150,3 +153,31 @@ func (o *OLMHandler) getClientWithScheme(user *auth.User) (client.Client, *runti
|
150 | 153 | }
|
151 | 154 | return client, scheme, nil
|
152 | 155 | }
|
| 156 | + |
| 157 | +func deduplicateOperands(operandsList *unstructured.UnstructuredList) *unstructured.UnstructuredList { |
| 158 | + if operandsList == nil || len(operandsList.Items) == 0 { |
| 159 | + return operandsList |
| 160 | + } |
| 161 | + |
| 162 | + seen := make(map[string]bool) |
| 163 | + uniqueOperands := make([]unstructured.Unstructured, 0, len(operandsList.Items)) |
| 164 | + |
| 165 | + for _, operand := range operandsList.Items { |
| 166 | + key := fmt.Sprintf("%s-%s-%s", |
| 167 | + operand.GetKind(), |
| 168 | + operand.GetName(), |
| 169 | + operand.GetNamespace()) |
| 170 | + |
| 171 | + if !seen[key] { |
| 172 | + seen[key] = true |
| 173 | + uniqueOperands = append(uniqueOperands, operand) |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + result := &unstructured.UnstructuredList{ |
| 178 | + Items: uniqueOperands, |
| 179 | + } |
| 180 | + result.SetGroupVersionKind(operandsList.GroupVersionKind()) |
| 181 | + |
| 182 | + return result |
| 183 | +} |
0 commit comments