-
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 af0e332
Showing
6 changed files
with
163 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,85 @@ | ||
package pyxis | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/shurcooL/graphql" | ||
) | ||
|
||
const ( | ||
apiVersion = "v1" | ||
DefaultPyxisHost = "catalog.redhat.com/api/containers" | ||
) | ||
|
||
type HTTPClient interface { | ||
Do(req *http.Request) (*http.Response, error) | ||
} | ||
|
||
type PyxisClient struct { | ||
Client HTTPClient | ||
PyxisHost string | ||
} | ||
|
||
func (p *PyxisClient) getPyxisURL(path string) string { | ||
return fmt.Sprintf("https://%s/%s/%s", p.PyxisHost, apiVersion, path) | ||
} | ||
|
||
func (p *PyxisClient) getPyxisGraphqlURL() string { | ||
return fmt.Sprintf("https://%s/graphql/", p.PyxisHost) | ||
} | ||
|
||
func NewPyxisClient(pyxisHost string, httpClient HTTPClient) *PyxisClient { | ||
return &PyxisClient{ | ||
Client: httpClient, | ||
PyxisHost: pyxisHost, | ||
} | ||
} | ||
|
||
func (p *PyxisClient) FindOperatorIndices(ctx context.Context, organization string) ([]OperatorIndency, error) { | ||
// our graphQL query | ||
var query struct { | ||
FindOperatorIndices struct { | ||
OperatorIndency []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 | ||
httpClient, ok := p.Client.(*http.Client) | ||
if !ok { | ||
return nil, fmt.Errorf("client could not be used as http.Client") | ||
} | ||
client := graphql.NewClient(p.getPyxisGraphqlURL(), httpClient) | ||
|
||
err := client.Query(ctx, &query, variables) | ||
if err != nil { | ||
return nil, fmt.Errorf("error while executing find_operator_indices query: %v", err) | ||
} | ||
|
||
operatorIndices := make([]OperatorIndency, len(query.FindOperatorIndices.OperatorIndency)) | ||
for idx, operator := range query.FindOperatorIndices.OperatorIndency { | ||
operatorIndices[idx] = OperatorIndency{ | ||
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 OperatorIndency 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