Skip to content

Commit

Permalink
feat: [CDE-585]: Skip CDE VMs from cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vikyathharekal committed Feb 3, 2025
1 parent 9bfcc4d commit 8a23a5d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/drivers/google/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package google

import (
"context"
"encoding/json"
"errors"
"fmt"
"math/rand"
Expand Down Expand Up @@ -337,7 +338,11 @@ func (p *config) create(ctx context.Context, opts *types.InstanceCreateOpts, nam
return nil, err
}

instanceMap := p.mapToInstance(vm, zone, opts, enableNestedVirtualization)
instanceMap, err := p.mapToInstance(vm, zone, opts, enableNestedVirtualization)
if err != nil {
logr.WithError(err).Errorln("google: failed to map VM to instance")
return nil, err
}
logr.
WithField("ip", instanceMap.Address).
WithField("time", fmt.Sprintf("%.2fs", time.Since(startTime).Seconds())).
Expand Down Expand Up @@ -631,7 +636,7 @@ func (p *config) deletePersistentDisk(ctx context.Context, projectID, zone, disk
})
}

func (p *config) mapToInstance(vm *compute.Instance, zone string, opts *types.InstanceCreateOpts, enableNestedVitualization bool) types.Instance {
func (p *config) mapToInstance(vm *compute.Instance, zone string, opts *types.InstanceCreateOpts, enableNestedVitualization bool) (types.Instance, error) {
network := vm.NetworkInterfaces[0]
instanceIP := ""
if p.privateIP {
Expand All @@ -640,6 +645,11 @@ func (p *config) mapToInstance(vm *compute.Instance, zone string, opts *types.In
instanceIP = network.AccessConfigs[0].NatIP
}

labelsBytes, marshalErr := json.Marshal(opts.Labels)
if marshalErr != nil {
return types.Instance{}, fmt.Errorf("scheduler: could not marshal labels: %v, err: %w", opts.Labels, marshalErr)
}

started, _ := time.Parse(time.RFC3339, vm.CreationTimestamp)
return types.Instance{
ID: strconv.FormatUint(vm.Id, 10),
Expand All @@ -662,7 +672,8 @@ func (p *config) mapToInstance(vm *compute.Instance, zone string, opts *types.In
Port: lehelper.LiteEnginePort,
EnableNestedVirtualization: enableNestedVitualization,
StorageIdentifier: opts.StorageOpts.Identifier,
}
Labels: labelsBytes,
}, nil
}

func (p *config) findInstanceZone(ctx context.Context, instanceID string) (
Expand Down

0 comments on commit 8a23a5d

Please sign in to comment.