Skip to content

Commit

Permalink
Merge pull request kubernetes#442 from lingxiankong/mark-ingress-reso…
Browse files Browse the repository at this point in the history
…urces

octavia-ingress-controller: Add ingress information to openstack resources description
  • Loading branch information
k8s-ci-robot authored Jan 19, 2019
2 parents 5207742 + 0e1519a commit 3aa3006
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pkg/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

log "github.com/sirupsen/logrus"

apiv1 "k8s.io/api/core/v1"
extv1beta1 "k8s.io/api/extensions/v1beta1"
apimetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -467,7 +468,7 @@ func (c *Controller) ensureIngress(ing *extv1beta1.Ingress) error {
key := fmt.Sprintf("%s/%s", ing.Namespace, ing.Name)
name := getResourceName(ing.ObjectMeta.Namespace, ing.ObjectMeta.Name, c.config.ClusterName)

lb, err := c.osClient.EnsureLoadBalancer(name, c.config.Octavia.SubnetID)
lb, err := c.osClient.EnsureLoadBalancer(name, c.config.Octavia.SubnetID, ing.ObjectMeta.Namespace, ing.ObjectMeta.Name, c.config.ClusterName)
if err != nil {
return err
}
Expand Down Expand Up @@ -559,7 +560,7 @@ func (c *Controller) ensureIngress(ing *extv1beta1.Ingress) error {
address := lb.VipAddress
if c.config.Octavia.FloatingIPNetwork != "" {
// Allocate floating ip for loadbalancer vip.
if address, err = c.osClient.EnsureFloatingIP(lb.VipPortID, c.config.Octavia.FloatingIPNetwork); err != nil {
if address, err = c.osClient.EnsureFloatingIP(lb.VipPortID, c.config.Octavia.FloatingIPNetwork, ing.ObjectMeta.Namespace, ing.ObjectMeta.Name, c.config.ClusterName); err != nil {
return err
}
}
Expand All @@ -572,7 +573,7 @@ func (c *Controller) ensureIngress(ing *extv1beta1.Ingress) error {
c.recorder.Event(ing, apiv1.EventTypeNormal, "Updated", fmt.Sprintf("Successfully associated IP address %s to ingress %s", address, key))

// Add ingress resource version to the load balancer description
newDes := fmt.Sprintf("Created by Kubernetes ingress %s, version: %s", newIng.Name, newIng.ResourceVersion)
newDes := fmt.Sprintf("Kubernetes ingress %s in namespace %s from cluster %s, version: %s", newIng.Name, newIng.Namespace, c.config.ClusterName, newIng.ResourceVersion)
if err = c.osClient.UpdateLoadBalancerDescription(lb.ID, newDes); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/ingress/controller/openstack/neutron.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (os *OpenStack) getFloatingIPByPortID(portID string) (*floatingips.Floating
}

// EnsureFloatingIP makes sure a floating IP is allocated for the port
func (os *OpenStack) EnsureFloatingIP(portID string, floatingIPNetwork string) (string, error) {
func (os *OpenStack) EnsureFloatingIP(portID string, floatingIPNetwork string, ingName string, ingNamespace string, clusterName string) (string, error) {
fip, err := os.getFloatingIPByPortID(portID)
if err != nil {
if err != ErrNotFound {
Expand All @@ -69,6 +69,7 @@ func (os *OpenStack) EnsureFloatingIP(portID string, floatingIPNetwork string) (
floatIPOpts := floatingips.CreateOpts{
FloatingNetworkID: floatingIPNetwork,
PortID: portID,
Description: fmt.Sprintf("Floating IP for Kubernetes ingress %s in namespace %s from cluster %s", ingName, ingNamespace, clusterName),
}
fip, err = floatingips.Create(os.neutron, floatIPOpts).Extract()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ingress/controller/openstack/octavia.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (os *OpenStack) DeleteLoadbalancer(lbID string) error {
}

// EnsureLoadBalancer creates a loadbalancer in octavia if it does not exist, wait for the loadbalancer to be ACTIVE.
func (os *OpenStack) EnsureLoadBalancer(name string, subnetID string) (*loadbalancers.LoadBalancer, error) {
func (os *OpenStack) EnsureLoadBalancer(name string, subnetID string, ingNamespace string, ingName string, clusterName string) (*loadbalancers.LoadBalancer, error) {
loadbalancer, err := os.GetLoadbalancerByName(name)
if err != nil {
if err != ErrNotFound {
Expand All @@ -313,7 +313,7 @@ func (os *OpenStack) EnsureLoadBalancer(name string, subnetID string) (*loadbala

createOpts := loadbalancers.CreateOpts{
Name: name,
Description: "Created by Kubernetes",
Description: fmt.Sprintf("Kubernetes ingress %s in namespace %s from cluster %s", ingName, ingNamespace, clusterName),
VipSubnetID: subnetID,
Provider: "octavia",
}
Expand Down

0 comments on commit 3aa3006

Please sign in to comment.