Last active
August 25, 2020 12:29
-
-
Save jewzaam/0b7e2ce5eed35990d2d570b3d5a6a86d to your computer and use it in GitHub Desktop.
info from grpc catalogsource
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
# Useful link for how to discover API's: https://github.com/operator-framework/operator-registry/issues/33#issuecomment-473671805 | |
# get tools | |
go get github.com/fullstorydev/grpcurl/... | |
go install github.com/fullstorydev/grpcurl/cmd/grpcurl | |
# constants for what we're investigating | |
NAMESPACE=openshift-marketplace | |
LOCAL_PORT=50051 | |
REMOTE_PORT=50051 | |
GRPCURL=$(which grpcurl) | |
for CATALOG_SOURCE_NAME in redhat-operators certified-operators community-operators; | |
do | |
# 1. start a port-forward | |
POD_NAME=$(oc -n $NAMESPACE get pods -l marketplace.operatorSource=$CATALOG_SOURCE_NAME -o jsonpath='{.items[].metadata.name}' 2>/dev/null | grep $CATALOG_SOURCE_NAME || \ | |
oc -n $NAMESPACE get pods -l olm.catalogSource=$CATALOG_SOURCE_NAME -o jsonpath='{.items[].metadata.name}' 2>/dev/null) | |
oc -n $NAMESPACE port-forward pod/$POD_NAME $LOCAL_PORT:$REMOTE_PORT 2>/dev/null >/dev/null & | |
sleep 5 | |
# 2. extract CSV | |
for PACKAGE in $($GRPCURL -plaintext localhost:$LOCAL_PORT api.Registry/ListPackages | jq -r .name); | |
do | |
for CHANNEL in $($GRPCURL -plaintext -d "{\"name\":\"$PACKAGE\"}" localhost:$LOCAL_PORT api.Registry/GetPackage | jq -r .defaultChannelName); | |
do | |
echo "Writing ${CATALOG_SOURCE_NAME}_${PACKAGE}.json" | |
$GRPCURL -plaintext -d "{\"pkgName\":\"$PACKAGE\",\"channelName\":\"$CHANNEL\"}" localhost:$LOCAL_PORT api.Registry/GetBundleForChannel | jq -r .csvJson | python -mjson.tool > ${CATALOG_SOURCE_NAME}_${PACKAGE}.json | |
done | |
done | |
# 3. kill port-forward | |
kill -9 $(ps aux | grep "port-forward" | awk '{print $2}') 2>/dev/null | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment