mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 03:37:46 +08:00
Merge branch 'master' of https://github.com/goodrain/rainbond
This commit is contained in:
commit
a2cb4cce94
@ -355,15 +355,14 @@ type RuleExtensionDao interface {
|
||||
type HttpRuleDao interface {
|
||||
Dao
|
||||
GetHttpRuleByID(id string) (*model.HTTPRule, error)
|
||||
GetHttpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) (*model.HTTPRule, error)
|
||||
DeleteHttpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) (*model.HTTPRule, error)
|
||||
GetHttpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) ([]*model.HTTPRule, error)
|
||||
DeleteHttpRuleByID(id string) error
|
||||
}
|
||||
|
||||
// TcpRuleDao -
|
||||
type TcpRuleDao interface {
|
||||
Dao
|
||||
GetTcpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) (*model.TCPRule, error)
|
||||
GetTcpRuleByServiceIDAndContainerPort(serviceID string, containerPort int) ([]*model.TCPRule, error)
|
||||
GetTcpRuleByID(id string) (*model.TCPRule, error)
|
||||
DeleteTcpRule(tcpRule *model.TCPRule) error
|
||||
}
|
||||
|
@ -163,8 +163,8 @@ func (h *HttpRuleDaoImpl) GetHttpRuleByID(id string) (*model.HTTPRule, error) {
|
||||
|
||||
// GetHttpRuleByServiceIDAndContainerPort gets a HTTPRule based on serviceID and containerPort
|
||||
func (h *HttpRuleDaoImpl) GetHttpRuleByServiceIDAndContainerPort(serviceID string,
|
||||
containerPort int) (*model.HTTPRule, error) {
|
||||
httpRule := &model.HTTPRule{}
|
||||
containerPort int) ([]*model.HTTPRule, error) {
|
||||
var httpRule []*model.HTTPRule
|
||||
if err := h.DB.Where("service_id = ? and container_port = ?", serviceID,
|
||||
containerPort).Find(httpRule).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
@ -175,20 +175,6 @@ func (h *HttpRuleDaoImpl) GetHttpRuleByServiceIDAndContainerPort(serviceID strin
|
||||
return httpRule, nil
|
||||
}
|
||||
|
||||
func (h *HttpRuleDaoImpl) DeleteHttpRuleByServiceIDAndContainerPort(serviceID string,
|
||||
containerPort int) (*model.HTTPRule, error) {
|
||||
httpRule, err := h.GetHttpRuleByServiceIDAndContainerPort(serviceID, containerPort)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := h.DB.Where("service_id = ? and container_port = ?", serviceID,
|
||||
containerPort).Delete(httpRule).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return httpRule, nil
|
||||
}
|
||||
|
||||
func (h *HttpRuleDaoImpl) DeleteHttpRuleByID(id string) error {
|
||||
httpRule := &model.HTTPRule{
|
||||
UUID: id,
|
||||
@ -232,8 +218,8 @@ func (t *TcpRuleDaoTmpl) UpdateModel(mo model.Interface) error {
|
||||
|
||||
// GetTcpRuleByServiceIDAndContainerPort gets a TCPRule based on serviceID and containerPort
|
||||
func (s *TcpRuleDaoTmpl) GetTcpRuleByServiceIDAndContainerPort(serviceID string,
|
||||
containerPort int) (*model.TCPRule, error) {
|
||||
result := &model.TCPRule{}
|
||||
containerPort int) ([]*model.TCPRule, error) {
|
||||
var result []*model.TCPRule
|
||||
if err := s.DB.Where("service_id = ? and container_port = ?", serviceID,
|
||||
containerPort).Find(result).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
|
@ -157,7 +157,9 @@ func (a *AppServiceBuild) Build() ([]*corev1.Service, []*extensions.Ingress, []*
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
ingresses = append(ingresses, ings...)
|
||||
if ings != nil && len(ings) > 0 {
|
||||
ingresses = append(ingresses, ings...)
|
||||
}
|
||||
if secret != nil {
|
||||
secrets = append(secrets, secret)
|
||||
}
|
||||
@ -181,40 +183,45 @@ func (a *AppServiceBuild) Build() ([]*corev1.Service, []*extensions.Ingress, []*
|
||||
// ApplyRules applies http rules and tcp rules
|
||||
func (a AppServiceBuild) ApplyRules(port *model.TenantServicesPort,
|
||||
service *corev1.Service) ([]*extensions.Ingress, *corev1.Secret, error) {
|
||||
httpRule, err := a.dbmanager.HttpRuleDao().GetHttpRuleByServiceIDAndContainerPort(port.ServiceID,
|
||||
port.ContainerPort) // TODO: http rule should be more than one
|
||||
httpRules, err := a.dbmanager.HttpRuleDao().GetHttpRuleByServiceIDAndContainerPort(port.ServiceID,
|
||||
port.ContainerPort)
|
||||
if err != nil {
|
||||
logrus.Infof("Can't get HTTPRule corresponding to ServiceID(%s): %v", port.ServiceID, err)
|
||||
}
|
||||
tcpRule, err := a.dbmanager.TcpRuleDao().GetTcpRuleByServiceIDAndContainerPort(port.ServiceID,
|
||||
port.ContainerPort) // TODO: tcp rule should be more than one
|
||||
tcpRules, err := a.dbmanager.TcpRuleDao().GetTcpRuleByServiceIDAndContainerPort(port.ServiceID,
|
||||
port.ContainerPort)
|
||||
if err != nil {
|
||||
logrus.Infof("Can't get TCPRule corresponding to ServiceID(%s): %v", port.ServiceID, err)
|
||||
}
|
||||
if httpRule == nil && tcpRule == nil {
|
||||
return nil, nil, fmt.Errorf("Can't find HTTPRule or TCPRule for Outer Service(%s)", port.ServiceID)
|
||||
}
|
||||
|
||||
// create ingresses
|
||||
var ingresses []*extensions.Ingress
|
||||
var secret *corev1.Secret
|
||||
// http
|
||||
if httpRule != nil {
|
||||
ing, sec, err := a.applyHTTPRule(httpRule, port, service)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
if httpRules != nil && len(httpRules) > 0 {
|
||||
for _, httpRule := range httpRules {
|
||||
ing, sec, err := a.applyHTTPRule(httpRule, port, service)
|
||||
if err != nil {
|
||||
logrus.Errorf("Unexpected error occurred while applying http rule: %v", err)
|
||||
// skip the failed rule
|
||||
continue
|
||||
}
|
||||
ingresses = append(ingresses, ing)
|
||||
secret = sec
|
||||
}
|
||||
ingresses = append(ingresses, ing)
|
||||
secret = sec
|
||||
}
|
||||
|
||||
// tcp
|
||||
if tcpRule != nil {
|
||||
ing, err := applyTCPRule(tcpRule, service, a.tenant.UUID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
if tcpRules != nil && len(tcpRules) > 0 {
|
||||
for _, tcpRule := range tcpRules {
|
||||
ing, err := applyTCPRule(tcpRule, service, a.tenant.UUID)
|
||||
if err != nil {
|
||||
logrus.Errorf("Unexpected error occurred while applying tcp rule: %v", err)
|
||||
// skip the failed rule
|
||||
continue
|
||||
}
|
||||
ingresses = append(ingresses, ing)
|
||||
}
|
||||
ingresses = append(ingresses, ing)
|
||||
}
|
||||
|
||||
return ingresses, secret, nil
|
||||
|
Loading…
Reference in New Issue
Block a user