Skip to content

Commit 92e6a75

Browse files
authored
Support Exec column for generic resource apis (#153)
Signed-off-by: Tamal Saha <[email protected]>
1 parent 9ad17ae commit 92e6a75

File tree

9 files changed

+77
-46
lines changed

9 files changed

+77
-46
lines changed

artifacts/resourcequeries/render-response.yaml

+11-11
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ response:
184184
textAlign: center
185185
type: string
186186
- exec:
187-
alias: ""
188187
command:
189188
- bash
190189
- -c
@@ -203,12 +202,12 @@ response:
203202
- data: mg-alert-0
204203
link: /${username}/${clustername}/core/v1/pods/mg-alert-0?namespace=demo
205204
- data: '-'
206-
- data: 143m / 700m
207-
- data: 522Mi / 2Gi
205+
- data: 125m / 700m
206+
- data: 552Mi / 2Gi
208207
- data: 4Gi / 10Gi
209208
- color: success is-light
210209
data: Running
211-
- data: 31d
210+
- data: 32d
212211
sort: 1656073686
213212
- data: http://grafana.bb.test:3005/d/uqpE2Cynk/kubedb-mongodb-pod?from=now-3h&orgId=1&refresh=30s&to=now&var-db=mg-alert&var-namespace=demo&var-pod=mg-alert-0
214213
- data: mg-alert-0
@@ -284,7 +283,7 @@ response:
284283
- data: mg-alert-auth
285284
- data: mongodb-backup-5.0.3
286285
- data: mongodb-restore-5.0.3
287-
- data: 60d
286+
- data: 61d
288287
sort: 1653560482
289288
namespace: demo
290289
insight:
@@ -346,12 +345,12 @@ response:
346345
metadata: {}
347346
rows:
348347
- cells:
349-
- data: 1487
350-
- data: 1272080
351-
- data: 837373
352-
- data: 496
348+
- data: 1510
349+
- data: 1314928
350+
- data: 837350
351+
- data: 503
353352
- data: 5
354-
- data: 1061972
353+
- data: 1062431
355354
- data: 6
356355
- data: 172032
357356
- data: <unknown>
@@ -394,7 +393,8 @@ response:
394393
- name: Monitoring
395394
priority: 3
396395
type: string
397-
- name: Exec
396+
- exec: {}
397+
name: Exec
398398
priority: 4
399399
type: object
400400
metadata: {}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
kmodules.xyz/client-go v0.24.5
3333
kmodules.xyz/custom-resources v0.24.0
3434
kmodules.xyz/monitoring-agent-api v0.24.0
35-
kmodules.xyz/resource-metadata v0.12.4-0.20220725191232-73f401ba5161
35+
kmodules.xyz/resource-metadata v0.12.4-0.20220726185618-99fbbaaa8ba5
3636
kmodules.xyz/resource-metrics v0.10.1
3737
kmodules.xyz/sets v0.24.0
3838
kubepack.dev/kubepack v0.4.1-0.20220604085220-0b1719a66516

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1792,8 +1792,8 @@ kmodules.xyz/monitoring-agent-api v0.24.0 h1:CPFvzDppUKckMBLwaMnZbpYCuP7+NhcS4t7
17921792
kmodules.xyz/monitoring-agent-api v0.24.0/go.mod h1:lu1TmXRMx9IcjMpY8s5nc4HNOhOix5/z9caEnbL8JxA=
17931793
kmodules.xyz/offshoot-api v0.24.1 h1:8KCVNkLwdebzWmHcTdZPTQGxqI92bqA+vrmz65ueULY=
17941794
kmodules.xyz/offshoot-api v0.24.1/go.mod h1:fYu0051hoJXXs70OjmIE+Q5smOgmzvYFhRJXCiFShaY=
1795-
kmodules.xyz/resource-metadata v0.12.4-0.20220725191232-73f401ba5161 h1:TmWxIDLDAoSEWlJ6w5eCtTZj3oozJAn+SHaZZGMtPbQ=
1796-
kmodules.xyz/resource-metadata v0.12.4-0.20220725191232-73f401ba5161/go.mod h1:i9+cwehXHOAD/UG/WDlVcnNqKJEd1BzCjvNzy0tc/4Y=
1795+
kmodules.xyz/resource-metadata v0.12.4-0.20220726185618-99fbbaaa8ba5 h1:XWnXF2X56e3pn8vJ1KwZQqogqGsY/C/i0tIvDCRxMUU=
1796+
kmodules.xyz/resource-metadata v0.12.4-0.20220726185618-99fbbaaa8ba5/go.mod h1:i9+cwehXHOAD/UG/WDlVcnNqKJEd1BzCjvNzy0tc/4Y=
17971797
kmodules.xyz/resource-metrics v0.10.1 h1:q1dhk0eYxkZqd1peRy9wHGd8tOktBBH3kzgeTVaNBiY=
17981798
kmodules.xyz/resource-metrics v0.10.1/go.mod h1:YK0hjiLq6oBaGROmLSVcVDbmEgSxT1vpt8BCZZ+9teY=
17991799
kmodules.xyz/sets v0.24.0 h1:GbltLEPVnURjcmWyf8eFstgJBpm9o151wsrABkByGrc=

vendor/kmodules.xyz/resource-metadata/apis/meta/v1alpha1/openapi_generated.go

+6-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/kmodules.xyz/resource-metadata/apis/meta/v1alpha1/resourcedescriptor_types.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,14 @@ type DashboardResult struct {
307307

308308
// cell.Data == name of resource
309309
type ExecResult struct {
310-
Alias string `json:"alias"`
311-
Resource string `json:"resource"` // pods or services
312-
// Namespace string `json:"namespace"`
313-
Container string `json:"container"`
314-
Command []string `json:"command"`
310+
// +optional
311+
Alias string `json:"alias,omitempty"`
312+
// +optional
313+
Resource string `json:"resource,omitempty"` // pods or services
314+
// +optional
315+
Container string `json:"container,omitempty"`
316+
// +optional
317+
Command []string `json:"command,omitempty"`
315318
// +optional
316319
Help string `json:"help,omitempty"`
317320
}

vendor/kmodules.xyz/resource-metadata/apis/meta/v1alpha1/table_helpers.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ func Convert_ResourceColumnDefinition_To_ResourceColumn(def ResourceColumnDefini
7373
}
7474
}
7575
if def.Exec != nil {
76-
rs := "pods"
77-
if def.Exec.ServiceNameTemplate != "" {
78-
rs = "services"
76+
var rs string
77+
if len(def.Exec.Command) > 0 {
78+
rs = "pods"
79+
if def.Exec.ServiceNameTemplate != "" {
80+
rs = "services"
81+
}
7982
}
8083
col.Exec = &ExecResult{
8184
Alias: def.Exec.Alias,

vendor/kmodules.xyz/resource-metadata/hub/resourcetabledefinitions/core.k8s.appscode.com/v1alpha1/kubedb/genericresourceservices.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ spec:
7474
pathTemplate: '{{ .spec.facilities.monitoring.usage }}'
7575
priority: 3
7676
type: string
77-
- name: Exec
77+
- exec: {}
78+
name: Exec
7879
pathTemplate: '{{ .spec.facilities.exec | toRawJson }}'
7980
priority: 4
8081
type: object

vendor/kmodules.xyz/resource-metadata/pkg/tableconvertor/tableconvertor.go

+40-11
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"sync"
2727
"text/template"
2828

29+
meta_util "kmodules.xyz/client-go/meta"
2930
"kmodules.xyz/resource-metadata/apis/meta/v1alpha1"
3031
"kmodules.xyz/resource-metadata/apis/shared"
3132
"kmodules.xyz/resource-metadata/pkg/tableconvertor/lib"
@@ -248,25 +249,53 @@ func (c *convertor) rowFn(obj interface{}) ([]v1alpha1.TableCell, error) {
248249
}
249250
}
250251
} else if col.Exec != nil {
251-
if col.Exec.ServiceNameTemplate == "" {
252-
if v, err := renderTemplate(data, columnOptions{
253-
Name: col.Name,
254-
Type: col.Type,
255-
Template: col.PathTemplate,
256-
}, buf); err != nil {
257-
return nil, err
252+
if col.Type == "string" {
253+
if col.Exec.ServiceNameTemplate == "" {
254+
if v, err := renderTemplate(data, columnOptions{
255+
Name: col.Name,
256+
Type: col.Type,
257+
Template: col.PathTemplate,
258+
}, buf); err != nil {
259+
return nil, err
260+
} else {
261+
cell.Data = v
262+
}
258263
} else {
259-
cell.Data = v
264+
if v, err := renderTemplate(data, columnOptions{
265+
Name: col.Name,
266+
Type: "string",
267+
Template: col.Exec.ServiceNameTemplate,
268+
}, buf); err != nil {
269+
return nil, err
270+
} else {
271+
cell.Data = v
272+
}
260273
}
261274
} else {
262275
if v, err := renderTemplate(data, columnOptions{
263276
Name: col.Name,
264-
Type: "string",
265-
Template: col.Exec.ServiceNameTemplate,
277+
Type: col.Type,
278+
Template: col.PathTemplate,
266279
}, buf); err != nil {
267280
return nil, err
268281
} else {
269-
cell.Data = v
282+
if col.Exec.Alias != "" {
283+
var execs []v1alpha1.ResourceExec
284+
err = meta_util.DecodeObject(v, &execs)
285+
if err != nil {
286+
return nil, errors.Wrapf(err, "failed to decode cell value for col %s", col.Name)
287+
}
288+
result := make([]v1alpha1.ResourceExec, 0, len(execs))
289+
for _, exec := range execs {
290+
if exec.Alias == col.Exec.Alias {
291+
result = append(result, exec)
292+
break
293+
}
294+
}
295+
cell.Data = result
296+
} else {
297+
cell.Data = v
298+
}
270299
}
271300
}
272301
} else {

vendor/modules.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ kmodules.xyz/monitoring-agent-api/client
19001900
# kmodules.xyz/offshoot-api v0.24.1
19011901
## explicit; go 1.18
19021902
kmodules.xyz/offshoot-api/api/v1
1903-
# kmodules.xyz/resource-metadata v0.12.4-0.20220725191232-73f401ba5161
1903+
# kmodules.xyz/resource-metadata v0.12.4-0.20220726185618-99fbbaaa8ba5
19041904
## explicit; go 1.18
19051905
kmodules.xyz/resource-metadata/apis/core/install
19061906
kmodules.xyz/resource-metadata/apis/core/v1alpha1

0 commit comments

Comments
 (0)