Skip to content
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

[WIP]pvt cluster changes #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/v1beta1/azurecluster_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1beta1

import (
"fmt"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network"

"k8s.io/utils/pointer"
)
Expand Down Expand Up @@ -307,6 +308,9 @@ func (lb *LoadBalancerClassSpec) setAPIServerLBDefaults() {
if lb.SKU == "" {
lb.SKU = SKUStandard
}
if lb.IPAllocationMethod == "" {
lb.IPAllocationMethod = string(network.IPAllocationMethodDynamic)
}
if lb.IdleTimeoutInMinutes == nil {
lb.IdleTimeoutInMinutes = pointer.Int32Ptr(DefaultOutboundRuleIdleTimeoutInMinutes)
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta1/azurecluster_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func validateAPIServerLB(lb LoadBalancerSpec, old LoadBalancerSpec, cidrs []stri
fldPath.Child("frontendIPConfigs").Index(0).Child("privateIP")); err != nil {
allErrs = append(allErrs, err)
}
if len(old.FrontendIPs) != 0 && old.FrontendIPs[0].PrivateIPAddress != lb.FrontendIPs[0].PrivateIPAddress {
if lb.IPAllocationMethod == "Static" && len(old.FrontendIPs) != 0 && old.FrontendIPs[0].PrivateIPAddress != lb.FrontendIPs[0].PrivateIPAddress {
allErrs = append(allErrs, field.Forbidden(fldPath.Child("name"), "API Server load balancer private IP should not be modified after AzureCluster creation."))
}
}
Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/types_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type LoadBalancerClassSpec struct {
SKU SKU `json:"sku,omitempty"`
// +optional
Type LBType `json:"type,omitempty"`
// +optional
IPAllocationMethod string `json:"ipAllocationMethod,omitempty"`
// IdleTimeoutInMinutes specifies the timeout for the TCP idle connection.
// +optional
IdleTimeoutInMinutes *int32 `json:"idleTimeoutInMinutes,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func (s *ClusterScope) LBSpecs() []azure.ResourceSpecGetter {
Type: s.APIServerLB().Type,
SKU: infrav1.SKUStandard,
Role: infrav1.APIServerRole,
IPAllocationMethod: s.APIServerLB().IPAllocationMethod,
BackendPoolName: s.APIServerLBPoolName(s.APIServerLB().Name),
IdleTimeoutInMinutes: s.APIServerLB().IdleTimeoutInMinutes,
AdditionalTags: s.AdditionalTags(),
Expand Down
19 changes: 17 additions & 2 deletions azure/services/loadbalancers/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package loadbalancers

import (
"context"
"fmt"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network"
"github.com/pkg/errors"

infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
Expand Down Expand Up @@ -78,13 +81,25 @@ func (s *Service) Reconcile(ctx context.Context) error {
// Order of precedence (highest -> lowest) is: error that is not an operationNotDoneError (i.e. error creating) -> operationNotDoneError (i.e. creating in progress) -> no error (i.e. created)
var result error
for _, lbSpec := range specs {
if _, err := s.CreateResource(ctx, lbSpec, serviceName); err != nil {
if lb, err := s.CreateResource(ctx, lbSpec, serviceName); err != nil {
if !azure.IsOperationNotDoneError(err) || result == nil {
result = err
}
} else {
loadBalancer, ok := lb.(network.LoadBalancer)
if !ok {
// Return out of loop since this would be an unexepcted fatal error
result = errors.Errorf("created resource %T is not a network.loadBalancer", result)
break
}
if lbSpec.ResourceName() == s.Scope.APIServerLB().Name {
if len(*loadBalancer.FrontendIPConfigurations) > 0 && *(*loadBalancer.FrontendIPConfigurations)[0].PrivateIPAddress != "" {
fmt.Println("LOADBALANCER's PRIVATE IP", (*loadBalancer.FrontendIPConfigurations)[0].PrivateIPAddress)
s.Scope.APIServerLB().FrontendIPs[0].PrivateIPAddress = *(*loadBalancer.FrontendIPConfigurations)[0].PrivateIPAddress
}
}
}
}

s.Scope.UpdatePutStatus(infrav1.LoadBalancersReadyCondition, serviceName, result)
return result
}
Expand Down
11 changes: 8 additions & 3 deletions azure/services/loadbalancers/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type LBSpec struct {
BackendPoolName string
FrontendIPConfigs []infrav1.FrontendIP
APIServerPort int32
IPAllocationMethod string
IdleTimeoutInMinutes *int32
AdditionalTags map[string]string
}
Expand Down Expand Up @@ -163,13 +164,17 @@ func getFrontendIPConfigs(lbSpec LBSpec) ([]network.FrontendIPConfiguration, []n
frontendIDs := make([]network.SubResource, 0)
for _, ipConfig := range lbSpec.FrontendIPConfigs {
var properties network.FrontendIPConfigurationPropertiesFormat
var privateIPAddress string
if lbSpec.IPAllocationMethod == "Static" {
privateIPAddress = ipConfig.PrivateIPAddress
}
if lbSpec.Type == infrav1.Internal {
properties = network.FrontendIPConfigurationPropertiesFormat{
PrivateIPAllocationMethod: network.IPAllocationMethodStatic,
PrivateIPAllocationMethod: network.IPAllocationMethod(lbSpec.IPAllocationMethod),
Subnet: &network.Subnet{
ID: to.StringPtr(azure.SubnetID(lbSpec.SubscriptionID, lbSpec.VNetResourceGroup, lbSpec.VNetName, lbSpec.SubnetName)),
},
PrivateIPAddress: to.StringPtr(ipConfig.PrivateIPAddress),
PrivateIPAddress: to.StringPtr(privateIPAddress),
}
} else {
properties = network.FrontendIPConfigurationPropertiesFormat{
Expand Down Expand Up @@ -225,7 +230,7 @@ func getLoadBalancingRules(lbSpec LBSpec, frontendIDs []network.SubResource) []n
FrontendPort: to.Int32Ptr(lbSpec.APIServerPort),
BackendPort: to.Int32Ptr(lbSpec.APIServerPort),
IdleTimeoutInMinutes: lbSpec.IdleTimeoutInMinutes,
EnableFloatingIP: to.BoolPtr(false),
EnableFloatingIP: to.BoolPtr(true),
LoadDistribution: network.LoadDistributionDefault,
FrontendIPConfiguration: &frontendIPConfig,
BackendAddressPool: &network.SubResource{
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: gcr.io/k8s-staging-cluster-api-azure/cluster-api-azure-controller:latest
- image: gcr.io/spectro-common-dev/cluster-api-azure-controller:dev
name: manager