Skip to content

Commit

Permalink
Add Optional Override API Endpoint
Browse files Browse the repository at this point in the history
This adds an optional field to the Network API to override what
is being sent back to Cluster API as the API Endpoint for K8S.
This is more of a, Hope you know what you are doing! feature.

Signed-off-by: David ML Brown Jr <[email protected]>
  • Loading branch information
dmlb2000 committed Jan 11, 2022
1 parent d29299c commit ee000b4
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 20 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha3/azurecluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (src *AzureCluster) ConvertTo(dstRaw conversion.Hub) error { // nolint

dst.Spec.NetworkSpec.APIServerLB.FrontendIPsCount = restored.Spec.NetworkSpec.APIServerLB.FrontendIPsCount
dst.Spec.NetworkSpec.APIServerLB.IdleTimeoutInMinutes = restored.Spec.NetworkSpec.APIServerLB.IdleTimeoutInMinutes
dst.Spec.NetworkSpec.OverrideAPIEndpoint = restored.Spec.NetworkSpec.OverrideAPIEndpoint
dst.Spec.CloudProviderConfigOverrides = restored.Spec.CloudProviderConfigOverrides
dst.Spec.BastionSpec = restored.Spec.BastionSpec

Expand Down Expand Up @@ -185,6 +186,8 @@ func Convert_v1alpha3_NetworkSpec_To_v1beta1_NetworkSpec(in *NetworkSpec, out *i
}
}

out.OverrideAPIEndpoint = nil

if err := autoConvert_v1alpha3_LoadBalancerSpec_To_v1beta1_LoadBalancerSpec(&in.APIServerLB, &out.APIServerLB, s); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions api/v1alpha4/azurecluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (src *AzureCluster) ConvertTo(dstRaw conversion.Hub) error { // nolint

// Restore list of virtual network peerings
dst.Spec.NetworkSpec.Vnet.Peerings = restored.Spec.NetworkSpec.Vnet.Peerings
dst.Spec.NetworkSpec.OverrideAPIEndpoint = restored.Spec.NetworkSpec.OverrideAPIEndpoint

return nil
}
Expand Down Expand Up @@ -79,3 +80,19 @@ func Convert_v1beta1_VnetSpec_To_v1alpha4_VnetSpec(in *infrav1beta1.VnetSpec, ou
func Convert_v1alpha4_VnetSpec_To_v1beta1_VnetSpec(in *VnetSpec, out *infrav1beta1.VnetSpec, s apiconversion.Scope) error {
return autoConvert_v1alpha4_VnetSpec_To_v1beta1_VnetSpec(in, out, s)
}

// Convert_v1alpha4_NetworkSpec_To_v1beta1_NetworkSpec is an autogenerated conversion function.
func Convert_v1alpha4_NetworkSpec_To_v1beta1_NetworkSpec(in *NetworkSpec, out *infrav1beta1.NetworkSpec, s apiconversion.Scope) error {
if err := autoConvert_v1alpha4_NetworkSpec_To_v1beta1_NetworkSpec(in, out, s); err != nil {
return err
}

out.OverrideAPIEndpoint = nil

return nil
}

// Convert_v1beta1_NetworkSpec_To_v1alpha4_NetworkSpec is an autogenerated conversion function.
func Convert_v1beta1_NetworkSpec_To_v1alpha4_NetworkSpec(in *infrav1beta1.NetworkSpec, out *NetworkSpec, s apiconversion.Scope) error {
return autoConvert_v1beta1_NetworkSpec_To_v1alpha4_NetworkSpec(in, out, s)
}
31 changes: 11 additions & 20 deletions api/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/api/resource"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const (
Expand Down Expand Up @@ -75,6 +76,10 @@ type NetworkSpec struct {
// +optional
APIServerLB LoadBalancerSpec `json:"apiServerLB,omitempty"`

// override API Endpoint passed back to Cluster API (hope you know what you are doing, good luck!)
// +optional
OverrideAPIEndpoint *clusterv1.APIEndpoint `json:"overrideAPIEndpoint,omitempty"`

// NodeOutboundLB is the configuration for the node outbound load balancer.
// +optional
NodeOutboundLB *LoadBalancerSpec `json:"nodeOutboundLB,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,10 @@ func (s *ClusterScope) AdditionalTags() infrav1.Tags {

// APIServerPort returns the APIServerPort to use when creating the load balancer.
func (s *ClusterScope) APIServerPort() int32 {
netSpec := s.AzureCluster.Spec.NetworkSpec
if netSpec.OverrideAPIEndpoint != nil {
return netSpec.OverrideAPIEndpoint.Port
}
if s.Cluster.Spec.ClusterNetwork != nil && s.Cluster.Spec.ClusterNetwork.APIServerPort != nil {
return *s.Cluster.Spec.ClusterNetwork.APIServerPort
}
Expand All @@ -657,6 +661,10 @@ func (s *ClusterScope) APIServerPort() int32 {

// APIServerHost returns the hostname used to reach the API server.
func (s *ClusterScope) APIServerHost() string {
netSpec := s.AzureCluster.Spec.NetworkSpec
if netSpec.OverrideAPIEndpoint != nil && len(netSpec.OverrideAPIEndpoint.Host) > 0 {
return netSpec.OverrideAPIEndpoint.Host
}
if s.IsAPIServerPrivate() {
return azure.GeneratePrivateFQDN(s.GetPrivateDNSZoneName())
}
Expand Down
15 changes: 15 additions & 0 deletions azure/scope/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ func TestAPIServerHost(t *testing.T) {
},
want: "apiserver.example.private",
},
{
name: "override host returned to cluster api.",
azureCluster: infrav1.AzureCluster{
Spec: infrav1.AzureClusterSpec{
SubscriptionID: fakeSubscriptionID,
NetworkSpec: infrav1.NetworkSpec{
OverrideAPIEndpoint: &clusterv1.APIEndpoint{
Host: "apiserver.example.private",
Port: 443,
},
},
},
},
want: "apiserver.example.private",
},
}

for _, tc := range tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,21 @@ spec:
description: LBType defines an Azure load balancer Type.
type: string
type: object
overrideAPIEndpoint:
description: override API Endpoint passed back to Cluster API
(hope you know what you are doing, good luck!)
properties:
host:
description: The hostname on which the API server is serving.
type: string
port:
description: The port on which the API server is serving.
format: int32
type: integer
required:
- host
- port
type: object
privateDNSZoneName:
description: PrivateDNSZoneName defines the zone name for the
Azure Private DNS.
Expand Down

0 comments on commit ee000b4

Please sign in to comment.