-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding call to pyxis for non EOL catalogs and updating imagestream logic
Signed-off-by: Adam D. Cornett <[email protected]>
- Loading branch information
1 parent
81fab96
commit d124aba
Showing
6 changed files
with
150 additions
and
26 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,72 @@ | ||
package pyxis | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/shurcooL/graphql" | ||
) | ||
|
||
const ( | ||
DefaultPyxisHost = "catalog.redhat.com/api/containers" | ||
) | ||
|
||
type PyxisClient struct { | ||
Client *http.Client | ||
PyxisHost string | ||
} | ||
|
||
func (p *PyxisClient) getPyxisGraphqlURL() string { | ||
return fmt.Sprintf("https://%s/graphql/", p.PyxisHost) | ||
} | ||
|
||
func NewPyxisClient(pyxisHost string, httpClient *http.Client) *PyxisClient { | ||
return &PyxisClient{ | ||
Client: httpClient, | ||
PyxisHost: pyxisHost, | ||
} | ||
} | ||
|
||
func (p *PyxisClient) FindOperatorIndices(ctx context.Context, organization string) ([]OperatorIndex, error) { | ||
// our graphQL query | ||
var query struct { | ||
FindOperatorIndices struct { | ||
OperatorIndex []struct { | ||
OCPVersion graphql.String `graphql:"ocp_version"` | ||
Organization graphql.String `graphql:"organization"` | ||
EndOfLife graphql.String `graphql:"end_of_life"` | ||
} `graphql:"data"` | ||
Errors struct { | ||
Status graphql.Int `graphql:"status"` | ||
Detail graphql.String `graphql:"detail"` | ||
} `graphql:"error"` | ||
Total graphql.Int | ||
Page graphql.Int | ||
// filter to make sure we get exact results, end_of_life is a string, querying for `null` yields active OCP versions. | ||
} `graphql:"find_operator_indices(filter:{and:[{organization:{eq:$organization}},{end_of_life:{eq:null}}]})"` | ||
} | ||
|
||
// variables to feed to our graphql filter | ||
variables := map[string]interface{}{ | ||
"organization": graphql.String(organization), | ||
} | ||
|
||
// make our query | ||
client := graphql.NewClient(p.getPyxisGraphqlURL(), p.Client) | ||
|
||
err := client.Query(ctx, &query, variables) | ||
if err != nil { | ||
return nil, fmt.Errorf("error while executing remote query for %s catalogs: %v", organization, err) | ||
} | ||
|
||
operatorIndices := make([]OperatorIndex, len(query.FindOperatorIndices.OperatorIndex)) | ||
for idx, operator := range query.FindOperatorIndices.OperatorIndex { | ||
operatorIndices[idx] = OperatorIndex{ | ||
OCPVersion: string(operator.OCPVersion), | ||
Organization: string(operator.Organization), | ||
} | ||
} | ||
|
||
return operatorIndices, nil | ||
} |
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,7 @@ | ||
package pyxis | ||
|
||
type OperatorIndex struct { | ||
OCPVersion string `json:"ocp_version"` | ||
Organization string `json:"organization"` | ||
EndOfLife string `json:"end_of_life,omitempty"` | ||
} |
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