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

fix: create tcp route failure #2002

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
37 changes: 21 additions & 16 deletions api/controller/apigateway/api_gateway_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,28 +345,20 @@ func (g Struct) CreateTCPRoute(w http.ResponseWriter, r *http.Request) {
Spec: spec,
}, v1.CreateOptions{})
if err != nil {
logrus.Errorf("create tcp rule func, create svc failure: %s", err.Error())
httputil.ReturnBcodeError(r, w, bcode.ErrPortExists)
return
if errors.IsAlreadyExists(err) {
logrus.Infof("Service %s already exists, skipping creation", name)
} else {
logrus.Errorf("create tcp rule func, create svc failure: %s", err.Error())
httputil.ReturnBcodeError(r, w, bcode.ErrPortExists)
return
}
}
// 如果不是第三方组件,需要绑定 service_alias,第三方组件会从ep中自动读取
if r.URL.Query().Get("service_type") != "third_party" {
spec.Selector = map[string]string{
"service_alias": serviceName,
}
get, err := k.Services(tenant.Namespace).Get(r.Context(), name, v1.GetOptions{})
if err != nil {
logrus.Errorf("get route error %s", err.Error())
httputil.ReturnBcodeError(r, w, bcode.ErrPortExists)
return
}
get.Spec = spec
_, err = k.Services(tenant.Namespace).Update(r.Context(), get, v1.UpdateOptions{})
if err != nil {
logrus.Errorf("update route error %s", err.Error())
httputil.ReturnBcodeError(r, w, bcode.ErrPortExists)
return
}

} else {
// 找到这个第三方组件,去更新状态
list, err := k8s.Default().RainbondClient.RainbondV1alpha1().ThirdComponents(tenant.Namespace).List(r.Context(), v1.ListOptions{
Expand All @@ -389,6 +381,19 @@ func (g Struct) CreateTCPRoute(w http.ResponseWriter, r *http.Request) {
}
}
}
get, err := k.Services(tenant.Namespace).Get(r.Context(), name, v1.GetOptions{})
if err != nil {
logrus.Errorf("get route error %s", err.Error())
httputil.ReturnBcodeError(r, w, bcode.ErrPortExists)
return
}
get.Spec = spec
_, err = k.Services(tenant.Namespace).Update(r.Context(), get, v1.UpdateOptions{})
if err != nil {
logrus.Errorf("update route error %s", err.Error())
httputil.ReturnBcodeError(r, w, bcode.ErrPortExists)
return
}
tcpRule := &dbmodel.TCPRule{
UUID: r.URL.Query().Get("service_id"),
ServiceID: r.URL.Query().Get("service_id"),
Expand Down
Loading