Skip to content

Commit

Permalink
fix: Handle VS hosts nil (#265)
Browse files Browse the repository at this point in the history
Signed-off-by: nbn01 <nandan_bn@intuit.com>
  • Loading branch information
Nandan B N committed Nov 9, 2022
1 parent 90542ca commit 13daaf0
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions admiral/pkg/clusters/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,49 +418,51 @@ func handleVirtualServiceEvent(
}
}

dependentClusters := r.AdmiralCache.CnameDependentClusterCache.Get(virtualService.Hosts[0]).Copy()
if len(dependentClusters) > 0 {
for _, dependentCluster := range dependentClusters {
rc := r.GetRemoteController(dependentCluster)
if clusterId != dependentCluster {
log.Infof(LogFormat, "Event", "VirtualService", obj.Name, clusterId, "Processing")
if event == common.Delete {
err := rc.VirtualServiceController.IstioClient.NetworkingV1alpha3().VirtualServices(syncNamespace).Delete(ctx, obj.Name, v12.DeleteOptions{})
if err != nil {
if k8sErrors.IsNotFound(err) {
log.Infof(LogFormat, "Delete", "VirtualService", obj.Name, clusterId, "Either VirtualService was already deleted, or it never existed")
if len(virtualService.Hosts) != 0 {
dependentClusters := r.AdmiralCache.CnameDependentClusterCache.Get(virtualService.Hosts[0]).Copy()
if len(dependentClusters) > 0 {
for _, dependentCluster := range dependentClusters {
rc := r.GetRemoteController(dependentCluster)
if clusterId != dependentCluster {
log.Infof(LogFormat, "Event", "VirtualService", obj.Name, clusterId, "Processing")
if event == common.Delete {
err := rc.VirtualServiceController.IstioClient.NetworkingV1alpha3().VirtualServices(syncNamespace).Delete(ctx, obj.Name, v12.DeleteOptions{})
if err != nil {
if k8sErrors.IsNotFound(err) {
log.Infof(LogFormat, "Delete", "VirtualService", obj.Name, clusterId, "Either VirtualService was already deleted, or it never existed")
} else {
log.Errorf(LogErrFormat, "Delete", "VirtualService", obj.Name, clusterId, err)
}
} else {
log.Errorf(LogErrFormat, "Delete", "VirtualService", obj.Name, clusterId, err)
log.Infof(LogFormat, "Delete", "VirtualService", obj.Name, clusterId, "Success")
}
} else {
log.Infof(LogFormat, "Delete", "VirtualService", obj.Name, clusterId, "Success")
}
} else {
exist, _ := rc.VirtualServiceController.IstioClient.NetworkingV1alpha3().VirtualServices(syncNamespace).Get(ctx, obj.Name, v12.GetOptions{})
//change destination host for all http routes <service_name>.<ns>. to same as host on the virtual service
for _, httpRoute := range virtualService.Http {
for _, destination := range httpRoute.Route {
//get at index 0, we do not support wildcards or multiple hosts currently
if strings.HasSuffix(destination.Destination.Host, common.DotLocalDomainSuffix) {
destination.Destination.Host = virtualService.Hosts[0]
exist, _ := rc.VirtualServiceController.IstioClient.NetworkingV1alpha3().VirtualServices(syncNamespace).Get(ctx, obj.Name, v12.GetOptions{})
//change destination host for all http routes <service_name>.<ns>. to same as host on the virtual service
for _, httpRoute := range virtualService.Http {
for _, destination := range httpRoute.Route {
//get at index 0, we do not support wildcards or multiple hosts currently
if strings.HasSuffix(destination.Destination.Host, common.DotLocalDomainSuffix) {
destination.Destination.Host = virtualService.Hosts[0]
}
}
}
}
for _, tlsRoute := range virtualService.Tls {
for _, destination := range tlsRoute.Route {
//get at index 0, we do not support wildcards or multiple hosts currently
if strings.HasSuffix(destination.Destination.Host, common.DotLocalDomainSuffix) {
destination.Destination.Host = virtualService.Hosts[0]
for _, tlsRoute := range virtualService.Tls {
for _, destination := range tlsRoute.Route {
//get at index 0, we do not support wildcards or multiple hosts currently
if strings.HasSuffix(destination.Destination.Host, common.DotLocalDomainSuffix) {
destination.Destination.Host = virtualService.Hosts[0]
}
}
}
addUpdateVirtualService(ctx, obj, exist, syncNamespace, rc)
}
addUpdateVirtualService(ctx, obj, exist, syncNamespace, rc)
}
}
return nil
} else {
log.Infof(LogFormat, "Event", "VirtualService", obj.Name, clusterId, "No dependent clusters found")
}
return nil
} else {
log.Infof(LogFormat, "Event", "VirtualService", obj.Name, clusterId, "No dependent clusters found")
}

// copy the VirtualService `as is` if they are not generated by Admiral (not in CnameDependentClusterCache)
Expand Down

0 comments on commit 13daaf0

Please sign in to comment.