Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AV-223736 support routes with subdomain #259

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ require (
github.com/google/uuid v1.3.1
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.27.10
github.com/openshift/api v3.9.0+incompatible
github.com/openshift/api v0.0.0-20201019163320-c6a5ec25f267
github.com/openshift/client-go v0.0.0-20201020082437-7737f16e53fc
github.com/prometheus/client_golang v1.17.0
github.com/vmware/alb-sdk v0.0.0-20240619053936-3103500da639
github.com/vmware/load-balancer-and-ingress-services-for-kubernetes v0.0.0-20240909104351-9ae7aeee7746
github.com/vmware/load-balancer-and-ingress-services-for-kubernetes v0.0.0-20241128140134-4606ef823783
google.golang.org/protobuf v1.33.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v2 v2.4.0
Expand Down
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,8 @@ github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoT
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/openshift/api v0.0.0-20201019163320-c6a5ec25f267 h1:d6qOoblJz8DjQ44PRT0hYt3qLqJ/Lnvipk1vXr0gpfo=
github.com/openshift/api v0.0.0-20201019163320-c6a5ec25f267/go.mod h1:RDvBcRQMGLa3aNuDuejVBbTEQj/2i14NXdpOLqbNBvM=
github.com/openshift/api v3.9.0+incompatible h1:fJ/KsefYuZAjmrr3+5U9yZIZbTOpVkDDLDLFresAeYs=
github.com/openshift/api v3.9.0+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY=
github.com/openshift/build-machinery-go v0.0.0-20200917070002-f171684f77ab/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
github.com/openshift/client-go v0.0.0-20201020082437-7737f16e53fc h1:aeVqf+NL5rNq1uM2jvIfSQiWodd5OJ5o90ayju+vdeM=
github.com/openshift/client-go v0.0.0-20201020082437-7737f16e53fc/go.mod h1:yZ3u8vgWC19I9gbDMRk8//9JwG/0Sth6v7C+m6R8HXs=
Expand Down Expand Up @@ -462,8 +461,8 @@ github.com/vmware-tanzu/service-apis v0.0.0-20200901171416-461d35e58618 h1:ZLkxM
github.com/vmware-tanzu/service-apis v0.0.0-20200901171416-461d35e58618/go.mod h1:afqpDk9He9v+/qWix0RRotm3RNyni4Lmc1y9geDCPuo=
github.com/vmware/alb-sdk v0.0.0-20240619053936-3103500da639 h1:UaTxFP5LeiSOlLEyHC9kmYuzdZWmvYpPB7jevg+ASNw=
github.com/vmware/alb-sdk v0.0.0-20240619053936-3103500da639/go.mod h1:fuRb4saDY/xy/UMeMvyKYmcplNknEL9ysaqYSw7reNE=
github.com/vmware/load-balancer-and-ingress-services-for-kubernetes v0.0.0-20240909104351-9ae7aeee7746 h1:WjqHHnk/w9PblhJAGzCAnDt+CtmlyOQZw0XO7dSoPek=
github.com/vmware/load-balancer-and-ingress-services-for-kubernetes v0.0.0-20240909104351-9ae7aeee7746/go.mod h1:OYFWfOG6sHCDgYgMafq/Rcm3haP0q+9ZCUh0GGyVhCA=
github.com/vmware/load-balancer-and-ingress-services-for-kubernetes v0.0.0-20241128140134-4606ef823783 h1:fo4QuXqKFz21XmzzopJv6I8pwpws+QyXKjGGrxab4YE=
github.com/vmware/load-balancer-and-ingress-services-for-kubernetes v0.0.0-20241128140134-4606ef823783/go.mod h1:coCKZFNoB2f5GzuS/Ks5Zt8cBC+oBGZryvkzm/wfBxo=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
Expand Down
18 changes: 17 additions & 1 deletion gslb/gslbutils/gdputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ type GlobalFilter struct {
GslbDownResponse *gslbalphav1.DownResponse
// ControlPlaneHmOnly will only enable hm on control plane and would not create data plane HM for GSLB service
ControlPlaneHmOnly *bool
Checksum uint32
// DefaultDomain will be used to generate hostname if openshift route uses subdomain
DefaultDomain *string
Checksum uint32
// Respective filters for the namespaces.
// NSFilterMap map[string]*NSFilter
// GlobalLock is locked before accessing any of the filters.
Expand Down Expand Up @@ -203,6 +205,13 @@ func (gf *GlobalFilter) GetControlPlaneHmOnlyFlag() *bool {
return gf.ControlPlaneHmOnly
}

func (gf *GlobalFilter) GetDefaultDomain() *string {
gf.GlobalLock.RLock()
defer gf.GlobalLock.RUnlock()

return gf.DefaultDomain
}

func (gf *GlobalFilter) GetGslbPoolAlgorithm() *gslbalphav1.PoolAlgorithmSettings {
gf.GlobalLock.RLock()
defer gf.GlobalLock.RUnlock()
Expand Down Expand Up @@ -235,6 +244,7 @@ func (gf *GlobalFilter) GetCopy() *GlobalFilter {
GslbDownResponse: gf.GslbDownResponse,
Checksum: gf.Checksum,
ControlPlaneHmOnly: gf.ControlPlaneHmOnly,
DefaultDomain: gf.DefaultDomain,
}
return &newFilter
}
Expand Down Expand Up @@ -369,6 +379,7 @@ func (gf *GlobalFilter) AddToFilter(gdp *gdpv1alpha2.GlobalDeploymentPolicy) {

gf.ControlPlaneHmOnly = gdp.Spec.ControlPlaneHmOnly

gf.DefaultDomain = gdp.Spec.DefaultDomain
gf.ComputeChecksum()
Logf("ns: %s, object: NSFilter, msg: added/changed the global filter", gdp.ObjectMeta.Namespace)
}
Expand Down Expand Up @@ -439,6 +450,9 @@ func (gf *GlobalFilter) ComputeChecksum() {
if gf.ControlPlaneHmOnly != nil {
cksum += utils.Hash(utils.Stringify(*gf.ControlPlaneHmOnly))
}
if gf.DefaultDomain != nil {
cksum += utils.Hash(*gf.DefaultDomain)
}
cksum += getChecksumForPoolAlgorithm(gf.GslbPoolAlgorithm)
if gf.HealthMonitorTemplate != nil {
cksum += utils.Hash(*gf.HealthMonitorTemplate)
Expand Down Expand Up @@ -692,6 +706,7 @@ func (gf *GlobalFilter) UpdateGlobalFilter(oldGDP, newGDP *gdpv1alpha2.GlobalDep
gf.HealthMonitorTemplate = nf.HealthMonitorTemplate
gf.GslbDownResponse = nf.GslbDownResponse
gf.ControlPlaneHmOnly = nf.ControlPlaneHmOnly
gf.DefaultDomain = nf.DefaultDomain
gf.Checksum = nf.Checksum

clustersToBeSynced := isSyncTypeChanged(newGDP, oldGDP)
Expand Down Expand Up @@ -727,6 +742,7 @@ func GetNewGlobalFilter() *GlobalFilter {
GslbPoolAlgorithm: nil,
GslbDownResponse: nil,
ControlPlaneHmOnly: nil,
DefaultDomain: nil,
}
return gf
}
Expand Down
18 changes: 18 additions & 0 deletions gslb/gslbutils/gslbutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ func SplitMultiClusterNS(name string) (string, string, error) {

func RouteGetIPAddr(route *routev1.Route) (string, bool) {
hostname := route.Spec.Host
if hostname == "" {
hostname = GetHostnameforSubdomain(route.Spec.Subdomain)
}
// Return true if the IP address is present in an route's status field, else return false
routeStatus := route.Status
for _, ingr := range routeStatus.Ingress {
Expand Down Expand Up @@ -217,6 +220,21 @@ func RouteGetIPAddr(route *routev1.Route) (string, bool) {
return "", false
}

func GetHostnameforSubdomain(subdomain string) string {
defaultdomain := GetGlobalFilter().GetDefaultDomain()
if defaultdomain == nil {
return ""
}
if subdomain == "" || *defaultdomain == "" {
return ""
}
if strings.HasPrefix(*defaultdomain, ".") {
return subdomain + *defaultdomain
} else {
return subdomain + "." + *defaultdomain
}
}

type IngressHostIP struct {
Hostname string
IPAddr string
Expand Down
13 changes: 8 additions & 5 deletions gslb/k8sobjects/route_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ func GetRouteMeta(route *routev1.Route, cname string) RouteMeta {
}
var vsUUIDs map[string]string
var controllerUUID, tenant string
hostname := route.Spec.Host
if hostname == "" {
hostname = gslbutils.GetHostnameforSubdomain(route.Spec.Subdomain)
}

// Parse status field
vsUUIDs, controllerUUID, tenant, err = parseVSAndControllerUUIDStatus(route.Status, route.Spec.Host)
vsUUIDs, controllerUUID, tenant, err = parseVSAndControllerUUIDStatus(route.Status, hostname)
if err != nil {
// parse annotations
gslbutils.Logf("cluster: %s, ns: %s, route: %s, msg: parsing Controller annotations", cname, route.Namespace, route.Name)
Expand All @@ -70,16 +74,16 @@ func GetRouteMeta(route *routev1.Route, cname string) RouteMeta {
gslbutils.Logf("cluster: %s, ns: %s, route: %s, msg: skipping route because either VS UUID or controller UUID missing from annotations: %v",
cname, route.Namespace, route.Name, route.Annotations)
}
vsUUID, ok := vsUUIDs[route.Spec.Host]
vsUUID, ok := vsUUIDs[hostname]
if !ok && !syncVIPsOnly {
gslbutils.Logf("cluster: %s, ns: %s, route: %s, msg: hostname %s is missing from VS UUID annotations",
cname, route.Namespace, route.Name, route.Spec.Host)
cname, route.Namespace, route.Name, hostname)
}
ipAddr, _ := gslbutils.RouteGetIPAddr(route)
metaObj := RouteMeta{
Name: route.Name,
Namespace: route.ObjectMeta.Namespace,
Hostname: route.Spec.Host,
Hostname: hostname,
IPAddr: ipAddr,
Cluster: cname,
TLS: false,
Expand All @@ -92,7 +96,6 @@ func GetRouteMeta(route *routev1.Route, cname string) RouteMeta {
for key, value := range routeLabels {
metaObj.Labels[key] = value
}

if route.Spec.TLS != nil {
// for passthrough routes, only set the port and protocol
if route.Spec.TLS.Termination == gslbutils.PassthroughRoute {
Expand Down
3 changes: 3 additions & 0 deletions gslb/test/ingestion/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func getTestGDPObject(appLabelReq, nsLabelReq bool) *gdpalphav2.GlobalDeployment
ObjectMeta: gdpMeta,
Spec: gdpSpec,
}
var defaultDomain string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use defaultDomain := TestDomain1.

defaultDomain = TestDomain1
gdp.Spec.DefaultDomain = &defaultDomain
return &gdp
}

Expand Down
68 changes: 68 additions & 0 deletions gslb/test/ingestion/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ func ocAddRoute(t *testing.T, oc *oshiftfake.Clientset, name, ns, svc, cname, ho
return routeObj
}

func ocAddRouteWithSubDomain(t *testing.T, oc *oshiftfake.Clientset, name, ns, svc, cname, host, ip string) *routev1.Route {
routeObj := buildRouteObj(name, ns, svc, cname, host, ip, true)
routeObj.Spec.Host = ""
routeObj.Spec.Subdomain = host
routeObj.Status.Ingress[0].Host = host + "." + TestDomain1
_, err := oc.RouteV1().Routes(ns).Create(context.TODO(), routeObj, metav1.CreateOptions{})
if err != nil {
t.Fatalf("error in creating route: %v", err)
}
return routeObj
}

func ocAddRouteWithoutStatus(t *testing.T, oc *oshiftfake.Clientset, name, ns, svc, cname, host string) *routev1.Route {
routeObj := buildRouteObj(name, ns, svc, cname, host, "", false)
_, err := oc.RouteV1().Routes(ns).Create(context.TODO(), routeObj, metav1.CreateOptions{})
Expand Down Expand Up @@ -362,3 +374,59 @@ func TestStatusChangeIPAddrRoute(t *testing.T) {
verifyInRouteStore(g, acceptedRouteStore, false, routeName, ns, cname, host, newIPAddr)
DeleteTestGDPObj(gdp)
}

func TestBasicRoutewithSubdomainCD(t *testing.T) {
g := gomega.NewGomegaWithT(t)
testPrefix := "rcd"
routeName := testPrefix + "def-route"
ns := "default"
host := testPrefix
ipAddr := "10.10.20.20"
cname := "cluster1"
hostname := host + "." + TestDomain1
gdp := addGDPAndGSLBForIngress(t)
t.Log("adding and testing route")
ocAddRouteWithSubDomain(t, fooOshiftClient, routeName, ns, TestSvc, cname, host, ipAddr)
buildRouteKeyAndVerify(t, false, "ADD", cname, ns, routeName, tenant)
// verify the presence of the route in the accepted store
verifyInRouteStore(g, acceptedRouteStore, true, routeName, ns, cname, hostname, ipAddr)

// delete and verify
ocDeleteRoute(t, fooOshiftClient, routeName, ns)
buildRouteKeyAndVerify(t, false, "DELETE", cname, ns, routeName, tenant)

DeleteTestGDPObj(gdp)
}

func TestBasicRouteWithsubdomainCUD(t *testing.T) {
g := gomega.NewGomegaWithT(t)
testPrefix := "rcud-"
routeName := testPrefix + "def-route"
ns := "default"
host := testPrefix
ipAddr := "10.10.20.20"
cname := "cluster1"
hostname := host + "." + TestDomain1
gdp := addGDPAndGSLBForIngress(t)

t.Log("adding and testing route")
route := ocAddRouteWithSubDomain(t, fooOshiftClient, routeName, ns, TestSvc, cname, host, ipAddr)
buildRouteKeyAndVerify(t, false, "ADD", cname, ns, routeName, tenant)
// verify the presence of the route in the accepted store
verifyInRouteStore(g, acceptedRouteStore, true, routeName, ns, cname, hostname, ipAddr)

newHost := testPrefix + TestDomain2
route.Spec.Host = newHost
route.Status.Ingress[0].Host = newHost

t.Log("updating route")
ocUpdateRoute(t, fooOshiftClient, ns, cname, route)
buildRouteKeyAndVerify(t, false, "UPDATE", cname, ns, routeName, tenant)
verifyInRouteStore(g, acceptedRouteStore, true, routeName, ns, cname, newHost, ipAddr)

// delete and verify
ocDeleteRoute(t, fooOshiftClient, routeName, ns)
buildRouteKeyAndVerify(t, false, "DELETE", cname, ns, routeName, tenant)

DeleteTestGDPObj(gdp)
}
3 changes: 3 additions & 0 deletions helm/amko/crds/gdp_def.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ spec:
type: string
pkiProfileRef:
type: string
defaultDomain:
description: "It will be used to generate hostname for openshift route if openshift route uses subdomain instead of host field"
type: string
poolAlgorithmSettings:
description: "Algorithm settings to be specified for Gslb Service pool"
type: object
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/amko/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type GDPSpec struct {
PoolAlgorithmSettings *gslbalphav1.PoolAlgorithmSettings `json:"poolAlgorithmSettings,omitempty"`
DownResponse *gslbalphav1.DownResponse `json:"downResponse,omitempty"`
ControlPlaneHmOnly *bool `json:"controlPlaneHmOnly,omitempty"`
DefaultDomain *string `json:"defaultDomain,omitempty"`
}

// ClusterProperty specifies all the properties required for a Cluster. Cluster is the cluster
Expand Down
14 changes: 2 additions & 12 deletions vendor/github.com/openshift/api/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading