From 9921ee97723f0f206b6af0e030264267e0cfb464 Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Fri, 18 Jan 2019 13:14:44 +1300 Subject: [PATCH] octavia-ingress-controller: Add ingress information to openstack resource description This patch adds the ingress information, e.g. namespace, name and cluster name into openstack resource description, in order to identify the corresponding openstack resources created for the ingress and make it easy to do clean up. --- pkg/ingress/controller/controller.go | 7 ++++--- pkg/ingress/controller/openstack/neutron.go | 3 ++- pkg/ingress/controller/openstack/octavia.go | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/ingress/controller/controller.go b/pkg/ingress/controller/controller.go index 6f4a0d927d..49757d080c 100644 --- a/pkg/ingress/controller/controller.go +++ b/pkg/ingress/controller/controller.go @@ -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" @@ -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 } @@ -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 } } @@ -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 } diff --git a/pkg/ingress/controller/openstack/neutron.go b/pkg/ingress/controller/openstack/neutron.go index 1222e6297b..bf7d5f99e3 100644 --- a/pkg/ingress/controller/openstack/neutron.go +++ b/pkg/ingress/controller/openstack/neutron.go @@ -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 { @@ -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 { diff --git a/pkg/ingress/controller/openstack/octavia.go b/pkg/ingress/controller/openstack/octavia.go index b907f2260c..e0d96e068e 100644 --- a/pkg/ingress/controller/openstack/octavia.go +++ b/pkg/ingress/controller/openstack/octavia.go @@ -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 { @@ -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", }