func (c *GCECloud) deleteInstance(name string) error {
	klog.V(2).Infof("GCE Delete Instances name=%q", name)
	_, err := c.computeClient.Instances.Delete(c.config.Project, c.config.Zone, name).Do()
	if err != nil {
		return fmt.Errorf("error terminating instance %q: %v", name, err)
	}
	return nil
}
deleteInstance terminates the specified instance
package imagebuilder
import (
	"fmt"
	"time"
	"golang.org/x/crypto/ssh"
	compute "google.golang.org/api/compute/v1"
	"google.golang.org/api/googleapi"
	"k8s.io/klog"
	"sigs.k8s.io/image-builder/images/kube-deploy/imagebuilder/pkg/imagebuilder/executor"
)
type GCEInstance struct {
	cloud    *GCECloud
	name     string
	instance *compute.Instance
}
func (i *GCEInstance) Shutdown() error {
	klog.Infof("Terminating instance %q", i.name)
	return i.cloud.deleteInstance(i.name)
}
func (i *GCEInstance) DialSSH(config *ssh.ClientConfig) (executor.Executor, error) {
	publicIP, err := i.WaitPublicIP()
	if err != nil {
		return nil, err
	}
	for {
		sshClient, err := ssh.Dial("tcp", publicIP+":22", config)
		if err != nil {
			klog.Warningf("error connecting to SSH on server %q: %v", publicIP, err)
			time.Sleep(5 * time.Second)
			continue
		}
		return executor.NewSSH(sshClient), nil
	}
}
func (i *GCEInstance) WaitPublicIP() (string, error) {
	for {
		instance, err := i.cloud.describeInstance(i.name)
		if err != nil {
			return "", err
		}
		for _, ni := range instance.NetworkInterfaces {
			for _, ac := range ni.AccessConfigs {
				if ac.NatIP != "" {
					klog.Infof("Instance public IP is %q", ac.NatIP)
					return ac.NatIP, nil
				}
			}
		}
		klog.V(2).Infof("Sleeping before requerying instance for public IP: %q", i.name)
		time.Sleep(5 * time.Second)
	}
}
type GCECloud struct {
	config *GCEConfig
	computeClient *compute.Service
}
var _ Cloud = &GCECloud{}
func NewGCECloud(computeClient *compute.Service, config *GCEConfig) *GCECloud {
	return &GCECloud{
		computeClient: computeClient,
		config:        config,
	}
}
func (a *GCECloud) GetExtraEnv() (map[string]string, error) {
	env := make(map[string]string)
	return env, nil
}
func IsGCENotFound(err error) bool {
	apiErr, ok := err.(*googleapi.Error)
	if !ok {
		return false
	}
	return apiErr.Code == 404
}
func (c *GCECloud) describeInstance(name string) (*compute.Instance, error) {
	klog.V(2).Infof("GCE Instances List Name=%q", name)
	instances, err := c.computeClient.Instances.List(c.config.Project, c.config.Zone).Filter("name eq " + name).Do()
	if err != nil {
		return nil, fmt.Errorf("error making GCE Instances List call: %v", err)
	}
	if len(instances.Items) == 0 {
		return nil, nil
	}
	if len(instances.Items) != 1 {
		return nil, fmt.Errorf("found multiple instances with name %q", name)
	}
	return instances.Items[0], nil
}