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: delete port and delete doamin #2111

Merged
merged 1 commit into from
Dec 19, 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
21 changes: 19 additions & 2 deletions api/handler/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"context"
"encoding/json"
"fmt"
apisixversioned "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/client/clientset/versioned"
"github.com/goodrain/rainbond/builder/sources/registry"
"github.com/goodrain/rainbond/pkg/component/grpc"
"github.com/goodrain/rainbond/pkg/component/hubregistry"
Expand Down Expand Up @@ -84,6 +85,7 @@ type ServiceAction struct {
dbmanager db.Manager
registryCli *registry.Registry
config *rest.Config
apisixClient *apisixversioned.Clientset
}

type dCfg struct {
Expand All @@ -101,6 +103,7 @@ func CreateManager() *ServiceAction {
statusCli: grpc.Default().StatusClient,
prometheusCli: prom.Default().PrometheusCli,
rainbondClient: k8s.Default().RainbondClient,
apisixClient: k8s.Default().ApiSixClient,
kubeClient: k8s.Default().Clientset,
kubevirtClient: k8s.Default().KubevirtCli,
dbmanager: db.GetManager(),
Expand Down Expand Up @@ -1250,9 +1253,23 @@ func (s *ServiceAction) CreatePorts(tenantID, serviceID string, vps *apimodel.Se
return nil
}

func (s *ServiceAction) deletePorts(componentID string, ports *apimodel.ServicePorts) error {
func (s *ServiceAction) deletePorts(componentID string, tenantID string, ports *apimodel.ServicePorts) error {
component, err := db.GetManager().TenantServiceDao().GetServiceByID(componentID)
if err != nil {
return err
}
tenant, err := db.GetManager().TenantDao().GetTenantByUUID(tenantID)
if err != nil {
return err
}
return db.GetManager().DB().Transaction(func(tx *gorm.DB) error {
for _, port := range ports.Port {
err = k8s.Default().ApiSixClient.ApisixV2().ApisixRoutes(tenant.Namespace).DeleteCollection(context.Background(), metav1.DeleteOptions{}, metav1.ListOptions{
LabelSelector: "component_sort=" + component.ServiceAlias + ",port=" + strconv.Itoa(port.ContainerPort),
})
if err != nil {
return err
}
if err := db.GetManager().TenantServicesPortDaoTransactions(tx).DeleteModel(componentID, port.ContainerPort); err != nil {
return err
}
Expand Down Expand Up @@ -1299,7 +1316,7 @@ func (s *ServiceAction) PortVar(action, tenantID, serviceID string, vps *apimode
}
switch action {
case "delete":
return s.deletePorts(serviceID, vps)
return s.deletePorts(serviceID, tenantID, vps)
case "update":
tx := db.GetManager().Begin()
defer func() {
Expand Down
Loading