Skip to content

Commit

Permalink
gcp: handle image in two formats
Browse files Browse the repository at this point in the history
This allow users to use public images shared outside the project scope.

Signed-off-by: Beraldo Leal <bleal@redhat.com>
  • Loading branch information
beraldoleal committed Feb 4, 2025
1 parent b83d28f commit 69edb5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/cloud-providers/gcp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,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/<project>/global/images/<image>"
srcImage := proto.String(fmt.Sprintf("projects/%s/global/images/%s", p.serviceConfig.GcpProjectId, p.serviceConfig.ImageId))
// It's expected that the image from the annotation will follow the format
// "projects/<project>/global/images/<imageid>" or just the "<imageid>" if the
// image is present on the same project.
var srcImage *string
if strings.HasPrefix(p.serviceConfig.ImageId, "projects/") {
srcImage = proto.String(p.serviceConfig.ImageId)
} else {
srcImage = proto.String(fmt.Sprintf("projects/%s/global/images/%s", p.serviceConfig.GcpProjectId, p.serviceConfig.ImageId))
}

if spec.Image != "" {
logger.Printf("Choosing %s from annotation as the GCP image for the PodVM image", spec.Image)
Expand Down
2 changes: 1 addition & 1 deletion src/cloud-providers/gcp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Config struct {
GcpNetworkId string
// CAA configuration
ImageId string
InstanceType string
MachineType string
DisableCVM bool
DiskType string
}
Expand Down

0 comments on commit 69edb5c

Please sign in to comment.