Commit 188db6f8 authored by Tomer Froumin's avatar Tomer Froumin

Added service annotation to set Azure DNS label for public IP

parent 7c9e614c
...@@ -39,6 +39,9 @@ const ServiceAnnotationLoadBalancerInternal = "service.beta.kubernetes.io/azure- ...@@ -39,6 +39,9 @@ const ServiceAnnotationLoadBalancerInternal = "service.beta.kubernetes.io/azure-
// to specify what subnet it is exposed on // to specify what subnet it is exposed on
const ServiceAnnotationLoadBalancerInternalSubnet = "service.beta.kubernetes.io/azure-load-balancer-internal-subnet" const ServiceAnnotationLoadBalancerInternalSubnet = "service.beta.kubernetes.io/azure-load-balancer-internal-subnet"
// ServiceAnnotationDNSLabelName annotation speficying the DNS label name for the service.
const ServiceAnnotationDNSLabelName = "service.beta.kubernetes.io/azure-dns-label-name"
// GetLoadBalancer returns whether the specified load balancer exists, and // GetLoadBalancer returns whether the specified load balancer exists, and
// if so, what its status is. // if so, what its status is.
func (az *Cloud) GetLoadBalancer(clusterName string, service *v1.Service) (status *v1.LoadBalancerStatus, exists bool, err error) { func (az *Cloud) GetLoadBalancer(clusterName string, service *v1.Service) (status *v1.LoadBalancerStatus, exists bool, err error) {
...@@ -118,6 +121,13 @@ func (az *Cloud) determinePublicIPName(clusterName string, service *v1.Service) ...@@ -118,6 +121,13 @@ func (az *Cloud) determinePublicIPName(clusterName string, service *v1.Service)
return "", fmt.Errorf("user supplied IP Address %s was not found", loadBalancerIP) return "", fmt.Errorf("user supplied IP Address %s was not found", loadBalancerIP)
} }
func getPublicIPLabel(service *v1.Service) string {
if labelName, found := service.Annotations[ServiceAnnotationDNSLabelName]; found {
return labelName
}
return ""
}
// EnsureLoadBalancer creates a new load balancer 'name', or updates the existing one. Returns the status of the balancer // EnsureLoadBalancer creates a new load balancer 'name', or updates the existing one. Returns the status of the balancer
func (az *Cloud) EnsureLoadBalancer(clusterName string, service *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) { func (az *Cloud) EnsureLoadBalancer(clusterName string, service *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) {
isInternal := requiresInternalLoadBalancer(service) isInternal := requiresInternalLoadBalancer(service)
...@@ -221,7 +231,8 @@ func (az *Cloud) EnsureLoadBalancer(clusterName string, service *v1.Service, nod ...@@ -221,7 +231,8 @@ func (az *Cloud) EnsureLoadBalancer(clusterName string, service *v1.Service, nod
if err != nil { if err != nil {
return nil, err return nil, err
} }
pip, err := az.ensurePublicIPExists(serviceName, pipName) domainNameLabel := getPublicIPLabel(service)
pip, err := az.ensurePublicIPExists(serviceName, pipName, domainNameLabel)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -455,7 +466,7 @@ func (az *Cloud) cleanupLoadBalancer(clusterName string, service *v1.Service, is ...@@ -455,7 +466,7 @@ func (az *Cloud) cleanupLoadBalancer(clusterName string, service *v1.Service, is
return nil return nil
} }
func (az *Cloud) ensurePublicIPExists(serviceName, pipName string) (*network.PublicIPAddress, error) { func (az *Cloud) ensurePublicIPExists(serviceName, pipName, domainNameLabel string) (*network.PublicIPAddress, error) {
pip, existsPip, err := az.getPublicIPAddress(pipName) pip, existsPip, err := az.getPublicIPAddress(pipName)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -469,6 +480,11 @@ func (az *Cloud) ensurePublicIPExists(serviceName, pipName string) (*network.Pub ...@@ -469,6 +480,11 @@ func (az *Cloud) ensurePublicIPExists(serviceName, pipName string) (*network.Pub
pip.PublicIPAddressPropertiesFormat = &network.PublicIPAddressPropertiesFormat{ pip.PublicIPAddressPropertiesFormat = &network.PublicIPAddressPropertiesFormat{
PublicIPAllocationMethod: network.Static, PublicIPAllocationMethod: network.Static,
} }
if len(domainNameLabel) > 0 {
pip.PublicIPAddressPropertiesFormat.DNSSettings = &network.PublicIPAddressDNSSettings{
DomainNameLabel: &domainNameLabel,
}
}
pip.Tags = &map[string]*string{"service": &serviceName} pip.Tags = &map[string]*string{"service": &serviceName}
glog.V(3).Infof("ensure(%s): pip(%s) - creating", serviceName, *pip.Name) glog.V(3).Infof("ensure(%s): pip(%s) - creating", serviceName, *pip.Name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment