test/api.sh: randomize used GCP zone from the region
The `api.sh` test currently always defaults to "<REGION>-a" zone when creating instance using the built image. The resources in a zone may get exhausted and the solution is to use a different zone. Currently even a CI job retry won't help with mitigation of such error during a CI run. Modify `api.sh` to pick random GCP zone for a given region when creating a compute instance. Use only GCP zones which are "UP". The `cloud-cleaner` relied on the behavior of `api.sh` to always choose the "<REGION>-a" zone. Guessing the chosen zone in `cloud-cleaner` is not viable, but thankfully the instance name is by default unique for the whole GCP project. Modify `cloud-cleaner` to iterate over all available zones in the used region and try to delete the specific instance in each of them. Make `ComputeZonesInRegion` method from the `internal/cloud/gcp` package exported and use it in `cloud-cleaner` for getting the list of available zones in a region. Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
1fd151ce28
commit
3a0540dff0
3 changed files with 37 additions and 16 deletions
|
|
@ -87,7 +87,7 @@ func (g *GCP) ComputeImageImport(ctx context.Context, bucket, object, imageName,
|
|||
// regions than what can potentially fit into int32.
|
||||
gceRegion := gceRegions[int(gceRegionIndex.Int64())]
|
||||
|
||||
availableZones, err := g.computeZonesInRegion(ctx, gceRegion)
|
||||
availableZones, err := g.ComputeZonesInRegion(ctx, gceRegion)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get available GCE Zones within Region '%s': %v", region, err)
|
||||
}
|
||||
|
|
@ -396,11 +396,11 @@ func (g *GCP) storageRegionToComputeRegions(ctx context.Context, region string)
|
|||
}
|
||||
}
|
||||
|
||||
// computeZonesInRegion returns list of zones within the given GCE Region, which are "UP".
|
||||
// ComputeZonesInRegion returns list of zones within the given GCE Region, which are "UP".
|
||||
//
|
||||
// Uses:
|
||||
// - Compute Engine API
|
||||
func (g *GCP) computeZonesInRegion(ctx context.Context, region string) ([]string, error) {
|
||||
func (g *GCP) ComputeZonesInRegion(ctx context.Context, region string) ([]string, error) {
|
||||
var zones []string
|
||||
|
||||
computeService, err := compute.NewService(ctx, option.WithCredentials(g.creds))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue