mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-05-06 13:42:10 +08:00
fix: create redirect lb listener fail (#24726)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -160,6 +160,11 @@ var LB_LISTENER_TYPES = []string{
|
||||
LB_LISTENER_TYPE_HTTPS,
|
||||
}
|
||||
|
||||
var LB_APP_LISTENER_TYPES = []string{
|
||||
LB_LISTENER_TYPE_HTTP,
|
||||
LB_LISTENER_TYPE_HTTPS,
|
||||
}
|
||||
|
||||
// aws_network_lb_listener
|
||||
var AWS_NETWORK_LB_LISTENER_TYPES = choices.NewChoices(
|
||||
LB_LISTENER_TYPE_TCP,
|
||||
|
||||
@@ -181,6 +181,10 @@ type LoadbalancerListenerCreateInput struct {
|
||||
AclType string `json:"acl_type"`
|
||||
}
|
||||
|
||||
func (input LoadbalancerListenerCreateInput) IsRedirect() bool {
|
||||
return len(input.Redirect) > 0 && input.Redirect != LB_REDIRECT_OFF
|
||||
}
|
||||
|
||||
func (self *LoadbalancerListenerCreateInput) Validate() error {
|
||||
if len(self.Status) == 0 {
|
||||
self.Status = LB_STATUS_ENABLED
|
||||
@@ -191,7 +195,13 @@ func (self *LoadbalancerListenerCreateInput) Validate() error {
|
||||
if !utils.IsInStringArray(self.SendProxy, LB_SENDPROXY_CHOICES) {
|
||||
return httperrors.NewInputParameterError("invalid send_proxy %s", self.SendProxy)
|
||||
}
|
||||
if !utils.IsInStringArray(self.Scheduler, LB_SCHEDULER_TYPES) {
|
||||
if len(self.Redirect) == 0 {
|
||||
self.Redirect = LB_REDIRECT_OFF
|
||||
}
|
||||
if !utils.IsInStringArray(self.Redirect, []string{LB_REDIRECT_OFF, LB_REDIRECT_RAW}) {
|
||||
return httperrors.NewInputParameterError("invalid redirect %s", self.Redirect)
|
||||
}
|
||||
if !self.IsRedirect() && !utils.IsInStringArray(self.Scheduler, LB_SCHEDULER_TYPES) {
|
||||
return httperrors.NewInputParameterError("invalid scheduler %s", self.Scheduler)
|
||||
}
|
||||
if len(self.StickySession) == 0 {
|
||||
@@ -223,6 +233,9 @@ func (self *LoadbalancerListenerCreateInput) Validate() error {
|
||||
if !utils.IsInStringArray(self.ListenerType, LB_LISTENER_TYPES) {
|
||||
return httperrors.NewInputParameterError("invalid listener_type %s", self.ListenerType)
|
||||
}
|
||||
if self.IsRedirect() && !utils.IsInStringArray(self.ListenerType, LB_APP_LISTENER_TYPES) {
|
||||
return httperrors.NewInputParameterError("redirect is only supported for http/https listeners")
|
||||
}
|
||||
if self.ListenerPort < 1 || self.ListenerPort > 65535 {
|
||||
return httperrors.NewOutOfRangeError("listener_port out of range 1-65535")
|
||||
}
|
||||
@@ -272,12 +285,7 @@ func (self *LoadbalancerListenerCreateInput) Validate() error {
|
||||
self.HealthCheckInterval = 30
|
||||
}
|
||||
}
|
||||
if len(self.Redirect) == 0 {
|
||||
self.Redirect = LB_REDIRECT_OFF
|
||||
}
|
||||
if !utils.IsInStringArray(self.Redirect, []string{LB_REDIRECT_OFF, LB_REDIRECT_RAW}) {
|
||||
return httperrors.NewInputParameterError("invalid redirect %s", self.Redirect)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -359,14 +359,6 @@ func (man *SLoadbalancerListenerManager) ValidateCreateData(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
lb := lbObj.(*SLoadbalancer)
|
||||
lbbgObj, err := validators.ValidateModel(ctx, userCred, LoadbalancerBackendGroupManager, &input.BackendGroupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lbbg := lbbgObj.(*SLoadbalancerBackendGroup)
|
||||
if lbbg.LoadbalancerId != lb.Id {
|
||||
return nil, httperrors.NewConflictError("backendgroup_id not same with listener's loadbalancer")
|
||||
}
|
||||
region, err := lb.GetRegion()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetRegion")
|
||||
@@ -378,6 +370,19 @@ func (man *SLoadbalancerListenerManager) ValidateCreateData(ctx context.Context,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var lbbg *SLoadbalancerBackendGroup
|
||||
if input.IsRedirect() {
|
||||
input.BackendGroupId = ""
|
||||
} else {
|
||||
lbbgObj, err := validators.ValidateModel(ctx, userCred, LoadbalancerBackendGroupManager, &input.BackendGroupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lbbg = lbbgObj.(*SLoadbalancerBackendGroup)
|
||||
if lbbg.LoadbalancerId != lb.Id {
|
||||
return nil, httperrors.NewConflictError("backendgroup_id not same with listener's loadbalancer")
|
||||
}
|
||||
}
|
||||
if utils.IsInStringArray(input.ListenerType, []string{api.LB_LISTENER_TYPE_TCP, api.LB_LISTENER_TYPE_UDP}) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user