diff --git a/src/cloud-providers/gcp/provider.go b/src/cloud-providers/gcp/provider.go index f12054208..03c691097 100644 --- a/src/cloud-providers/gcp/provider.go +++ b/src/cloud-providers/gcp/provider.go @@ -9,6 +9,7 @@ import ( "fmt" "log" "net/netip" + "strings" compute "cloud.google.com/go/compute/apiv1" computepb "cloud.google.com/go/compute/apiv1/computepb" @@ -89,8 +90,15 @@ func (p *gcpProvider) CreateInstance(ctx context.Context, podName, sandboxID str userDataEnc := base64.StdEncoding.EncodeToString([]byte(userData)) logger.Printf("userDataEnc: %s", userDataEnc) - // It's expected that the image from the annotation will follow the format "projects//global/images/" - srcImage := proto.String(fmt.Sprintf("projects/%s/global/images/%s", p.serviceConfig.ProjectId, p.serviceConfig.ImageName)) + // It's expected that the image from the annotation will follow the format + // "projects//global/images/" or just the "" if the + // image is present on the same project. + var srcImage *string + if strings.HasPrefix(p.serviceConfig.ImageName, "projects/") { + srcImage = proto.String(p.serviceConfig.ImageName) + } else { + srcImage = proto.String(fmt.Sprintf("projects/%s/global/images/%s", p.serviceConfig.ProjectId, p.serviceConfig.ImageName)) + } if spec.Image != "" { logger.Printf("Choosing %s from annotation as the GCP image for the PodVM image", spec.Image)