-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IndexFunc using ProvidedAPIs as key to look up CSVs
Signed-off-by: Vu Dinh <[email protected]>
- Loading branch information
1 parent
07dd944
commit b8951c6
Showing
3 changed files
with
97 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package indexer | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1" | ||
"k8s.io/client-go/tools/cache" | ||
) | ||
|
||
const ( | ||
// ProvidedAPIsIndexFuncKey is the recommended key to use for registering the index func with an indexer. | ||
ProvidedAPIsIndexFuncKey string = "providedAPIs" | ||
) | ||
|
||
func ProvidedAPIsIndexFunc(obj interface{}) ([]string, error) { | ||
indicies := []string{} | ||
|
||
csv, ok := obj.(*v1alpha1.ClusterServiceVersion) | ||
if !ok { | ||
return indicies, fmt.Errorf("invalid object of type: %T", obj) | ||
} | ||
|
||
for _, crd := range csv.Spec.CustomResourceDefinitions.Owned { | ||
parts := strings.SplitN(crd.Name, ".", 2) | ||
if len(parts) < 2 { | ||
return indicies, fmt.Errorf("couldn't parse plural.group from crd name: %s", crd.Name) | ||
} | ||
indicies = append(indicies, fmt.Sprintf("provided=%s/%s/%s", parts[1], crd.Version, crd.Kind)) | ||
} | ||
for _, api := range csv.Spec.APIServiceDefinitions.Owned { | ||
indicies = append(indicies, fmt.Sprintf("provided=%s/%s/%s", api.Group, api.Version, api.Kind)) | ||
} | ||
|
||
return indicies, nil | ||
} | ||
|
||
// APIsIndexValues returns the names of CSVs that own the given CRD | ||
func APIsIndexValues(indexers map[string]cache.Indexer, apiKey string) (map[string]struct{}, error) { | ||
csvSet := map[string]struct{}{} | ||
for _, indexer := range indexers { | ||
|
||
csvs, err := indexer.ByIndex(ProvidedAPIsIndexFuncKey, apiKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, csv := range csvs { | ||
csv, ok := csv.(*v1alpha1.ClusterServiceVersion) | ||
if !ok { | ||
continue | ||
} | ||
// Add to set | ||
csvSet[csv.GetName()] = struct{}{} | ||
} | ||
|
||
} | ||
return csvSet, nil | ||
} |