-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from virtual-kubelet/aci-gpu-client
ACI GPU Support Changes in Client
- Loading branch information
Showing
8 changed files
with
242 additions
and
43 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
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,76 @@ | ||
package aci | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/virtual-kubelet/azure-aci/client/api" | ||
) | ||
|
||
const ( | ||
resourceProviderURLPath = "providers/Microsoft.ContainerInstance" | ||
resourceProviderAPIVersion = "2018-02-01" | ||
) | ||
|
||
// GetResourceProviderMetadata gets the ACI resource provider metadata | ||
func (c *Client) GetResourceProviderMetadata(ctx context.Context) (*ResourceProviderMetadata, error) { | ||
manifest, err := c.getResourceProviderManifest(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if manifest == nil { | ||
return nil, fmt.Errorf("The resource provider manifest is empty") | ||
} | ||
|
||
if manifest.Metadata == nil { | ||
return nil, fmt.Errorf("The resource provider metadata is empty") | ||
} | ||
|
||
return manifest.Metadata, nil | ||
} | ||
|
||
func (c *Client) getResourceProviderManifest(ctx context.Context) (*ResourceProviderManifest, error) { | ||
urlParams := url.Values{ | ||
"api-version": []string{resourceProviderAPIVersion}, | ||
"$expand": []string{"metadata"}, | ||
} | ||
|
||
// Create the url. | ||
uri := api.ResolveRelative(c.auth.ResourceManagerEndpoint, resourceProviderURLPath) | ||
uri += "?" + url.Values(urlParams).Encode() | ||
|
||
// Create the request. | ||
req, err := http.NewRequest("GET", uri, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("Creating get resource provider manifest request failed: %v", err) | ||
} | ||
req = req.WithContext(ctx) | ||
|
||
// Send the request. | ||
resp, err := c.hc.Do(req) | ||
if err != nil { | ||
return nil, fmt.Errorf("Sending get resource provider manifest request failed: %v", err) | ||
} | ||
defer resp.Body.Close() | ||
|
||
// 200 (OK) is a success response. | ||
if err := api.CheckResponse(resp); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Decode the body from the response. | ||
if resp.Body == nil { | ||
return nil, errors.New("Get resource provider manifest returned an empty body in the response") | ||
} | ||
var manifest ResourceProviderManifest | ||
if err := json.NewDecoder(resp.Body).Decode(&manifest); err != nil { | ||
return nil, fmt.Errorf("Decoding get resource provider manifest response body failed: %v", err) | ||
} | ||
|
||
return &manifest, nil | ||
} |
Oops, something went wrong.