(ctx context.Context, apiClient client.APIClient, options psOptions)
| 81 | } |
| 82 | |
| 83 | func createFilter(ctx context.Context, apiClient client.APIClient, options psOptions) (client.Filters, []string, error) { |
| 84 | filter := options.filter.Value() |
| 85 | |
| 86 | serviceIDFilter := make(client.Filters) |
| 87 | serviceNameFilter := make(client.Filters) |
| 88 | for _, service := range options.services { |
| 89 | serviceIDFilter.Add("id", service) |
| 90 | serviceNameFilter.Add("name", service) |
| 91 | } |
| 92 | serviceByID, err := apiClient.ServiceList(ctx, client.ServiceListOptions{Filters: serviceIDFilter}) |
| 93 | if err != nil { |
| 94 | return filter, nil, err |
| 95 | } |
| 96 | serviceByName, err := apiClient.ServiceList(ctx, client.ServiceListOptions{Filters: serviceNameFilter}) |
| 97 | if err != nil { |
| 98 | return filter, nil, err |
| 99 | } |
| 100 | |
| 101 | var notfound []string |
| 102 | serviceCount := 0 |
| 103 | loop: |
| 104 | // Match services by 1. Full ID, 2. Full name, 3. ID prefix. An error is returned if the ID-prefix match is ambiguous |
| 105 | for _, service := range options.services { |
| 106 | for _, s := range serviceByID.Items { |
| 107 | if s.ID == service { |
| 108 | filter.Add("service", s.ID) |
| 109 | serviceCount++ |
| 110 | continue loop |
| 111 | } |
| 112 | } |
| 113 | for _, s := range serviceByName.Items { |
| 114 | if s.Spec.Annotations.Name == service { |
| 115 | filter.Add("service", s.ID) |
| 116 | serviceCount++ |
| 117 | continue loop |
| 118 | } |
| 119 | } |
| 120 | found := false |
| 121 | for _, s := range serviceByID.Items { |
| 122 | if strings.HasPrefix(s.ID, service) { |
| 123 | if found { |
| 124 | return filter, nil, errors.New("multiple services found with provided prefix: " + service) |
| 125 | } |
| 126 | filter.Add("service", s.ID) |
| 127 | serviceCount++ |
| 128 | found = true |
| 129 | } |
| 130 | } |
| 131 | if !found { |
| 132 | notfound = append(notfound, "no such service: "+service) |
| 133 | } |
| 134 | } |
| 135 | if serviceCount == 0 { |
| 136 | return filter, nil, errors.New(strings.Join(notfound, "\n")) |
| 137 | } |
| 138 | return filter, notfound, err |
| 139 | } |
| 140 |
searching dependent graphs…