Skip to content

Commit 8ecd944

Browse files
Merge pull request #9992 from barbacbd/CORS-4258
CORS-4258: Create a Private DNS Zone for PSC
2 parents c999161 + d0ba8fc commit 8ecd944

38 files changed

+570
-513
lines changed

data/data/install.openshift.io_installconfigs.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5847,6 +5847,14 @@ spec:
58475847
endpoint:
58485848
description: Endpoint is the private service connect endpoint.
58495849
properties:
5850+
clusterUseOnly:
5851+
description: |-
5852+
ClusterUseOnly should be set to true when the installer should use
5853+
the public api endpoints and all cluster operators should use the
5854+
api endpoint overrides. The value should be false when the installer
5855+
and cluster operators should use the api endpoint overrides; that is,
5856+
the installer is being run in the same network as the cluster.
5857+
type: boolean
58505858
name:
58515859
description: Name contains the name of the private service
58525860
connect endpoint.

pkg/asset/cluster/gcp/gcp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ func Metadata(config *types.InstallConfig) *gcp.Metadata {
2828
NetworkProjectID: config.Platform.GCP.NetworkProjectID,
2929
PrivateZoneDomain: privateZoneDomain,
3030
PrivateZoneProjectID: privateZoneProject,
31-
ServiceEndpoints: config.Platform.GCP.ServiceEndpoints,
31+
Endpoint: config.Platform.GCP.Endpoint,
3232
}
3333
}

pkg/asset/cluster/tfvars/tfvars.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
igntypes "github.com/coreos/ignition/v2/config/v3_2/types"
1313
"github.com/pkg/errors"
1414
"github.com/sirupsen/logrus"
15+
"google.golang.org/api/option"
1516
"k8s.io/utils/ptr"
1617
"sigs.k8s.io/yaml"
1718

@@ -452,7 +453,7 @@ func (t *TerraformVariables) Generate(ctx context.Context, parents asset.Parents
452453
ServiceAccount: string(sess.Credentials.JSON),
453454
}
454455

