Skip to content

Commit 8909227

Browse files
committed
CORS-2933: IBMCloud: Service endpoint override installconfig
Adding support to allow overrides of IBM Cloud service endpoints in installconfig. This is a hard requirement for disconnected cluster support, to allow use of non-default endpoints for IBM Cloud services. Related: https://issues.redhat.com/browse/CORS-2933
1 parent 0a9e0e7 commit 8909227

31 files changed

+1159
-131
lines changed

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,49 @@ spec:
33643364
resource group where the cluster should be installed. If empty,
33653365
a new resource group will be created for the cluster.
33663366
type: string
3367+
serviceEndpoints:
3368+
description: ServiceEndpoints is a list which contains custom
3369+
endpoints to override default service endpoints of IBM Cloud
3370+
Services. There must only be one ServiceEndpoint for a service
3371+
(no duplicates).
3372+
items:
3373+
description: IBMCloudServiceEndpoint stores the configuration
3374+
of a custom url to override existing defaults of IBM Cloud
3375+
Services.
3376+
properties:
3377+
name:
3378+
description: 'name is the name of the IBM Cloud service.
3379+
Possible values are: CIS, COS, DNSServices, GlobalSearch,
3380+
GlobalTagging, HyperProtect, IAM, KeyProtect, ResourceController,
3381+
ResourceManager, or VPC. For example, the IBM Cloud Private
3382+
IAM service could be configured with the service `name`
3383+
of `IAM` and `url` of `https://private.iam.cloud.ibm.com`
3384+
Whereas the IBM Cloud Private VPC service for US South
3385+
(Dallas) could be configured with the service `name` of
3386+
`VPC` and `url` of `https://us.south.private.iaas.cloud.ibm.com`'
3387+
enum:
3388+
- CIS
3389+
- COS
3390+
- DNSServices
3391+
- GlobalSearch
3392+
- GlobalTagging
3393+
- HyperProtect
3394+
- IAM
3395+
- KeyProtect
3396+
- ResourceController
3397+
- ResourceManager
3398+
- VPC
3399+
type: string
3400+
url:
3401+
description: url is fully qualified URI with scheme https,
3402+
that overrides the default generated endpoint for a client.
3403+
This must be provided and cannot be empty.
3404+
type: string
3405+
required:
3406+
- name
3407+
- url
3408+
type: object
3409+
type: array
33673410
vpcName:
33683411
description: VPCName is the name of an already existing VPC to
33693412
be used during cluster creation.

pkg/asset/cluster/ibmcloud/ibmcloud.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010
)
1111

