Skip to content

Commit

Permalink
AV-220286 set tenant from gslbconfig if namespacetenant is empty but …
Browse files Browse the repository at this point in the history
…k8s object contains tenant annotation
  • Loading branch information
arihantg committed Nov 3, 2024
1 parent 5e90fc2 commit 97b5174
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 55 deletions.
9 changes: 9 additions & 0 deletions gslb/gslbutils/gslbutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,15 @@ func GetTenantInNamespaceAnnotation(namespace, cname string) string {
return tenant
}

func CheckTenant(namespace, cname, tenant string) bool {
namespaceTenant := GetTenantInNamespaceAnnotation(namespace, cname)
if namespaceTenant != "" && tenant != namespaceTenant {
Logf("cluster: %s, nstenant: %s, tenant: %s, msg: %s\n", cname, namespaceTenant, tenant, "rejected object because object tenant is not same as namespace")
return false
}
return true
}

var allClusterContexts []string

func AddClusterContext(cc string) {
Expand Down
174 changes: 121 additions & 53 deletions gslb/ingestion/event_handlers.go

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions gslb/ingestion/fullsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func fetchAndApplyAllIngresses(c *GSLBMemberController, nsList *corev1.Namespace
}
for _, ing := range ingList {
ihms := k8sobjects.GetIngressHostMeta(ing, c.GetName())
filterAndAddIngressMeta(ihms, c, acceptedIngStore, rejectedIngStore, 0, true)
namespaceTenant := gslbutils.GetTenantInNamespaceAnnotation(ing.Namespace, c.GetName())
filterAndAddIngressMeta(ihms, c, acceptedIngStore, rejectedIngStore, 0, true, namespaceTenant)
}
}

Expand All @@ -81,6 +82,9 @@ func fetchAndApplyAllServices(c *GSLBMemberController, nsList *corev1.NamespaceL
c.GetName(), namespace.Name, svc.Name)
continue
}
if !gslbutils.CheckTenant(svc.Namespace, c.GetName(), svcMeta.Tenant) {
continue
}
if !filter.ApplyFilter(filter.FilterArgs{
Obj: svcMeta,
Cluster: c.GetName(),
Expand Down Expand Up @@ -113,6 +117,9 @@ func fetchAndApplyAllRoutes(c *GSLBMemberController, nsList *corev1.NamespaceLis
routeMeta.Name, "rejected ADD route because IP address/hostname not found in status field")
continue
}
if !gslbutils.CheckTenant(route.Namespace, c.GetName(), routeMeta.Tenant) {
continue
}
if !filter.ApplyFilter(filter.FilterArgs{
Cluster: c.name,
Obj: routeMeta,
Expand Down Expand Up @@ -146,7 +153,8 @@ func fetchAndApplyAllMultiClusterIngresses(c *GSLBMemberController, nsList *core
}
for _, mci := range mciList {
ihms := k8sobjects.GetHostMetaForMultiClusterIngress(mci, c.GetName())
filterAndAddMultiClusterIngressMeta(ihms, c, acceptedStore, rejectedStore, 0, true)
namespaceTenant := gslbutils.GetTenantInNamespaceAnnotation(mci.Namespace, c.name)
filterAndAddMultiClusterIngressMeta(ihms, c, acceptedStore, rejectedStore, 0, true, namespaceTenant)
}
}

Expand Down
7 changes: 7 additions & 0 deletions gslb/k8sobjects/ingress_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ func GetIngressHostMeta(ingress *networkingv1.Ingress, cname string) []IngressHo
var controllerUUID, tenant string

vsUUIDs, controllerUUID, tenant, err = parseVSAndControllerAnnotations(ingress.Annotations)
namespaceTenant := gslbutils.GetTenantInNamespaceAnnotation(ingress.Namespace, cname)

if namespaceTenant == "" {
tenant = gslbutils.GetTenant()
gslbutils.Debugf("cluster: %s, ns: %s, ingress: %s, tenant:%s, namespaceTenant %s ",
cname, ingress.Namespace, ingress.Name, tenant, namespaceTenant)
}
if err != nil && !syncVIPsOnly {
// Note that the ingress key will still be published to graph layer, but the key
// won't be processed, this is just to maintain the ingress information as part
Expand Down
4 changes: 4 additions & 0 deletions gslb/k8sobjects/multicluster_ingress_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func GetHostMetaForMultiClusterIngress(mci *akov1alpha1.MultiClusterIngress, cna
var controllerUUID, tenant string

vsUUIDs, controllerUUID, tenant, err = parseVSAndControllerAnnotations(mci.ObjectMeta.Annotations)
namespaceTenant := gslbutils.GetTenantInNamespaceAnnotation(mci.Namespace, cname)
if namespaceTenant == "" {
tenant = gslbutils.GetTenant()
}
if err != nil && !syncVIPsOnly {
// Note that the ingress key will still be published to graph layer, but the key
// won't be processed, this is just to maintain the ingress information as part
Expand Down
6 changes: 6 additions & 0 deletions gslb/k8sobjects/route_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func GetRouteMeta(route *routev1.Route, cname string) RouteMeta {
gslbutils.Logf("cluster: %s, ns: %s, route: %s, msg: parsing Controller annotations", cname, route.Namespace, route.Name)
vsUUIDs, controllerUUID, tenant, err = parseVSAndControllerAnnotations(route.Annotations)
}
namespaceTenant := gslbutils.GetTenantInNamespaceAnnotation(route.Namespace, cname)
if namespaceTenant == "" {
tenant = gslbutils.GetTenant()
gslbutils.Debugf("cluster: %s, ns: %s, ingress: %s, tenant:%s, namespaceTenant %s ",
cname, route.Namespace, route.Name, tenant, namespaceTenant)
}
if err != nil && !syncVIPsOnly {
gslbutils.Logf("cluster: %s, ns: %s, route: %s, msg: skipping route because of error: %v",
cname, route.Namespace, route.Name, err)
Expand Down
4 changes: 4 additions & 0 deletions gslb/k8sobjects/service_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func GetSvcMeta(svc *corev1.Service, cname string) (SvcMeta, bool) {
cname, svc.Namespace, svc.Name, err)
}
vsUUIDs, controllerUUID, tenant, err := parseVSAndControllerAnnotations(svc.Annotations)
namespaceTenant := gslbutils.GetTenantInNamespaceAnnotation(svc.Namespace, cname)
if namespaceTenant == "" {
tenant = gslbutils.GetTenant()
}
if err != nil && !syncVIPsOnly {
gslbutils.Logf("cluster: %s, ns: %s, service: %s, msg: skipping service because of error in parsing VS and Controller annotations: %v",
cname, svc.Namespace, svc.Name, err)
Expand Down

0 comments on commit 97b5174

Please sign in to comment.