Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

Commit 07d5e6e

Browse files
committed
--node-link-url-template and --pod-link-url-template for external links
1 parent 4dc7d48 commit 07d5e6e

File tree

8 files changed

+36
-8
lines changed

8 files changed

+36
-8
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ push: docker
2727
docker push "$(IMAGE):$(TAG)"
2828

2929
mock:
30-
docker run $(TTYFLAGS) -p 8080:8080 "$(IMAGE):$(TAG)" --mock
30+
docker run $(TTYFLAGS) -p 8080:8080 "$(IMAGE):$(TAG)" --mock \
31+
--node-link-url-template "https://kube-web-view.example.org/clusters/{cluster}/nodes/{name}" \
32+
--pod-link-url-template "https://kube-web-view.example.org/clusters/{cluster}/namespaces/{namespace}/pods/{name}"

README.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ Kubernetes Operational View
1414
:target: https://hub.docker.com/r/hjacobs/kube-ops-view
1515
:alt: Docker pulls
1616

17-
**This project is in a very early state, but it might already be useful.**
18-
1917
.. image:: screenshot.png
2018
:alt: Screenshot
2119

@@ -157,6 +155,10 @@ The following environment variables are supported:
157155
Optional Redis server to use for pub/sub events and job locking when running more than one replica. Example: ``redis://my-redis:6379``
158156
``SERVER_PORT``
159157
HTTP port to listen on. It defaults to ``8080``.
158+
``NODE_LINK_URL_TEMPLATE``
159+
Template to make Nodes clickable, e.g. can point to `kube-web-view <https://codeberg.org/hjacobs/kube-web-view/>`_. ``{cluster}`` (cluster ID) and ``{name}`` (Node name) will be replaced in the URL template.
160+
``POD_LINK_URL_TEMPLATE``
161+
Template to make Pods clickable, e.g. can point to `kube-web-view <https://codeberg.org/hjacobs/kube-web-view/>`_. ``{cluster}`` (cluster ID), ``{namespace}`` (Pod's namespace), and ``{name}`` (Pod name) will be replaced in the URL template.
160162

161163

162164
Supported Browsers

app/src/app.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ const addWheelListener = require('./vendor/addWheelListener')
1414

1515
export default class App {
1616

17-
constructor() {
17+
constructor(config) {
1818
const params = this.parseLocationHash()
19+
1920
this.config = Config.fromParams(params)
21+
this.config.nodeLinkUrlTemplate = config['node_link_url_template']
22+
this.config.podLinkUrlTemplate = config['pod_link_url_template']
23+
2024
this.filterString = (params.get('q') && decodeURIComponent(params.get('q'))) || ''
2125
this.selectedClusters = new Set((params.get('clusters') || '').split(',').filter(x => x))
2226
this.seenPods = new Set()
23-
27+
2428
// check localStorage, use the first function as a default option
2529
const indexSorterFn = ALL_SORTS.findIndex(obj => obj.text === (localStorage.getItem('sorterFn') || ALL_SORTS[0].text))
2630
this.sorterFn = ALL_SORTS[indexSorterFn].value

app/src/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export default class Config {
1313
this.maxConnectionLifetimeSeconds = 300
1414
// consider cluster data older than 1 minute outdated
1515
this.maxDataAgeSeconds = 60
16+
17+
this.nodeLinkUrlTemplate = null
18+
this.podLinkUrlTemplate = null
1619
}
1720

1821
static fromParams(params) {

app/src/node.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class Node extends PIXI.Graphics {
7070
topHandle.beginFill(App.current.theme.primaryColor, 1)
7171
topHandle.drawRect(0, 0, this.widthOfNodePx, App.current.heightOfTopHandlePx)
7272
topHandle.endFill()
73+
7374
// there is about 2.83 letters per pod
7475
const roomForText = Math.floor(2.83 * this.podsPerRow)
7576
const ellipsizedNodeName = this.node.name.length > roomForText ? this.node.name.substring(0, roomForText).concat('…') : this.node.name
@@ -97,6 +98,12 @@ export class Node extends PIXI.Graphics {
9798
topHandle.on('mouseout', function () {
9899
nodeBox.tooltip.visible = false
99100
})
101+
if (App.current.config.nodeLinkUrlTemplate !== null) {
102+
topHandle.buttonMode = true
103+
topHandle.on('click', function() {
104+
location.href = App.current.config.nodeLinkUrlTemplate.replace('{cluster}', nodeBox.cluster.cluster.id).replace('{name}', nodeBox.node.name)
105+
})
106+
}
100107
const resources = this.getResourceUsage()
101108
const bars = new Bars(nodeBox, resources, nodeBox.tooltip)
102109
bars.x = 0

app/src/pod.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ export class Pod extends PIXI.Graphics {
228228
podBox.filters = podBox.filters.filter(x => x != BRIGHTNESS_FILTER)
229229
this.tooltip.visible = false
230230
})
231+
if (App.current.config.podLinkUrlTemplate !== null) {
232+
podBox.buttonMode = true
233+
podBox.on('click', function() {
234+
location.href = App.current.config.podLinkUrlTemplate.replace('{cluster}', this.cluster.cluster.id).replace('{namespace}', this.pod.namespace).replace('{name}', this.pod.name)
235+
})
236+
}
231237
podBox.lineStyle(1, App.current.theme.primaryColor, 1)
232238
const w = 10 / this.pod.containers.length
233239
for (let i = 0; i < this.pod.containers.length; i++) {

kube_ops_view/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def index():
7878
else:
7979
logger.error('Could not find JavaScript application bundle app*.js in {}'.format(static_build_path))
8080
flask.abort(503, 'JavaScript application bundle not found (missing build)')
81-
return flask.render_template('index.html', app_js=app_js, version=kube_ops_view.__version__)
81+
return flask.render_template('index.html', app_js=app_js, version=kube_ops_view.__version__, app_config_json=json.dumps(app.app_config))
8282

8383

8484
def event(cluster_ids: set):
@@ -188,14 +188,18 @@ def convert(self, value, param, ctx):
188188
@click.option('--kubeconfig-contexts', type=CommaSeparatedValues(),
189189
help='List of kubeconfig contexts to use (default: use all defined contexts)', envvar='KUBECONFIG_CONTEXTS')
190190
@click.option('--query-interval', type=float, help='Interval in seconds for querying clusters (default: 5)', envvar='QUERY_INTERVAL', default=5)
191-
def main(port, debug, mock, secret_key, redis_url, clusters: list, cluster_registry_url, kubeconfig_path, kubeconfig_contexts: list, query_interval):
191+
@click.option('--node-link-url-template', help='Template for target URL when clicking on a Node', envvar='NODE_LINK_URL_TEMPLATE')
192+
@click.option('--pod-link-url-template', help='Template for target URL when clicking on a Pod', envvar='POD_LINK_URL_TEMPLATE')
193+
def main(port, debug, mock, secret_key, redis_url, clusters: list, cluster_registry_url, kubeconfig_path, kubeconfig_contexts: list, query_interval,
194+
node_link_url_template: str, pod_link_url_template: str):
192195
logging.basicConfig(level=logging.DEBUG if debug else logging.INFO)
193196

194197
store = RedisStore(redis_url) if redis_url else MemoryStore()
195198

196199
app.debug = debug
197200
app.secret_key = secret_key
198201
app.store = store
202+
app.app_config = {'node_link_url_template': node_link_url_template, 'pod_link_url_template': pod_link_url_template}
199203

200204
if mock:
201205
cluster_query = query_mock_cluster

kube_ops_view/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
<!-- make sure the font is loaded -->
2424
<div id="loading" style="font-family: ShareTechMono">Loading..</div>
2525
<script src="static/build/{{ app_js }}"></script>
26-
<script>document.getElementById('loading').style.display = 'none'; const app = new App(); app.run()</script>
26+
<script>document.getElementById('loading').style.display = 'none'; const app = new App({{ app_config_json|safe }}); app.run()</script>
2727
</body>
2828
</html>

0 commit comments

Comments
 (0)