Skip to content

Commit 8fb0236

Browse files
swordqiuQiu Jian
andauthored
fix: endpoint mode slave (#24023)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
1 parent c1cd91e commit 8fb0236

File tree

63 files changed

+349
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+349
-279
lines changed

cmd/climc/shell/identity/endpoints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func init() {
6666
type EndpointCreateOptions struct {
6767
SERVICE string `help:"Service ID or Name"`
6868
REGION string `help:"Region"`
69-
INTERFACE string `help:"Interface types" choices:"internal|public|admin|console"`
69+
INTERFACE string `help:"Interface types" choices:"internal|public|admin|console|slave"`
7070
URL string `help:"URL"`
7171
Zone string `help:"Zone"`
7272
Name string `help:"Name"`

cmd/climc/shell/misc/pprof.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"yunion.io/x/jsonutils"
2626
"yunion.io/x/pkg/errors"
27+
"yunion.io/x/pkg/util/httputils"
2728
"yunion.io/x/pkg/util/netutils"
2829
"yunion.io/x/pkg/util/signalutils"
2930

@@ -76,7 +77,7 @@ func init() {
7677
svcUrl string
7778
)
7879
if len(opts.Service) > 0 {
79-
svcUrl, err = s.GetServiceURL(opts.Service, "")
80+
svcUrl, err = s.GetServiceURL(opts.Service, "", httputils.GET)
8081
if err != nil {
8182
return errors.Wrapf(err, "get service %s url", opts.Service)
8283
}

pkg/ansibleserver/service/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"yunion.io/x/onecloud/pkg/cloudcommon/db"
3636
)
3737

38-
func InitHandlers(app *appsrv.Application) {
38+
func InitHandlers(app *appsrv.Application, isSlave bool) {
3939
db.InitAllManagers()
4040

4141
db.RegisterModelManager(db.OpsLog)
@@ -51,6 +51,6 @@ func InitHandlers(app *appsrv.Application) {
5151
} {
5252
db.RegisterModelManager(manager)
5353
handler := db.NewModelHandler(manager)
54-
dispatcher.AddModelDispatcher("", app, handler)
54+
dispatcher.AddModelDispatcher("", app, handler, isSlave)
5555
}
5656
}

pkg/ansibleserver/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func StartService() {
4545

4646
cloudcommon.InitDB(dbOpts)
4747

48-
InitHandlers(app)
48+
InitHandlers(app, opts.IsSlaveNode)
4949

5050
db.EnsureAppSyncDB(app, dbOpts, models.InitDB)
5151
defer cloudcommon.CloseDB()

pkg/apigateway/handler/backendproxy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import (
2424

2525
"yunion.io/x/log"
2626
"yunion.io/x/pkg/appctx"
27+
"yunion.io/x/pkg/util/httputils"
2728

29+
"yunion.io/x/onecloud/pkg/apis/identity"
2830
"yunion.io/x/onecloud/pkg/appsrv"
2931
"yunion.io/x/onecloud/pkg/httperrors"
3032
"yunion.io/x/onecloud/pkg/mcclient/auth"
@@ -149,12 +151,11 @@ func (h *SBackendServiceProxyHandler) fetchReverseEndpoint() *proxy.SEndpointFac
149151
zone = path[:slashPos]
150152
}
151153
}
152-
endpointType := "internalURL"
153154
session := auth.GetAdminSession(ctx, region)
154155
if len(zone) > 0 {
155156
session.SetZone(zone)
156157
}
157-
ep, err := session.GetServiceURL(serviceName, endpointType)
158+
ep, err := session.GetServiceURL(serviceName, identity.EndpointInterfaceInternal, httputils.THttpMethod(r.Method))
158159
if err != nil {
159160
return "", httperrors.NewBadRequestError("invalid service %s: %s", serviceName, err)
160161
}

pkg/apigateway/handler/proxy.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import (
1919
"net/http"
2020
"net/url"
2121

22+
"yunion.io/x/pkg/util/httputils"
23+
2224
"yunion.io/x/onecloud/pkg/apis"
25+
"yunion.io/x/onecloud/pkg/apis/identity"
2326
"yunion.io/x/onecloud/pkg/appsrv"
2427
"yunion.io/x/onecloud/pkg/mcclient/auth"
2528
"yunion.io/x/onecloud/pkg/proxy"
@@ -67,9 +70,8 @@ func getEndpointSchemeHost(endpoint string) (string, error) {
6770

6871
func fetchReverseEndpoint(serviceName string) *proxy.SEndpointFactory {
6972
f := func(ctx context.Context, r *http.Request) (string, error) {
70-
endpointType := "internalURL"
7173
session := auth.GetAdminSession(ctx, FetchRegion(r))
72-
ep, err := session.GetServiceURL(serviceName, endpointType)
74+
ep, err := session.GetServiceURL(serviceName, identity.EndpointInterfaceInternal, httputils.THttpMethod(r.Method))
7375
if err != nil {
7476
return "", err
7577
}

pkg/apis/identity/consts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ const (
5858

5959
EndpointInterfaceApigateway = "apigateway"
6060

61+
EndpointInterfaceSlave = "slave"
62+
6163
KeystoneDomainRoot = "<<keystone.domain.root>>"
6264

6365
IdMappingEntityUser = "user"

pkg/appsrv/dispatcher/dispatcher.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
3232
)
3333

34-
func AddModelDispatcher(prefix string, app *appsrv.Application, manager IModelDispatchHandler) {
34+
func AddModelDispatcher(prefix string, app *appsrv.Application, manager IModelDispatchHandler, isSlave bool) {
3535
metadata := map[string]interface{}{"manager": manager}
3636
tags := map[string]string{"resource": manager.KeywordPlural()}
3737
// list
@@ -69,6 +69,12 @@ func AddModelDispatcher(prefix string, app *appsrv.Application, manager IModelDi
6969
fmt.Sprintf("%s/%s/<resid>/<spec>", prefix, manager.KeywordPlural()),
7070
manager.Filter(getSpecHandler), metadata, "get_specific", tags)
7171
manager.CustomizeHandlerInfo(h)
72+
73+
if isSlave {
74+
// slave node only support get and head
75+
return
76+
}
77+
7278
// create
7379
// create multi
7480
h = app.AddHandler2("POST",

pkg/appsrv/dispatcher/jointdispatcher.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
3030
)
3131

32-
func AddJointModelDispatcher(prefix string, app *appsrv.Application, manager IJointModelDispatchHandler) {
32+
func AddJointModelDispatcher(prefix string, app *appsrv.Application, manager IJointModelDispatchHandler, isSlave bool) {
3333
metadata := map[string]interface{}{"manager": manager}
3434
tags := map[string]string{"resource": manager.KeywordPlural()}
3535
// list
@@ -64,6 +64,12 @@ func AddJointModelDispatcher(prefix string, app *appsrv.Application, manager IJo
6464
manager.MasterKeywordPlural()),
6565
manager.Filter(jointGetHandler),
6666
metadata, "get_joint", tags)
67+
68+
if isSlave {
69+
// slave node only support get and head
70+
return
71+
}
72+
6773
// joint attach
6874
app.AddHandler2("POST",
6975
fmt.Sprintf("%s/%s/<master_id>/%s/<slave_id>", prefix,

pkg/baremetal/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ func (b *SBaremetalInstance) getHTTPFileUrl(filename string) string {
11551155

11561156
func (b *SBaremetalInstance) GetImageUrl(disableImageCache bool) string {
11571157
if disableImageCache {
1158-
url, err := b.GetPublicClientSession().GetServiceURL(apis.SERVICE_TYPE_IMAGE, apiidenty.EndpointInterfacePublic)
1158+
url, err := b.GetPublicClientSession().GetServiceURL(apis.SERVICE_TYPE_IMAGE, apiidenty.EndpointInterfacePublic, httputils.GET)
11591159
if err != nil {
11601160
log.Errorf("Get image public url: %v", err)
11611161
return ""
@@ -2388,7 +2388,7 @@ func (b *SBaremetalInstance) getBootIsoImagePath() string {
23882388
func (b *SBaremetalInstance) DoNTPConfig() error {
23892389
var urls []string
23902390
for _, ep := range []string{"internal", "public"} {
2391-
urls, _ = auth.GetServiceURLs("ntp", o.Options.Region, "", ep)
2391+
urls, _ = auth.GetServiceURLs("ntp", o.Options.Region, "", ep, httputils.POST)
23922392
if len(urls) > 0 {
23932393
break
23942394
}

0 commit comments

Comments
 (0)