Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions data/data/gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ locals {
master_subnet_cidr = cidrsubnet(var.machine_v4_cidrs[0], 3, 0) #master subnet is a smaller subnet within the vnet. i.e from /21 to /24
worker_subnet_cidr = cidrsubnet(var.machine_v4_cidrs[0], 3, 1) #worker subnet is a smaller subnet within the vnet. i.e from /21 to /24
public_endpoints = var.gcp_publish_strategy == "External" ? true : false

gcp_image = var.gcp_preexisting_image ? var.gcp_image : google_compute_image.cluster[0].self_link
}

provider "google" {
Expand All @@ -17,7 +19,7 @@ module "bootstrap" {

bootstrap_enabled = var.gcp_bootstrap_enabled

image = google_compute_image.cluster.self_link
image = local.gcp_image
machine_type = var.gcp_bootstrap_instance_type
cluster_id = var.cluster_id
ignition = var.ignition_bootstrap
Expand All @@ -36,7 +38,7 @@ module "bootstrap" {
module "master" {
source = "./master"

image = google_compute_image.cluster.self_link
image = local.gcp_image
instance_count = var.master_count
machine_type = var.gcp_master_instance_type
cluster_id = var.cluster_id
Expand Down Expand Up @@ -91,6 +93,8 @@ module "dns" {
}

resource "google_compute_image" "cluster" {
count = var.gcp_preexisting_image ? 0 : 1

name = "${var.cluster_id}-rhcos-image"

# See https://github.com/openshift/installer/issues/2546
Expand Down
13 changes: 12 additions & 1 deletion data/data/gcp/variables-gcp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,18 @@ variable "gcp_master_instance_type" {

variable "gcp_image_uri" {
type = string
description = "Image for all nodes."
description = "URL to Raw Image for all nodes. This is used in case a new image needs to be generated for the nodes."
}

variable "gcp_image" {
type = string
description = "URL to the Image for all nodes."
}

variable "gcp_preexisting_image" {
type = bool
default = true
description = "Specifies whether an existing GCP Image should be used or a new one created for installation"
}

variable "gcp_master_root_volume_type" {
Expand Down
8 changes: 7 additions & 1 deletion pkg/asset/cluster/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/openshift/installer/pkg/asset/machines"
"github.com/openshift/installer/pkg/asset/openshiftinstall"
"github.com/openshift/installer/pkg/asset/rhcos"
rhcospkg "github.com/openshift/installer/pkg/rhcos"
"github.com/openshift/installer/pkg/tfvars"
awstfvars "github.com/openshift/installer/pkg/tfvars/aws"
azuretfvars "github.com/openshift/installer/pkg/tfvars/azure"
Expand Down Expand Up @@ -327,12 +328,17 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
publicZoneName = publicZone.Name
}
preexistingnetwork := installConfig.Config.GCP.Network != ""

imageRaw, err := rhcospkg.GCPRaw(ctx, installConfig.Config.ControlPlane.Architecture)
if err != nil {
return errors.Wrap(err, "failed to find Raw GCP image URL")
}
data, err := gcptfvars.TFVars(
gcptfvars.TFVarsSources{
Auth: auth,
MasterConfigs: masterConfigs,
WorkerConfigs: workerConfigs,
ImageURI: string(*rhcosImage),
ImageURI: imageRaw,
ImageLicenses: installConfig.Config.GCP.Licenses,
PublicZoneName: publicZoneName,
PublishStrategy: installConfig.Config.Publish,
Expand Down
6 changes: 4 additions & 2 deletions pkg/asset/machines/gcp/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine

func provider(clusterID string, platform *gcp.Platform, mpool *gcp.MachinePool, osImage string, azIdx int, role, userDataSecret string) (*gcpprovider.GCPMachineProviderSpec, error) {
az := mpool.Zones[azIdx]

if len(platform.Licenses) > 0 {
osImage = fmt.Sprintf("%s-rhcos-image", clusterID)
}
network, subnetwork, err := getNetworks(platform, clusterID, role)
if err != nil {
return nil, err
Expand All @@ -87,7 +89,7 @@ func provider(clusterID string, platform *gcp.Platform, mpool *gcp.MachinePool,
Boot: true,
SizeGb: mpool.OSDisk.DiskSizeGB,
Type: mpool.OSDisk.DiskType,
Image: fmt.Sprintf("%s-rhcos-image", clusterID),
Image: osImage,
}},
NetworkInterfaces: []*gcpprovider.GCPNetworkInterface{{
Network: network,
Expand Down
5 changes: 3 additions & 2 deletions pkg/rhcos/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type metadata struct {
URL string `json:"url"`
}
GCP struct {
Image string `json:"image"`
URL string `json:"url"`
Image string `json:"image"`
Project string `json:"project"`
URL string `json:"url"`
}
BaseURI string `json:"baseURI"`
Images struct {
Expand Down
16 changes: 11 additions & 5 deletions pkg/rhcos/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@ package rhcos

import (
"context"
"fmt"

"github.com/pkg/errors"

"github.com/openshift/installer/pkg/types"
)

// GCP fetches the URL of the public GCP storage bucket containing the RHCOS image
// GCP fetches the URL of the public RHCOS image
func GCP(ctx context.Context, arch types.Architecture) (string, error) {
meta, err := fetchRHCOSBuild(ctx, arch)
if err != nil {
return "", errors.Wrap(err, "failed to fetch RHCOS metadata")
}

url := meta.GCP.URL
if url == "" {
return "", errors.New("no RHCOS GCP URL found")
return fmt.Sprintf("projects/%s/global/images/%s", meta.GCP.Project, meta.GCP.Image), nil
}

// GCPRaw fetches the URL of the public GCP storage bucket containing the RHCOS image
func GCPRaw(ctx context.Context, arch types.Architecture) (string, error) {
meta, err := fetchRHCOSBuild(ctx, arch)
if err != nil {
return "", errors.Wrap(err, "failed to fetch RHCOS metadata")
}

return url, nil
return meta.GCP.URL, nil
}
10 changes: 9 additions & 1 deletion pkg/tfvars/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type config struct {
MasterInstanceType string `json:"gcp_master_instance_type,omitempty"`
MasterAvailabilityZones []string `json:"gcp_master_availability_zones"`
ImageURI string `json:"gcp_image_uri,omitempty"`
Image string `json:"gcp_image,omitempty"`
PreexistingImage bool `json:"gcp_preexisting_image"`
ImageLicenses []string `json:"gcp_image_licenses,omitempty"`
VolumeType string `json:"gcp_master_root_volume_type"`
VolumeSize int64 `json:"gcp_master_root_volume_size"`
Expand All @@ -36,7 +38,7 @@ type config struct {
type TFVarsSources struct {
Auth Auth
ImageURI string
ImageLicenses []string `json:"gcp_image_licenses,omitempty"`
ImageLicenses []string
MasterConfigs []*gcpprovider.GCPMachineProviderSpec
WorkerConfigs []*gcpprovider.GCPMachineProviderSpec
PublicZoneName string
Expand All @@ -52,6 +54,7 @@ func TFVars(sources TFVarsSources) ([]byte, error) {
for i, c := range sources.MasterConfigs {
masterAvailabilityZones[i] = c.Zone
}

cfg := &config{
Auth: sources.Auth,
Region: masterConfig.Region,
Expand All @@ -61,6 +64,7 @@ func TFVars(sources TFVarsSources) ([]byte, error) {
VolumeType: masterConfig.Disks[0].Type,
VolumeSize: masterConfig.Disks[0].SizeGb,
ImageURI: sources.ImageURI,
Image: masterConfig.Disks[0].Image,
ImageLicenses: sources.ImageLicenses,
PublicZoneName: sources.PublicZoneName,
PublishStrategy: string(sources.PublishStrategy),
Expand All @@ -69,6 +73,10 @@ func TFVars(sources TFVarsSources) ([]byte, error) {
ComputeSubnet: workerConfig.NetworkInterfaces[0].Subnetwork,
PreexistingNetwork: sources.PreexistingNetwork,
}
cfg.PreexistingImage = true
if len(sources.ImageLicenses) > 0 {
cfg.PreexistingImage = false
}

return json.MarshalIndent(cfg, "", " ")
}