-
Notifications
You must be signed in to change notification settings - Fork 425
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
enable the use of an external control plane #4611
base: main
Are you sure you want to change the base?
Changes from 1 commit
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 | ||||
---|---|---|---|---|---|---|
|
@@ -45,6 +45,11 @@ type AzureClusterSpec struct { | |||||
// +optional | ||||||
BastionSpec BastionSpec `json:"bastionSpec,omitempty"` | ||||||
|
||||||
// ControlPlaneEnabled enable control plane cluster components. | ||||||
// +kubebuilder:default=true | ||||||
// +optional | ||||||
ControlPlaneEnabled bool `json:"controlPlaneEnabled"` | ||||||
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
|
||||||
|
||||||
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane. It is not recommended to set | ||||||
// this when creating an AzureCluster as CAPZ will set this for you. However, if it is set, CAPZ will not change it. | ||||||
// +optional | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,12 @@ limitations under the License. | |
package v1beta1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"reflect" | ||
"regexp" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
valid "github.com/asaskevich/govalidator" | ||
corev1 "k8s.io/api/core/v1" | ||
|
@@ -85,12 +87,16 @@ func (c *AzureCluster) validateCluster(old *AzureCluster) (admission.Warnings, e | |
|
||
// validateClusterSpec validates a ClusterSpec. | ||
func (c *AzureCluster) validateClusterSpec(old *AzureCluster) field.ErrorList { | ||
logger := log.FromContext(context.TODO()) | ||
var allErrs field.ErrorList | ||
var oldNetworkSpec NetworkSpec | ||
if old != nil { | ||
oldNetworkSpec = old.Spec.NetworkSpec | ||
} | ||
allErrs = append(allErrs, validateNetworkSpec(c.Spec.NetworkSpec, oldNetworkSpec, field.NewPath("spec").Child("networkSpec"))...) | ||
|
||
logger.Info(fmt.Sprintf("ControlPlaneEnabled: %v", c.Spec.ControlPlaneEnabled)) | ||
|
||
allErrs = append(allErrs, validateNetworkSpec(c.Spec.ControlPlaneEnabled, c.Spec.NetworkSpec, oldNetworkSpec, field.NewPath("spec").Child("networkSpec"))...) | ||
|
||
var oldCloudProviderConfigOverrides *CloudProviderConfigOverrides | ||
if old != nil { | ||
|
@@ -154,7 +160,7 @@ func validateIdentityRef(identityRef *corev1.ObjectReference, fldPath *field.Pat | |
} | ||
|
||
// validateNetworkSpec validates a NetworkSpec. | ||
func validateNetworkSpec(networkSpec NetworkSpec, old NetworkSpec, fldPath *field.Path) field.ErrorList { | ||
func validateNetworkSpec(controlPlaneEnabled bool, networkSpec NetworkSpec, old NetworkSpec, fldPath *field.Path) field.ErrorList { | ||
var allErrs field.ErrorList | ||
// If the user specifies a resourceGroup for vnet, it means | ||
// that they intend to use a pre-existing vnet. In this case, | ||
|
@@ -167,20 +173,21 @@ func validateNetworkSpec(networkSpec NetworkSpec, old NetworkSpec, fldPath *fiel | |
|
||
allErrs = append(allErrs, validateVnetCIDR(networkSpec.Vnet.CIDRBlocks, fldPath.Child("cidrBlocks"))...) | ||
|
||
allErrs = append(allErrs, validateSubnets(networkSpec.Subnets, networkSpec.Vnet, fldPath.Child("subnets"))...) | ||
allErrs = append(allErrs, validateSubnets(controlPlaneEnabled, networkSpec.Subnets, networkSpec.Vnet, fldPath.Child("subnets"))...) | ||
|
||
allErrs = append(allErrs, validateVnetPeerings(networkSpec.Vnet.Peerings, fldPath.Child("peerings"))...) | ||
} | ||
|
||
var cidrBlocks []string | ||
controlPlaneSubnet, err := networkSpec.GetControlPlaneSubnet() | ||
if err != nil { | ||
allErrs = append(allErrs, field.Invalid(fldPath.Child("subnets"), networkSpec.Subnets, "ControlPlaneSubnet invalid")) | ||
} | ||
|
||
cidrBlocks = controlPlaneSubnet.CIDRBlocks | ||
if controlPlaneEnabled { | ||
controlPlaneSubnet, err := networkSpec.GetControlPlaneSubnet() | ||
if err != nil { | ||
allErrs = append(allErrs, field.Invalid(fldPath.Child("subnets"), networkSpec.Subnets, "ControlPlaneSubnet invalid")) | ||
} | ||
|
||
allErrs = append(allErrs, validateAPIServerLB(networkSpec.APIServerLB, old.APIServerLB, cidrBlocks, fldPath.Child("apiServerLB"))...) | ||
cidrBlocks = controlPlaneSubnet.CIDRBlocks | ||
allErrs = append(allErrs, validateAPIServerLB(networkSpec.APIServerLB, old.APIServerLB, cidrBlocks, fldPath.Child("apiServerLB"))...) | ||
} | ||
|
||
var needOutboundLB bool | ||
for _, subnet := range networkSpec.Subnets { | ||
|
@@ -192,10 +199,14 @@ func validateNetworkSpec(networkSpec NetworkSpec, old NetworkSpec, fldPath *fiel | |
if needOutboundLB { | ||
allErrs = append(allErrs, validateNodeOutboundLB(networkSpec.NodeOutboundLB, old.NodeOutboundLB, networkSpec.APIServerLB, fldPath.Child("nodeOutboundLB"))...) | ||
} | ||
|
||
allErrs = append(allErrs, validateControlPlaneOutboundLB(networkSpec.ControlPlaneOutboundLB, networkSpec.APIServerLB, fldPath.Child("controlPlaneOutboundLB"))...) | ||
|
||
allErrs = append(allErrs, validatePrivateDNSZoneName(networkSpec.PrivateDNSZoneName, networkSpec.APIServerLB.Type, fldPath.Child("privateDNSZoneName"))...) | ||
if controlPlaneEnabled { | ||
allErrs = append(allErrs, validateControlPlaneOutboundLB(networkSpec.ControlPlaneOutboundLB, networkSpec.APIServerLB, fldPath.Child("controlPlaneOutboundLB"))...) | ||
} | ||
var lbType LBType = Internal | ||
if networkSpec.APIServerLB != nil { | ||
lbType = networkSpec.APIServerLB.Type | ||
} | ||
allErrs = append(allErrs, validatePrivateDNSZoneName(networkSpec.PrivateDNSZoneName, controlPlaneEnabled, lbType, fldPath.Child("privateDNSZoneName"))...) | ||
|
||
if len(allErrs) == 0 { | ||
return nil | ||
|
@@ -214,11 +225,11 @@ func validateResourceGroup(resourceGroup string, fldPath *field.Path) *field.Err | |
|
||
// validateSubnets validates a list of Subnets. | ||
// When configuring a cluster, it is essential to include either a control-plane subnet and a node subnet, or a user can configure a cluster subnet which will be used as a control-plane subnet and a node subnet. | ||
func validateSubnets(subnets Subnets, vnet VnetSpec, fldPath *field.Path) field.ErrorList { | ||
func validateSubnets(controlPlaneEnabled bool, subnets Subnets, vnet VnetSpec, fldPath *field.Path) field.ErrorList { | ||
var allErrs field.ErrorList | ||
subnetNames := make(map[string]bool, len(subnets)) | ||
requiredSubnetRoles := map[string]bool{ | ||
"control-plane": false, | ||
"control-plane": !controlPlaneEnabled, | ||
"node": false, | ||
} | ||
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. This should be refactored this way: requiredSubnetRoles := map[string]bool{
"node": false,
}
if controlPlaneEnabled {
requiredSubnetRoles["control-plane"] = false
} The key |
||
clusterSubnet := false | ||
|
@@ -383,7 +394,7 @@ func validateSecurityRule(rule SecurityRule, fldPath *field.Path) (allErrs field | |
return allErrs | ||
} | ||
|
||
func validateAPIServerLB(lb LoadBalancerSpec, old LoadBalancerSpec, cidrs []string, fldPath *field.Path) field.ErrorList { | ||
func validateAPIServerLB(lb *LoadBalancerSpec, old *LoadBalancerSpec, cidrs []string, fldPath *field.Path) field.ErrorList { | ||
var allErrs field.ErrorList | ||
|
||
lbClassSpec := lb.LoadBalancerClassSpec | ||
|
@@ -433,7 +444,7 @@ func validateAPIServerLB(lb LoadBalancerSpec, old LoadBalancerSpec, cidrs []stri | |
return allErrs | ||
} | ||
|
||
func validateNodeOutboundLB(lb *LoadBalancerSpec, old *LoadBalancerSpec, apiserverLB LoadBalancerSpec, fldPath *field.Path) field.ErrorList { | ||
func validateNodeOutboundLB(lb *LoadBalancerSpec, old *LoadBalancerSpec, apiserverLB *LoadBalancerSpec, fldPath *field.Path) field.ErrorList { | ||
var allErrs field.ErrorList | ||
|
||
var lbClassSpec, oldClassSpec *LoadBalancerClassSpec | ||
|
@@ -483,7 +494,7 @@ func validateNodeOutboundLB(lb *LoadBalancerSpec, old *LoadBalancerSpec, apiserv | |
return allErrs | ||
} | ||
|
||
func validateControlPlaneOutboundLB(lb *LoadBalancerSpec, apiserverLB LoadBalancerSpec, fldPath *field.Path) field.ErrorList { | ||
func validateControlPlaneOutboundLB(lb *LoadBalancerSpec, apiserverLB *LoadBalancerSpec, fldPath *field.Path) field.ErrorList { | ||
var allErrs field.ErrorList | ||
|
||
var lbClassSpec *LoadBalancerClassSpec | ||
|
@@ -505,11 +516,11 @@ func validateControlPlaneOutboundLB(lb *LoadBalancerSpec, apiserverLB LoadBalanc | |
} | ||
|
||
// validatePrivateDNSZoneName validates the PrivateDNSZoneName. | ||
func validatePrivateDNSZoneName(privateDNSZoneName string, apiserverLBType LBType, fldPath *field.Path) field.ErrorList { | ||
func validatePrivateDNSZoneName(privateDNSZoneName string, controlPlaneEnabled bool, apiserverLBType LBType, fldPath *field.Path) field.ErrorList { | ||
var allErrs field.ErrorList | ||
|
||
if len(privateDNSZoneName) > 0 { | ||
if apiserverLBType != Internal { | ||
if controlPlaneEnabled && apiserverLBType != Internal { | ||
allErrs = append(allErrs, field.Invalid(fldPath, apiserverLBType, | ||
"PrivateDNSZoneName is available only if APIServerLB.Type is Internal")) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,7 @@ type NetworkSpec struct { | |
|
||
// APIServerLB is the configuration for the control-plane load balancer. | ||
// +optional | ||
APIServerLB LoadBalancerSpec `json:"apiServerLB,omitempty"` | ||
APIServerLB *LoadBalancerSpec `json:"apiServerLB,omitempty"` | ||
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. Instead of using a pointer, what about moving the additional field you introduced ( With such approach we could introduce the feature smoothly with no breaking changes, and maintain the current state of the pointers. 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. The "problem" is that der is a mutation inside the webhook and if this is no pointer then some fields will be filled which makes problems later. To me the question is 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. LGTM, it makes sense. |
||
|
||
// NodeOutboundLB is the configuration for the node outbound load balancer. | ||
// +optional | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Do worker nodes use the node outbound LB too?