Skip to content

Commit

Permalink
fix failed to delete route due to nil zoneInfo make panic (#6436)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey authored Sep 12, 2024
1 parent af95523 commit 4623611
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,9 @@ func (impl GatewayApiPolicyServiceImpl) SetPackageDefaultPolicyConfig(category,
if err != nil {
return "", err
}
zones = append(zones, *zone)
if zone != nil {
zones = append(zones, *zone)
}
}
}
policyEngine, err := apipolicy.GetPolicyEngine(category)
Expand Down
36 changes: 21 additions & 15 deletions internal/tools/orchestrator/hepa/services/endpoint_api/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ func (impl GatewayOpenapiServiceImpl) UpdatePackage(orgId, id string, dto *gw.Pa
return
}
//老类型兼容
if z.Type == db.ZONE_TYPE_PACKAGE {
if z != nil && z.Type == db.ZONE_TYPE_PACKAGE {
_, err = (*impl.zoneBiz).UpdateZoneRoute(dao.ZoneId, zone.ZoneRoute{
zone.RouteConfig{
Hosts: domains,
Expand Down Expand Up @@ -2116,9 +2116,11 @@ func (impl GatewayOpenapiServiceImpl) TouchPackageApiZone(info endpoint_api.Pack
if err != nil {
return "", err
}
externalSvc, err = impl.createOrUpdateService(k8sAdapter, info, *z)
if err != nil {
return "", err
if z != nil {
externalSvc, err = impl.createOrUpdateService(k8sAdapter, info, *z)
if err != nil {
return "", err
}
}
}
}
Expand All @@ -2133,9 +2135,11 @@ func (impl GatewayOpenapiServiceImpl) TouchPackageApiZone(info endpoint_api.Pack
if err != nil {
return "", err
}
err = (*impl.policyBiz).RefreshZoneIngress(*z, *az, runtimeService.ProjectNamespace, useKong)
if err != nil {
return "", err
if z != nil {
err = (*impl.policyBiz).RefreshZoneIngress(*z, *az, runtimeService.ProjectNamespace, useKong)
if err != nil {
return "", err
}
}
}
return info.ZoneId, nil
Expand Down Expand Up @@ -2900,14 +2904,16 @@ func (impl GatewayOpenapiServiceImpl) deleteMSEApi(dao *orm.GatewayPackageApi, p
if err != nil {
return err
}
var k8sAdapter k8s.K8SAdapter
k8sAdapter, err = k8s.NewAdapter(pack.DiceClusterName)
if err != nil {
return err
}
err = k8sAdapter.DeleteService(ingressNamespace, strings.ToLower(zone.Name))
if err != nil {
return err
if zone != nil {
var k8sAdapter k8s.K8SAdapter
k8sAdapter, err = k8s.NewAdapter(pack.DiceClusterName)
if err != nil {
return err
}
err = k8sAdapter.DeleteService(ingressNamespace, strings.ToLower(zone.Name))
if err != nil {
return err
}
}
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (impl GatewayOpenapiRuleServiceImpl) setPackageApiKongPolicies(basePriority
if err != nil {
return false, err
}
if len(zoneInfo.KongPolicies) > 0 {
if zoneInfo != nil && len(zoneInfo.KongPolicies) > 0 {
// clear
err = (*impl.zoneBiz).SetZoneKongPoliciesWithoutDomainPolicy(packageApi.ZoneId, nil, helper)
if err != nil {
Expand Down Expand Up @@ -812,11 +812,13 @@ func (impl GatewayOpenapiRuleServiceImpl) pluginReq(gatewayProvider string, dto
}

if gatewayProvider == mseCommon.MseProviderName && api.ZoneId != "" {
zone, err := (*impl.zoneBiz).GetZone(api.ZoneId)
z, err := (*impl.zoneBiz).GetZone(api.ZoneId)
if err != nil {
return nil, err
}
reqDto.ZoneName = strings.ToLower(zone.Name)
if z != nil {
reqDto.ZoneName = strings.ToLower(z.Name)
}
}
}
return reqDto, nil
Expand Down

0 comments on commit 4623611

Please sign in to comment.