Skip to content

Commit

Permalink
Test logs
Browse files Browse the repository at this point in the history
Signed-off-by: Aswin Suryanarayanan <[email protected]>
  • Loading branch information
aswinsuryan committed Dec 7, 2024
1 parent baffb51 commit 5cb5a3b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
22 changes: 5 additions & 17 deletions pkg/gcp/cloud_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,12 @@ import (
"google.golang.org/api/compute/v1"
)

type CloudOption func(*CloudInfo)

const (
VPCName = "VPCName"
)

type CloudInfo struct {
InfraID string
Region string
ProjectID string
cloudConfig map[string]interface{}
Client gcpclient.Interface
}

func WithVPCName(name string) CloudOption {
return func(cloud *CloudInfo) {
cloud.cloudConfig[VPCName] = name
}
InfraID string
Region string
ProjectID string
VpcName string
Client gcpclient.Interface
}

// Open expected ports by creating related firewall rule.
Expand Down
2 changes: 1 addition & 1 deletion pkg/gcp/firewall_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func newFirewallRule(projectID, name, direction, network string, ports []api.Por
return &compute.Firewall{
Name: name,
//Network: fmt.Sprintf("projects/%s/global/networks/%s-network", projectID, infraID),
Network: fmt.Sprintf("projects/%s/global/networks/%s-network", projectID, network),
Network: fmt.Sprintf("projects/%s/global/networks/%s", projectID, network),
Direction: direction,
Allowed: allowedPorts,
}
Expand Down
19 changes: 8 additions & 11 deletions pkg/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,22 @@ type gcpCloud struct {
}

// NewCloud creates a new api.Cloud instance which can prepare GCP for Submariner to be deployed on it.
func NewCloud(info CloudInfo, opts ...CloudOption) api.Cloud {
info.cloudConfig = make(map[string]interface{})
for _, opt := range opts {
opt(&info)
}
if _, ok := info.cloudConfig[VPCName]; !ok {
info.cloudConfig[VPCName] = info.InfraID + "-network"
func NewCloud(info CloudInfo) api.Cloud {
gcpCloud := &gcpCloud{CloudInfo: info}

if gcpCloud.VpcName == "" {
gcpCloud.VpcName = info.InfraID + "-network"
}
return &gcpCloud{CloudInfo: info}

return gcpCloud
}

func (gc *gcpCloud) OpenPorts(ports []api.PortSpec, status reporter.Interface) error {
// Create the inbound firewall rule for submariner internal ports.
status.Start("Opening internal ports %q for intra-cluster communications on GCP", formatPorts(ports))
defer status.End()

vpcName, _ := gc.cloudConfig[VPCName]

internalIngress := newInternalFirewallRule(gc.ProjectID, gc.InfraID, vpcName.(string), ports)
internalIngress := newInternalFirewallRule(gc.ProjectID, gc.InfraID, gc.VpcName, ports)
if err := gc.openPorts(internalIngress); err != nil {
return status.Error(err, "unable to open ports")
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/gcp/ocpgwdeployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ type ocpGatewayDeployer struct {
func NewOcpGatewayDeployer(info CloudInfo, msDeployer ocp.MachineSetDeployer, instanceType, image string,
k8sClient k8s.Interface,
) api.GatewayDeployer {
cloudInfo := info

if cloudInfo.VpcName == "" {
cloudInfo.VpcName = info.InfraID + "-network"
}

return &ocpGatewayDeployer{
CloudInfo: info,
CloudInfo: cloudInfo,
msDeployer: msDeployer,
instanceType: instanceType,
image: image,
Expand All @@ -60,9 +66,7 @@ func (d *ocpGatewayDeployer) Deploy(input api.GatewayDeployInput, status reporte
status.Start("Configuring the required firewall rules for inter-cluster traffic")
defer status.End()

vpcName, _ := d.cloudConfig[VPCName]

externalIngress := newExternalFirewallRules(d.ProjectID, d.InfraID, vpcName.(string), input.PublicPorts)
externalIngress := newExternalFirewallRules(d.ProjectID, d.InfraID, d.VpcName, input.PublicPorts)
if err := d.openPorts(externalIngress); err != nil {
return status.Error(err, "error creating firewall rule %q", externalIngress.Name)
}
Expand Down

0 comments on commit 5cb5a3b

Please sign in to comment.