-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shared VPC networking #991
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -94,6 +94,11 @@ | |||||
return m.ClusterGetter.Cloud() | ||||||
} | ||||||
|
||||||
// NetworkCloud returns initialized network cloud | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
func (m *MachineScope) NetworkCloud() cloud.Cloud { | ||||||
return m.ClusterGetter.NetworkCloud() | ||||||
} | ||||||
|
||||||
// Zone returns the FailureDomain for the GCPMachine. | ||||||
func (m *MachineScope) Zone() string { | ||||||
if m.Machine.Spec.FailureDomain == nil { | ||||||
|
@@ -276,7 +281,7 @@ | |||||
// InstanceNetworkInterfaceSpec returns compute network interface spec. | ||||||
func (m *MachineScope) InstanceNetworkInterfaceSpec() *compute.NetworkInterface { | ||||||
networkInterface := &compute.NetworkInterface{ | ||||||
Network: path.Join("projects", m.ClusterGetter.Project(), "global", "networks", m.ClusterGetter.NetworkName()), | ||||||
Network: path.Join("projects", m.ClusterGetter.NetworkProject(), "global", "networks", m.ClusterGetter.NetworkName()), | ||||||
} | ||||||
|
||||||
if m.GCPMachine.Spec.PublicIP != nil && *m.GCPMachine.Spec.PublicIP { | ||||||
|
@@ -289,7 +294,7 @@ | |||||
} | ||||||
|
||||||
if m.GCPMachine.Spec.Subnet != nil { | ||||||
networkInterface.Subnetwork = path.Join("regions", m.ClusterGetter.Region(), "subnetworks", *m.GCPMachine.Spec.Subnet) | ||||||
networkInterface.Subnetwork = path.Join("projects", m.ClusterGetter.NetworkProject(), "regions", m.ClusterGetter.Region(), "subnetworks", *m.GCPMachine.Spec.Subnet) | ||||||
} | ||||||
|
||||||
return networkInterface | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -93,6 +93,11 @@ | |||||
return newCloud(s.Project(), s.GCPServices) | ||||||
} | ||||||
|
||||||
// NetworkCloud returns initialized cloud. | ||||||
func (s *ManagedClusterScope) NetworkCloud() cloud.Cloud { | ||||||
return newCloud(s.NetworkProject(), s.GCPServices) | ||||||
} | ||||||
|
||||||
// Project returns the current project name. | ||||||
func (s *ManagedClusterScope) Project() string { | ||||||
return s.GCPManagedCluster.Spec.Project | ||||||
|
@@ -118,9 +123,22 @@ | |||||
return pointer.StringDeref(s.GCPManagedCluster.Spec.Network.Name, "default") | ||||||
} | ||||||
|
||||||
// NetworkProject returns the cluster network unique identifier. | ||||||
func (s *ManagedClusterScope) NetworkProject() string { | ||||||
return pointer.StringDeref(s.GCPManagedCluster.Spec.Network.HostProject, s.GCPManagedCluster.Spec.Project) | ||||||
} | ||||||
|
||||||
// IsSharedVpc returns the cluster network unique identifier. | ||||||
func (s *ManagedClusterScope) IsSharedVpc() bool { | ||||||
if s.NetworkProject() != s.Project() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
return true | ||||||
} | ||||||
return false | ||||||
} | ||||||
|
||||||
// NetworkLink returns the partial URL for the network. | ||||||
func (s *ManagedClusterScope) NetworkLink() string { | ||||||
return fmt.Sprintf("projects/%s/global/networks/%s", s.Project(), s.NetworkName()) | ||||||
return fmt.Sprintf("projects/%s/global/networks/%s", s.NetworkProject(), s.NetworkName()) | ||||||
} | ||||||
|
||||||
// Network returns the cluster network object. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,9 @@ func (s *Service) Reconcile(ctx context.Context) error { | |
// Delete deletes cluster subnetwork components. | ||
func (s *Service) Delete(ctx context.Context) error { | ||
logger := log.FromContext(ctx) | ||
if s.scope.IsSharedVpc() { | ||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Log/Alert that this is a shared VPC. |
||
} | ||
for _, subnetSpec := range s.scope.SubnetSpecs() { | ||
logger.V(2).Info("Deleting a subnet", "name", subnetSpec.Name) | ||
subnetKey := meta.RegionalKey(subnetSpec.Name, s.scope.Region()) | ||
|
@@ -68,6 +71,11 @@ func (s *Service) createOrGetSubnets(ctx context.Context) ([]*compute.Subnetwork | |
return subnets, err | ||
} | ||
|
||
if s.scope.IsSharedVpc() { | ||
logger.Error(err, "VPC is enabled. Error looking for subnetwork", "name", subnetSpec.Name) | ||
return nil, err | ||
} | ||
|
||
// Subnet was not found, let's create it | ||
logger.V(2).Info("Creating a subnet", "name", subnetSpec.Name) | ||
if err := s.subnets.Insert(ctx, subnetKey, subnetSpec); err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.