diff --git a/bcs-services/bcs-bscp/cmd/data-service/service/app.go b/bcs-services/bcs-bscp/cmd/data-service/service/app.go index 749f1483d0..95b473a8e3 100644 --- a/bcs-services/bcs-bscp/cmd/data-service/service/app.go +++ b/bcs-services/bcs-bscp/cmd/data-service/service/app.go @@ -163,6 +163,12 @@ func (s *Service) deleteAppRelatedResources(grpcKit *kit.Kit, req *pbds.DeleteAp return err } + // delete released hook + if err := s.dao.ReleasedHook().DeleteByAppIDWithTx(grpcKit, tx, req.Id, req.BizId); err != nil { + logs.Errorf("delete released hooks failed, err: %v, rid: %s", err, grpcKit.Rid) + return err + } + return nil } diff --git a/bcs-services/bcs-bscp/pkg/dal/dao/released_hooks.go b/bcs-services/bcs-bscp/pkg/dal/dao/released_hooks.go index fbda0305b5..ad0880eef5 100644 --- a/bcs-services/bcs-bscp/pkg/dal/dao/released_hooks.go +++ b/bcs-services/bcs-bscp/pkg/dal/dao/released_hooks.go @@ -39,6 +39,8 @@ type ReleasedHook interface { CreateWithTx(kit *kit.Kit, tx *gen.QueryTx, releasedHook *table.ReleasedHook) (uint32, error) // ListAll list all released hooks in biz ListAll(kit *kit.Kit, bizID uint32) ([]*table.ReleasedHook, error) + // DeleteByAppIDWithTx deletes the released hook by app id with transaction. + DeleteByAppIDWithTx(kit *kit.Kit, tx *gen.QueryTx, appID, bizID uint32) error // DeleteByUniqueKeyWithTx deletes the released hook by unique key with transaction. DeleteByUniqueKeyWithTx(kit *kit.Kit, tx *gen.QueryTx, rh *table.ReleasedHook) error // DeleteByHookIDAndReleaseIDWithTx deletes the released hook by hook id and release id with transaction. @@ -227,6 +229,19 @@ func (dao *releasedHookDao) ListAll(kit *kit.Kit, bizID uint32) ([]*table.Releas return rhs, nil } +// DeleteByAppIDWithTx deletes the released hook by app id with transaction. +func (dao *releasedHookDao) DeleteByAppIDWithTx(kit *kit.Kit, tx *gen.QueryTx, appID, bizID uint32) error { + if bizID == 0 { + return errf.New(errf.InvalidParameter, "bizID is 0") + } + if appID == 0 { + return errf.New(errf.InvalidParameter, "appID is 0") + } + m := tx.ReleasedHook + _, err := m.WithContext(kit.Ctx).Where(m.BizID.Eq(bizID), m.AppID.Eq(appID)).Delete() + return err +} + // DeleteByUniqueKeyWithTx deletes the released hook by unique key with transaction. func (dao *releasedHookDao) DeleteByUniqueKeyWithTx(kit *kit.Kit, tx *gen.QueryTx, rh *table.ReleasedHook) error { if rh == nil {