1212
// Metadata converts an install configuration to IBM Cloud metadata.
13-
func Metadata(infraID string, config *types.InstallConfig, meta *icibmcloud.Metadata) *ibmcloud.Metadata {
13+
func Metadata(infraID string, config *types.InstallConfig) *ibmcloud.Metadata {
14+
meta := icibmcloud.NewMetadata(config)
1415
accountID, _ := meta.AccountID(context.TODO())
1516
cisCrn, _ := meta.CISInstanceCRN(context.TODO())
1617
dnsInstance, _ := meta.DNSInstance(context.TODO())
@@ -40,6 +41,7 @@ func Metadata(infraID string, config *types.InstallConfig, meta *icibmcloud.Meta
4041
DNSInstanceID: dnsInstanceID,
4142
Region: config.Platform.IBMCloud.Region,
4243
ResourceGroupName: config.Platform.IBMCloud.ClusterResourceGroupName(infraID),
44+
ServiceEndpoints: config.Platform.IBMCloud.ServiceEndpoints,
4345
Subnets: subnets,
4446
VPC: config.Platform.IBMCloud.GetVPCName(),
4547
}

pkg/asset/cluster/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (m *Metadata) Generate(parents asset.Parents) (err error) {
8989
case gcptypes.Name:
9090
metadata.ClusterPlatformMetadata.GCP = gcp.Metadata(installConfig.Config)
9191
case ibmcloudtypes.Name:
92-
metadata.ClusterPlatformMetadata.IBMCloud = ibmcloud.Metadata(clusterID.InfraID, installConfig.Config, installConfig.IBMCloud)
92+
metadata.ClusterPlatformMetadata.IBMCloud = ibmcloud.Metadata(clusterID.InfraID, installConfig.Config)
9393
case baremetaltypes.Name:
9494
metadata.ClusterPlatformMetadata.BareMetal = baremetal.Metadata(installConfig.Config)
9595
case ovirttypes.Name:

pkg/asset/cluster/tfvars.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
awsconfig "github.com/openshift/installer/pkg/asset/installconfig/aws"
3535
aztypes "github.com/openshift/installer/pkg/asset/installconfig/azure"
3636
gcpconfig "github.com/openshift/installer/pkg/asset/installconfig/gcp"
37+
ibmcloudconfig "github.com/openshift/installer/pkg/asset/installconfig/ibmcloud"
3738
ovirtconfig "github.com/openshift/installer/pkg/asset/installconfig/ovirt"
3839
powervsconfig "github.com/openshift/installer/pkg/asset/installconfig/powervs"
3940
vsphereconfig "github.com/openshift/installer/pkg/asset/installconfig/vsphere"
@@ -518,7 +519,8 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
518519
Data: data,
519520
})
520521
case ibmcloud.Name:
521-
client, err := installConfig.IBMCloud.Client()
522+
meta := ibmcloudconfig.NewMetadata(installConfig.Config)
523+
client, err := meta.Client()
522524
if err != nil {
523525
return err
524526
}
@@ -601,8 +603,8 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
601603
vpcPermitted := false
602604

603605
if installConfig.Config.Publish == types.InternalPublishingStrategy {
604-
// Get DNSInstanceCRN from InstallConfig metadata
605-
dnsInstance, err := installConfig.IBMCloud.DNSInstance(ctx)
606+
// Get DNSInstanceCRN from metadata
607+
dnsInstance, err := meta.DNSInstance(ctx)
606608
if err != nil {
607609
return err
608610
}
@@ -611,24 +613,46 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
611613
}
612614
// If the VPC already exists and the cluster is Private, check if the VPC is already a Permitted Network on DNS Instance
613615
if preexistingVPC {
614-
vpcPermitted, err = installConfig.IBMCloud.IsVPCPermittedNetwork(ctx, installConfig.Config.Platform.IBMCloud.VPCName)
616+
vpcPermitted, err = meta.IsVPCPermittedNetwork(ctx, installConfig.Config.Platform.IBMCloud.VPCName)
615617
if err != nil {
616618
return err
617619
}
618620
}
619621
} else {
620-
// Get CISInstanceCRN from InstallConfig metadata
621-
cisCRN, err = installConfig.IBMCloud.CISInstanceCRN(ctx)
622+
// Get CISInstanceCRN from metadata
623+
cisCRN, err = meta.CISInstanceCRN(ctx)
624+
if err != nil {
625+
return err
626+
}
627+
}
628+
629+
// NOTE(cjschaef): If one or more ServiceEndpoint's are supplied, attempt to build the Terraform endpoint_file_path
630+
// https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/guides/custom-service-endpoints#file-structure-for-endpoints-file
631+
var endpointsJSONFile string
632+
if len(installConfig.Config.Platform.IBMCloud.ServiceEndpoints) > 0 {
633+
endpointData, err := ibmcloudtfvars.CreateEndpointJSON(installConfig.Config.Platform.IBMCloud.ServiceEndpoints, installConfig.Config.Platform.IBMCloud.Region)
622634
if err != nil {
623635
return err
624636
}
637+
// While we should have already confirmed there are ServiceEndpoints, we can verify data did get created, requiring the JSON file gets created and passed along
638+
if endpointData == nil {
639+
return fmt.Errorf("failed to generate endpoint JSON with provided IBM Cloud ServiceEndpoints")
640+
}
641+
642+
// Add endpoint JSON data to list of generated files for Terraform
643+
t.FileList = append(t.FileList, &asset.File{
644+
Filename: ibmcloudtfvars.IBMCloudEndpointJSONFileName,
645+
Data: endpointData,
646+
})
647+
endpointsJSONFile = ibmcloudtfvars.IBMCloudEndpointJSONFileName
625648
}
626649

627650
data, err = ibmcloudtfvars.TFVars(
628651
ibmcloudtfvars.TFVarsSources{
629652
Auth: auth,
630653
CISInstanceCRN: cisCRN,
631654
DNSInstanceID: dnsID,
655+
EndpointsJSONFile: endpointsJSONFile,
632656
ImageURL: string(*rhcosImage),
633657
MasterConfigs: masterConfigs,
634658
MasterDedicatedHosts: masterDedicatedHosts,

0 commit comments

Comments
 (0)