Skip to content

Commit a4e10db

Browse files
committed
add generic label passing
1 parent fbec7b7 commit a4e10db

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

internal/controlplane/controlplane.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ func NewDashboard() (Controlplane, error) {
3131

3232
gc := config.GetFirstGatewayConfig()
3333
if err := control.AddCluster(context.TODO(), &dashboard.ClusterOptions{
34-
Name: "default",
34+
Name: "default",
35+
Labels: map[string]string{
36+
"controller_name": config.ControllerConfig.ControllerName,
37+
},
3538
ControllerName: config.ControllerConfig.ControllerName,
3639
BaseURL: gc.ControlPlane.Endpoints[0],
3740
AdminKey: gc.ControlPlane.AdminKey,

pkg/dashboard/cluster.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ type ClusterOptions struct {
8383
SyncCache bool
8484
SSLKeyEncryptSalt string
8585
SkipTLSVerify bool
86+
Labels map[string]string
8687
}
8788

8889
type cluster struct {
90+
labels map[string]string
8991
controllerName string
9092
adminVersion string
9193
name string
@@ -137,6 +139,7 @@ func newCluster(ctx context.Context, o *ClusterOptions) (Cluster, error) {
137139
// if the version is not v3, then fallback to v2
138140
adminVersion := o.AdminAPIVersion
139141
c := &cluster{
142+
labels: o.Labels,
140143
controllerName: o.ControllerName,
141144
adminVersion: adminVersion,
142145
name: o.Name,
@@ -513,13 +516,15 @@ func (c *cluster) getResource(ctx context.Context, url, resource string) (*getRe
513516
return &res, nil
514517
}
515518

516-
func addQueryParam(urlStr, key, value string) string {
519+
func addQueryParam(urlStr string, labels map[string]string) string {
517520
parsedUrl, err := url.Parse(urlStr)
518521
if err != nil {
519522
return urlStr
520523
}
521524
query := parsedUrl.Query()
522-
query.Add(key, value)
525+
for key, value := range labels {
526+
query.Add(key, value)
527+
}
523528
parsedUrl.RawQuery = query.Encode()
524529
return parsedUrl.String()
525530
}
@@ -530,7 +535,10 @@ func (c *cluster) listResource(ctx context.Context, url, resource string) (listR
530535
zap.String("name", resource),
531536
zap.String("url", url),
532537
)
533-
url = addQueryParam(url, fmt.Sprintf("labels[%s]", "controller_name"), c.controllerName)
538+
if c.labels != nil {
539+
url = addQueryParam(url, c.labels)
540+
}
541+
534542
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
535543
if err != nil {
536544
return listResponse{}, err

test/e2e/scaffold/k8s.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func (s *Scaffold) ClusterClient() (apisix.Cluster, error) {
146146
err = cli.AddCluster(context.Background(), &apisix.ClusterOptions{
147147
BaseURL: u.String(),
148148
ControllerName: s.opts.ControllerName,
149+
Labels: map[string]string{"controller_name": s.opts.ControllerName},
149150
AdminKey: s.opts.APISIXAdminAPIKey,
150151
SyncCache: true,
151152
})

test/e2e/scaffold/scaffold.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ func (s *Scaffold) initDataPlaneClient() {
411411
err = s.apisixCli.AddCluster(context.Background(), &dashboard.ClusterOptions{
412412
Name: "default",
413413
ControllerName: s.opts.ControllerName,
414+
Labels: map[string]string{"controller_name": s.opts.ControllerName},
414415
BaseURL: url,
415416
AdminKey: s.AdminKey(),
416417
})

0 commit comments

Comments
 (0)