-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 #4163 from abhinavdahiya/bz-invalid-parse-machine-…
…type Bug 1878108: asset/quota/gcp: use GCP api to find CPU count for constraint and guess only on failure
- Loading branch information
Showing
4 changed files
with
224 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package gcp | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
computev1 "google.golang.org/api/compute/v1" | ||
"google.golang.org/api/option" | ||
|
||
gcpconfig "github.com/openshift/installer/pkg/asset/installconfig/gcp" | ||
) | ||
|
||
// MachineTypeGetter returns the machine type info for a type in a zone using GCP API. | ||
type MachineTypeGetter interface { | ||
GetMachineType(zone string, machineType string) (*computev1.MachineType, error) | ||
} | ||
|
||
// Client is GCP client for calculating quota constraint. | ||
type Client struct { | ||
computeSvc *computev1.Service | ||
|
||
projectID string | ||
} | ||
|
||
// NewClient returns Client using the context and session. | ||
func NewClient(ctx context.Context, sess *gcpconfig.Session, projectID string) (*Client, error) { | ||
svc, err := computev1.NewService(ctx, option.WithCredentials(sess.Credentials)) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to create compute service") | ||
} | ||
return &Client{computeSvc: svc, projectID: projectID}, nil | ||
} | ||
|
||
// GetMachineType returns the machine type info for a type in a zone using the client. | ||
func (c *Client) GetMachineType(zone string, machineType string) (*computev1.MachineType, error) { | ||
return c.computeSvc.MachineTypes.Get(c.projectID, zone, machineType).Context(context.TODO()).Do() | ||
} |
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
Oops, something went wrong.