455-
client, err := gcpconfig.NewClient(context.Background(), installConfig.Config.GCP.ServiceEndpoints)
456+
client, err := gcpconfig.NewClient(context.Background(), installConfig.Config.GCP.Endpoint)
456457
if err != nil {
457458
return err
458459
}
@@ -527,7 +528,13 @@ func (t *TerraformVariables) Generate(ctx context.Context, parents asset.Parents
527528
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
528529
defer cancel()
529530

530-
storageClient, err := gcpconfig.GetStorageService(ctx, installConfig.Config.GCP.ServiceEndpoints)
531+
opts := []option.ClientOption{}
532+
endpoint := installConfig.Config.GCP.Endpoint
533+
if gcp.ShouldUseEndpointForInstaller(endpoint) {
534+
opts = append(opts, gcpconfig.CreateEndpointOption(endpoint.Name, gcpconfig.ServiceNameGCPStorage))
535+
}
536+
537+
storageClient, err := gcpconfig.GetStorageService(ctx, opts...)
531538
if err != nil {
532539
return fmt.Errorf("failed to create storage client: %w", err)
533540
}

pkg/asset/installconfig/basedomain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (a *baseDomain) Generate(_ context.Context, parents asset.Parents) error {
6464
a.BaseDomain = zone.Name
6565
return platform.Azure.SetBaseDomain(zone.ID)
6666
case gcp.Name:
67-
a.BaseDomain, err = gcpconfig.GetBaseDomain(platform.GCP.ProjectID, platform.GCP.ServiceEndpoints)
67+
a.BaseDomain, err = gcpconfig.GetBaseDomain(platform.GCP.ProjectID, platform.GCP.Endpoint)
6868

6969
// We are done if success (err == nil) or an err besides forbidden/throttling
7070
if !(gcpconfig.IsForbidden(err) || gcpconfig.IsThrottled(err)) {

pkg/asset/installconfig/gcp/client.go

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
serviceusage "google.golang.org/api/serviceusage/v1beta1"
2121
"k8s.io/apimachinery/pkg/util/sets"
2222

23-
configv1 "github.com/openshift/api/config/v1"
2423
gcpconsts "github.com/openshift/installer/pkg/constants/gcp"
2524
gcptypes "github.com/openshift/installer/pkg/types/gcp"
2625
)
@@ -60,56 +59,76 @@ type API interface {
6059
GetNamespacedTagValue(ctx context.Context, tagNamespacedName string) (*cloudresourcemanager.TagValue, error)
6160
GetKeyRing(ctx context.Context, kmsKeyRef *gcptypes.KMSKeyReference) (*kmspb.KeyRing, error)
6261
UpdateDNSPrivateZoneLabels(ctx context.Context, baseDomain, project, zoneName string, labels map[string]string) error
62+
GetPrivateServiceConnectEndpoint(ctx context.Context, project string, endpoint *gcptypes.PSCEndpoint) (*compute.ForwardingRule, error)
6363
}
6464

6565
// Client makes calls to the GCP API.
6666
type Client struct {
67-
ssn *Session
68-
endpoints []configv1.GCPServiceEndpoint
67+
ssn *Session
68+
endpointName string
6969
}
7070

7171
// NewClient initializes a client with a session.
72-
func NewClient(ctx context.Context, endpoints []configv1.GCPServiceEndpoint) (*Client, error) {
72+
func NewClient(ctx context.Context, endpoint *gcptypes.PSCEndpoint) (*Client, error) {
7373
ssn, err := GetSession(ctx)
7474
if err != nil {
7575
return nil, errors.Wrap(err, "failed to get session")
7676
}
7777

78-
modifiedEndpoints := FormatGCPEndpointList(endpoints, FormatGCPEndpointInput{SkipPath: false})
78+
endpointName := ""
79+
if gcptypes.ShouldUseEndpointForInstaller(endpoint) {
80+
endpointName = endpoint.Name
81+
}
7982

8083
client := &Client{
81-
ssn: ssn,
82-
endpoints: modifiedEndpoints,
84+
ssn: ssn,
85+
endpointName: endpointName,
8386
}
8487
return client, nil
8588
}
8689

8790
func (c *Client) getComputeService(ctx context.Context) (*compute.Service, error) {
88-
svc, err := GetComputeService(ctx, c.endpoints)
91+
opts := []option.ClientOption{}
92+
if c.endpointName != "" {
93+
opts = append(opts, CreateEndpointOption(c.endpointName, ServiceNameGCPCompute))
94+
}
95+
svc, err := GetComputeService(ctx, opts...)
8996
if err != nil {
9097
return nil, fmt.Errorf("client failed to create compute service: %w", err)
9198
}
9299
return svc, nil
93100
}
94101

95102
func (c *Client) getDNSService(ctx context.Context) (*dns.Service, error) {
96-
svc, err := GetDNSService(ctx, c.endpoints)
103+
opts := []option.ClientOption{}
104+
if c.endpointName != "" {
105+
opts = append(opts, CreateEndpointOption(c.endpointName, ServiceNameGCPDNS))
106+
}
107+
svc, err := GetDNSService(ctx, opts...)
97108
if err != nil {
98109
return nil, fmt.Errorf("client failed to create dns service: %w", err)
99110
}
100111
return svc, nil
101112
}
102113

103114
func (c *Client) getCloudResourceService(ctx context.Context) (*cloudresourcemanager.Service, error) {
104-
svc, err := GetCloudResourceService(ctx, c.endpoints)
115+
opts := []option.ClientOption{}
116+
if c.endpointName != "" {
117+
opts = append(opts, CreateEndpointOption(c.endpointName, ServiceNameGCPCloudResource))
118+
}
119+
svc, err := GetCloudResourceService(ctx, opts...)
105120
if err != nil {
106121
return nil, fmt.Errorf("client failed to create cloud resource service: %w", err)
107122
}
108123
return svc, nil
109124
}
110125

111126
func (c *Client) getServiceUsageService(ctx context.Context) (*serviceusage.APIService, error) {
112-
svc, err := GetServiceUsageService(ctx, c.endpoints)
127+
opts := []option.ClientOption{}
128+
if c.endpointName != "" {
129+
opts = append(opts, CreateEndpointOption(c.endpointName, ServiceNameGCPServiceUsage))
130+
}
131+
svc, err := GetServiceUsageService(ctx, opts...)
113132
if err != nil {
114133
return nil, fmt.Errorf("client failed to create service usage service: %w", err)
115134
}
@@ -576,7 +595,11 @@ func (c *Client) GetEnabledServices(ctx context.Context, project string) ([]stri
576595

577596
// GetServiceAccount retrieves a service account from a project if it exists.
578597
func (c *Client) GetServiceAccount(ctx context.Context, project, serviceAccount string) (string, error) {
579-
svc, err := GetIAMService(ctx, c.endpoints)
598+
opts := []option.ClientOption{}
599+
if c.endpointName != "" {
600+
opts = append(opts, CreateEndpointOption(c.endpointName, ServiceNameGCPIAM))
601+
}
602+
svc, err := GetIAMService(ctx, opts...)
580603
if err != nil {
581604
return "", errors.Wrapf(err, "failed create IAM service")
582605
}
@@ -740,3 +763,40 @@ func (c *Client) GetKeyRing(ctx context.Context, kmsKeyRef *gcptypes.KMSKeyRefer
740763
}
741764
return nil, fmt.Errorf("failed to find kms key ring with name %s", keyRingName)
742765
}
766+
767+
// GetPrivateServiceConnectEndpoint finds the GCP compute forwarding rule that is associated with the endpoint.
768+
func GetPrivateServiceConnectEndpoint(client *compute.Service, project string, endpoint *gcptypes.PSCEndpoint) (*compute.ForwardingRule, error) {
769+
if endpoint == nil {
770+
return nil, nil
771+
}
772+
773+
var forwardingRules *compute.ForwardingRuleList
774+
var forwardingRuleErr error
775+
if endpoint.Region != "" {
776+
forwardingRules, forwardingRuleErr = client.ForwardingRules.List(project, endpoint.Region).Do()
777+
} else {
778+
forwardingRules, forwardingRuleErr = client.GlobalForwardingRules.List(project).Do()
779+
}
780+
if forwardingRuleErr != nil {
781+
return nil, fmt.Errorf("failed to list forwarding rules: %w", forwardingRuleErr)
782+
}
783+
784+
if forwardingRules != nil {
785+
// Iterate through forwarding rules to find the PSC endpoint
786+
for _, rule := range forwardingRules.Items {
787+
if rule.Name == endpoint.Name {
788+
return rule, nil
789+
}
790+
}
791+
}
792+
return nil, fmt.Errorf("failed to find forwarding rule for private service connect endpoint %s", endpoint.Name)
793+
}
794+
795+
// GetPrivateServiceConnectEndpoint will get the forwarding rule associated with a private service connect endpoint.
796+
func (c *Client) GetPrivateServiceConnectEndpoint(ctx context.Context, project string, endpoint *gcptypes.PSCEndpoint) (*compute.ForwardingRule, error) {
797+
svc, err := c.getComputeService(ctx)
798+
if err != nil {
799+
return nil, fmt.Errorf("failed to create Compute service: %w", err)
800+
}
801+
return GetPrivateServiceConnectEndpoint(svc, project, endpoint)
802+
}

pkg/asset/installconfig/gcp/dns.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111
"github.com/pkg/errors"
1212
"google.golang.org/api/googleapi"
1313

14-
configv1 "github.com/openshift/api/config/v1"
14+
gcptypes "github.com/openshift/installer/pkg/types/gcp"
1515
)
1616

1717
// GetBaseDomain returns a base domain chosen from among the project's public DNS zones.
18-
func GetBaseDomain(project string, endpoints []configv1.GCPServiceEndpoint) (string, error) {
19-
client, err := NewClient(context.TODO(), endpoints)
18+
func GetBaseDomain(project string, endpoint *gcptypes.PSCEndpoint) (string, error) {
19+
client, err := NewClient(context.TODO(), endpoint)
2020
if err != nil {
2121
return "", err
2222
}

pkg/asset/installconfig/gcp/mock/gcpclient_generated.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)