This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkube-replc.html
141 lines (123 loc) · 4.04 KB
/
kube-replc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="../paper-slider/paper-slider.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="kube-card.html">
<polymer-element name="kube-replc" attributes="rid data core">
<template>
<link rel="stylesheet" href="kube-replc.css">
<kube-card icon="apps" top="{{data.id}}">
<main>
<span class="circle">{{data.desiredState.replicas}}</span> replicas
<div class="top space">
<paper-slider pin snaps min="0" max="20" step="1"
value="{{data.desiredState.replicas}}"></paper-slider>
</div>
<div class="top space">
<template repeat="{{k in data.desiredState.replicaSelector | keys}}">
<div class="smaller inline">
<span class="slabel name">{{k}}
</span><span class="slabel value">{{data.desiredState.replicaSelector[k]}}</span>
</div>
</template>
</div>
<ul class="bullets">
<template repeat="{{c in data.desiredState.podTemplate.desiredState.manifest.containers}}">
<li>
{{c.name}}<br/>
<span class="secondary smaller newline">{{c.image}}</span>
<span class="secondary smaller newline">{{c.ports | cPorts}}</span>
</li>
</template>
</ul>
</main>
<template repeat="{{k in data.labels | keys}}">
<div class="smaller label item">
<span class="label name">{{k}}
</span><span class="label value">{{data.labels[k]}}</span>
</div>
</template>
<bottom>{{data.creationTimestamp | date}}</bottom>
<paper-icon-button id="close" icon="close" on-click="{{remove}}"></paper-icon-button>
</kube-card>
</template>
<script>
Polymer({
refreshInterval: 2000,
observe: {
'data.desiredState.replicas': 'maybeUpdate',
'rid': 'refresh'
// TODO: refresh on core changes
},
ready: function() {
this.isUpdating = false;
if (!this.data && this.rid)
this.refresh();
},
detached: function() {
this.isDetached = true;
},
date: function(v) {
return v ? new Date(v).toLocaleString() : null;
},
keys: function(obj) {
return obj ? Object.keys(obj) : [];
},
labels: function(obj) {
var labels = [];
for (var k in obj) {
labels.push(k + '=' + obj[k]);
}
return labels.join(', ');
},
cPorts: function(items) {
var ports = [];
if (!items) {
return;
}
for (var i=0, p; p = items[i]; i++) {
ports.push(p.hostPort + ':' + p.containerPort);
};
return ports.join(', ');
},
receive: function(response) {
if (this.isUpdating)
return;
if (response.id) {
this.data = response;
this.rid = this.data.id;
}
!this.isDetached && this.refresh(this.refreshInterval);
},
refresh: function(delay) {
this.refreshJob = this.job(this.refreshJob, this.refreshNow, parseInt(delay) || 0);
},
refreshNow: function() {
this.core && this.core.getReplica({
rid: this.rid,
callback: this.receive.bind(this)
});
},
maybeUpdate: function(oldval, newval) {
if (typeof oldval !== 'undefined' && newval >= 0) {
this.update();
}
},
update: function() {
if (!this.core)
return;
var self = this;
var callback = function() {
self.isUpdating = false;
self.receive.apply(self, arguments);
}
this.isUpdating = true;
this.core.updateReplica({rid: this.rid, callback: callback}, this.data);
},
remove: function() {
this.core && this.core.removeReplica({rid: this.rid});
this.super();
}
});
</script>
</polymer-element>