remove cloud cleaner
scheduled cloud cleaner now uses a new method to remove azure resources. So cloud cleaner code is not used
This commit is contained in:
parent
6d15c03d2f
commit
f6fa5ccca1
5 changed files with 0 additions and 392 deletions
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
compute "cloud.google.com/go/compute/apiv1"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"google.golang.org/api/iterator"
|
||||
"google.golang.org/api/option"
|
||||
computepb "google.golang.org/genproto/googleapis/cloud/compute/v1"
|
||||
)
|
||||
|
|
@ -267,141 +266,3 @@ func (g *GCP) ComputeExecuteFunctionForImages(ctx context.Context, f func(*compu
|
|||
imagesIterator := imagesClient.List(ctx, req)
|
||||
return f(imagesIterator)
|
||||
}
|
||||
|
||||
// ComputeInstanceDelete deletes a Compute Engine instance with the given name and
|
||||
// running in the given zone. If the instance existed and was successfully deleted,
|
||||
// no error is returned.
|
||||
//
|
||||
// Uses:
|
||||
// - Compute Engine API
|
||||
func (g *GCP) ComputeInstanceDelete(ctx context.Context, zone, instance string) error {
|
||||
instancesClient, err := compute.NewInstancesRESTClient(ctx, option.WithCredentials(g.creds))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Compute Engine Instances client: %v", err)
|
||||
}
|
||||
defer instancesClient.Close()
|
||||
|
||||
req := &computepb.DeleteInstanceRequest{
|
||||
Project: g.GetProjectID(),
|
||||
Zone: zone,
|
||||
Instance: instance,
|
||||
}
|
||||
_, err = instancesClient.Delete(ctx, req)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// ComputeInstanceGet fetches a Compute Engine instance information. If fetching the information
|
||||
// was successful, it is returned to the caller, otherwise <nil> is returned with a proper error.
|
||||
//
|
||||
// Uses:
|
||||
// - Compute Engine API
|
||||
func (g *GCP) ComputeInstanceGet(ctx context.Context, zone, instance string) (*computepb.Instance, error) {
|
||||
instancesClient, err := compute.NewInstancesRESTClient(ctx, option.WithCredentials(g.creds))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get Compute Engine Instances client: %v", err)
|
||||
}
|
||||
defer instancesClient.Close()
|
||||
|
||||
req := &computepb.GetInstanceRequest{
|
||||
Project: g.GetProjectID(),
|
||||
Instance: instance,
|
||||
Zone: zone,
|
||||
}
|
||||
resp, err := instancesClient.Get(ctx, req)
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// ComputeDiskDelete deletes a Compute Engine disk with the given name and
|
||||
// running in the given zone. If the disk existed and was successfully deleted,
|
||||
// no error is returned.
|
||||
//
|
||||
// Uses:
|
||||
// - Compute Engine API
|
||||
func (g *GCP) ComputeDiskDelete(ctx context.Context, zone, disk string) error {
|
||||
disksClient, err := compute.NewDisksRESTClient(ctx, option.WithCredentials(g.creds))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Compute Engine Disks client: %v", err)
|
||||
}
|
||||
defer disksClient.Close()
|
||||
|
||||
req := &computepb.DeleteDiskRequest{
|
||||
Project: g.GetProjectID(),
|
||||
Disk: disk,
|
||||
Zone: zone,
|
||||
}
|
||||
_, err = disksClient.Delete(ctx, req)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// ComputeUpZonesInRegion returns list of zones within the given GCE Region, which are "UP".
|
||||
//
|
||||
// Uses:
|
||||
// - Compute Engine API
|
||||
func (g *GCP) ComputeUpZonesInRegion(ctx context.Context, region *computepb.Region) ([]*computepb.Zone, error) {
|
||||
var zones []*computepb.Zone
|
||||
|
||||
zonesClient, err := compute.NewZonesRESTClient(ctx, option.WithCredentials(g.creds))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get Compute Engine Zones client: %v", err)
|
||||
}
|
||||
defer zonesClient.Close()
|
||||
|
||||
for _, zoneURL := range region.Zones {
|
||||
// zone URL example - "https://www.googleapis.com/compute/v1/projects/<PROJECT_ID>/zones/us-central1-a"
|
||||
zoneNameSs := strings.Split(zoneURL, "/")
|
||||
zoneName := zoneNameSs[len(zoneNameSs)-1]
|
||||
|
||||
getZoneReq := &computepb.GetZoneRequest{
|
||||
Project: g.GetProjectID(),
|
||||
Zone: zoneName,
|
||||
}
|
||||
zone, err := zonesClient.Get(ctx, getZoneReq)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get information about Compute Engine zone '%s': %v", zoneName, err)
|
||||
}
|
||||
|
||||
// Make sure to return only Zones, which can be used
|
||||
if zone.GetStatus() == computepb.Zone_UP.String() {
|
||||
zones = append(zones, zone)
|
||||
}
|
||||
}
|
||||
|
||||
return zones, nil
|
||||
}
|
||||
|
||||
// ComputeRegionsList returns list of GCE regions based on the provided filter.
|
||||
//
|
||||
// Uses:
|
||||
// - Compute Engine API
|
||||
func (g *GCP) ComputeRegionsList(ctx context.Context, filter string) ([]*computepb.Region, error) {
|
||||
var regions []*computepb.Region
|
||||
|
||||
regionsClient, err := compute.NewRegionsRESTClient(ctx, option.WithCredentials(g.creds))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get GCE regions client: %v", err)
|
||||
}
|
||||
defer regionsClient.Close()
|
||||
|
||||
listRegionsReq := &computepb.ListRegionsRequest{
|
||||
Project: g.GetProjectID(),
|
||||
Filter: common.StringToPtr(filter),
|
||||
}
|
||||
regionsIter := regionsClient.List(ctx, listRegionsReq)
|
||||
|
||||
for {
|
||||
resp, err := regionsIter.Next()
|
||||
if err == iterator.Done {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while iterating over GCE regions: %v", err)
|
||||
}
|
||||
|
||||
regions = append(regions, resp)
|
||||
}
|
||||
|
||||
return regions, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
cloudbuild "cloud.google.com/go/cloudbuild/apiv1"
|
||||
compute "cloud.google.com/go/compute/apiv1"
|
||||
|
|
@ -65,29 +64,6 @@ func NewFromFile(path string) (*GCP, error) {
|
|||
return New(gcpCredentials)
|
||||
}
|
||||
|
||||
// GetCredentialsFromEnv reads the service account credentials JSON file from
|
||||
// the path pointed to by the environment variable name stored in
|
||||
// 'GCPCredentialsEnvName'. If the content of the JSON file was read successfully,
|
||||
// its content is returned as []byte, otherwise nil is returned with proper error.
|
||||
func GetCredentialsFromEnv() ([]byte, error) {
|
||||
credsPath, exists := os.LookupEnv(GCPCredentialsEnvName)
|
||||
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("'%s' env variable is not set", GCPCredentialsEnvName)
|
||||
}
|
||||
if credsPath == "" {
|
||||
return nil, fmt.Errorf("'%s' env variable is empty", GCPCredentialsEnvName)
|
||||
}
|
||||
|
||||
var err error
|
||||
credentials, err := ioutil.ReadFile(credsPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error while reading credentials file: %s", err)
|
||||
}
|
||||
|
||||
return credentials, nil
|
||||
}
|
||||
|
||||
// GetProjectID returns a string with the Project ID of the project, used for
|
||||
// all GCP operations.
|
||||
func (g *GCP) GetProjectID() string {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"os"
|
||||
|
||||
"cloud.google.com/go/storage"
|
||||
"google.golang.org/api/iterator"
|
||||
"google.golang.org/api/option"
|
||||
)
|
||||
|
||||
|
|
@ -98,53 +97,3 @@ func (g *GCP) StorageObjectDelete(ctx context.Context, bucket, object string) er
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// StorageListObjectsByMetadata searches specified Storage bucket for objects matching the provided
|
||||
// metadata. The provided metadata is used for filtering the bucket's content. Therefore if the provided
|
||||
// metadata is nil, then all objects present in the bucket will be returned.
|
||||
//
|
||||
// Matched objects are returned as a list of ObjectAttrs.
|
||||
//
|
||||
// Uses:
|
||||
// - Storage API
|
||||
func (g *GCP) StorageListObjectsByMetadata(ctx context.Context, bucket string, metadata map[string]string) ([]*storage.ObjectAttrs, error) {
|
||||
var matchedObjectAttr []*storage.ObjectAttrs
|
||||
|
||||
storageClient, err := storage.NewClient(ctx, option.WithCredentials(g.creds))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get Storage client: %v", err)
|
||||
}
|
||||
defer storageClient.Close()
|
||||
|
||||
objects := storageClient.Bucket(bucket).Objects(ctx, nil)
|
||||
for {
|
||||
obj, err := objects.Next()
|
||||
if err == iterator.Done {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failure while iterating over bucket objects: %v", err)
|
||||
}
|
||||
|
||||
// check if the object's Metadata match the provided values
|
||||
metadataMatch := true
|
||||
for key, value := range metadata {
|
||||
objMetadataValue, ok := obj.Metadata[key]
|
||||
if !ok {
|
||||
metadataMatch = false
|
||||
break
|
||||
}
|
||||
if objMetadataValue != value {
|
||||
metadataMatch = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if metadataMatch {
|
||||
matchedObjectAttr = append(matchedObjectAttr, obj)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return matchedObjectAttr, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue