Skip to content

Commit

Permalink
Update public IP creation/reconcile (#124)
Browse files Browse the repository at this point in the history
* deployer: Improve FQDN retrieval in GetIP/GetKubeConfig

Signed-off-by: Stephen Augustus <[email protected]>

* network: Update GetPublicIPName usage

Signed-off-by: Stephen Augustus <[email protected]>

* network: Update public IP reconcile checks

Signed-off-by: Stephen Augustus <[email protected]>
  • Loading branch information
justaugustus authored and k8s-ci-robot committed Mar 7, 2019
1 parent 3fa0d0d commit a88f7cc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/cloud/azure/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
}
}

pip, err := networkSvc.CreateOrUpdatePublicIPAddress(scope.ClusterConfig.ResourceGroup, scope.Machine.Name, networkSvc.GetDefaultPublicIPZone())
pip, err := networkSvc.CreateOrUpdatePublicIPAddress(scope.ClusterConfig.ResourceGroup, networkSvc.GetPublicIPName(machine), networkSvc.GetDefaultPublicIPZone())
if err != nil {
klog.Errorf("Unable to create public IP: %+v", err)
return &controllerError.RequeueAfterError{
Expand Down
7 changes: 4 additions & 3 deletions pkg/cloud/azure/services/network/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *Service) ReconcileNICBackendPool(networkInterfaceName, backendPoolID st
if len(ipConfigs) > 0 {
ipConfig := ipConfigs[0]

if ipConfig.LoadBalancerBackendAddressPools != nil {
if ipConfig.LoadBalancerBackendAddressPools != (*[]network.BackendAddressPool)(nil) {
backendPool := (*ipConfig.LoadBalancerBackendAddressPools)[0]
if *backendPool.ID != backendPoolID {
klog.V(2).Infof("Could not attach NIC to load balancer backend pool (%q). NIC is already attached to %q.", backendPoolID, *backendPool.ID)
Expand Down Expand Up @@ -123,9 +123,8 @@ func (s *Service) ReconcileNICPublicIP(networkInterfaceName string, publicIP net
ipConfigs := (*nic.IPConfigurations)
if len(ipConfigs) > 0 {
ipConfig := ipConfigs[0]
pip := ipConfig.PublicIPAddress

if pip != nil {
if ipConfig.PublicIPAddress != (*network.PublicIPAddress)(nil) {
pipID := *ipConfig.PublicIPAddress.ID
if pipID != *publicIP.ID {
klog.V(2).Infof("Could not associate NIC to public IP (%q). NIC is already associated with %q.", *publicIP.ID, pipID)
Expand Down Expand Up @@ -173,3 +172,5 @@ func (s *Service) getDefaultVMNetworkInterfaceConfig() network.Interface {
func (s *Service) GetNetworkInterfaceName(machine *clusterv1.Machine) string {
return fmt.Sprintf("%s-nic", machine.Name)
}

// TODO: Add method for retrieving a network interface's primary IP config
23 changes: 21 additions & 2 deletions pkg/cloud/azure/services/network/publicipaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,31 @@ import (

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network"
"github.com/Azure/go-autorest/autorest/to"
"github.com/pkg/errors"
"k8s.io/klog"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)

// CreateOrUpdatePublicIPAddress retrieves the Public IP address resource.
// GetPublicIPAddress retrieves the Public IP address resource.
func (s *Service) GetPublicIPAddress(resourceGroup, IPName string) (network.PublicIPAddress, error) {
klog.V(2).Info("Attempting to get public IP")
pip, err := s.scope.PublicIPAddresses.Get(
s.scope.Context,
resourceGroup,
IPName,
"",
)

if err != nil {
return pip, errors.Wrapf(err, "Failed to get public IP %q", IPName)
}

return pip, nil
}

// CreateOrUpdatePublicIPAddress updates a Public IP address resource or creates one, if it doesn't exist.
func (s *Service) CreateOrUpdatePublicIPAddress(resourceGroup, IPName, zone string) (pip network.PublicIPAddress, err error) {
klog.V(2).Info("Attempting to create or update public IP")
publicIP := network.PublicIPAddress{
Name: to.StringPtr(IPName),
Location: to.StringPtr(s.scope.Location()),
Expand Down Expand Up @@ -78,7 +97,7 @@ func (s *Service) DeletePublicIPAddress(resourceGroup string, IPName string) (er

// GetPublicIPName returns the public IP resource name of the machine.
func (s *Service) GetPublicIPName(machine *clusterv1.Machine) string {
return fmt.Sprintf("%s-pip", machine.Name)
return fmt.Sprintf("%s", machine.Name)
}

// GetDefaultPublicIPZone returns the public IP resource name of the machine.
Expand Down
19 changes: 8 additions & 11 deletions pkg/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ func (d *Deployer) GetIP(cluster *clusterv1.Cluster, machine *clusterv1.Machine)

networkSvc := network.NewService(scope)

pip, err := networkSvc.CreateOrUpdatePublicIPAddress(scope.ClusterConfig.ResourceGroup, networkSvc.GetPublicIPName(machine), "")
// TODO: Consider moving FQDN retrieval into its' own method.
pip, err := networkSvc.GetPublicIPAddress(scope.ClusterConfig.ResourceGroup, networkSvc.GetPublicIPName(machine))
if err != nil {
return "", err
}
return *pip.IPAddress, nil

return *pip.DNSSettings.Fqdn, nil
}

// GetKubeConfig returns the kubeconfig after the bootstrap process is complete.
func (d *Deployer) GetKubeConfig(cluster *clusterv1.Cluster, machine *clusterv1.Machine) (string, error) {
func (d *Deployer) GetKubeConfig(cluster *clusterv1.Cluster, _ *clusterv1.Machine) (string, error) {

// Load provider config.
config, err := providerv1.ClusterConfigFromProviderSpec(cluster.Spec.ProviderSpec)
Expand All @@ -88,14 +90,9 @@ func (d *Deployer) GetKubeConfig(cluster *clusterv1.Cluster, machine *clusterv1.
return "", errors.New("key not found in status")
}

// TODO: Unwrap this once load balancer is implemented
dnsName := "null"

if machine != nil {
dnsName, err = d.GetIP(cluster, nil)
if err != nil {
return "", errors.Wrap(err, "failed to get DNS address")
}
dnsName, err := d.GetIP(cluster, nil)
if err != nil {
return "", errors.Wrap(err, "failed to get DNS address")
}

server := fmt.Sprintf("https://%s:6443", dnsName)
Expand Down

0 comments on commit a88f7cc

Please sign in to comment.