@@ -21,7 +21,6 @@ import (
21
21
"k8s.io/kubernetes/pkg/api"
22
22
unversioned "k8s.io/kubernetes/pkg/api/unversioned"
23
23
client "k8s.io/kubernetes/pkg/client/unversioned"
24
- unversionedClient "k8s.io/kubernetes/pkg/client/unversioned"
25
24
"k8s.io/kubernetes/pkg/fields"
26
25
"k8s.io/kubernetes/pkg/labels"
27
26
)
@@ -51,6 +50,9 @@ type ReplicaSetDetail struct {
51
50
52
51
// Detailed information about service related to Replica Set.
53
52
Services []ServiceDetail `json:"services"`
53
+
54
+ // True when the data contains at least one pod with metrics information, false otherwise.
55
+ HasMetrics bool `json:"hasMetrics"`
54
56
}
55
57
56
58
// Detailed information about a Pod that belongs to a Replica Set.
@@ -74,7 +76,7 @@ type ReplicaSetPod struct {
74
76
RestartCount int `json:"restartCount"`
75
77
76
78
// Pod metrics.
77
- Metrics PodMetrics `json:"metrics"`
79
+ Metrics * PodMetrics `json:"metrics"`
78
80
}
79
81
80
82
// Detailed information about a Service connected to Replica Set.
@@ -121,7 +123,7 @@ type ReplicaSetSpec struct {
121
123
}
122
124
123
125
// Returns detailed information about the given replica set in the given namespace.
124
- func GetReplicaSetDetail (client * client.Client , heapsterClient * unversionedClient. RESTClient ,
126
+ func GetReplicaSetDetail (client client.Interface , heapsterClient HeapsterClient ,
125
127
namespace , name string ) (* ReplicaSetDetail , error ) {
126
128
log .Printf ("Getting details of %s replica set in %s namespace" , name , namespace )
127
129
@@ -134,7 +136,7 @@ func GetReplicaSetDetail(client *client.Client, heapsterClient *unversionedClien
134
136
135
137
replicaSetMetricsByPod , err := getReplicaSetPodsMetrics (pods , heapsterClient , namespace , name )
136
138
if err != nil {
137
- return nil , err
139
+ log . Printf ( "Skipping Heapster metrics because of error: %s \n " , err )
138
140
}
139
141
140
142
services , err := client .Services (namespace ).List (unversioned.ListOptions {
@@ -172,7 +174,11 @@ func GetReplicaSetDetail(client *client.Client, heapsterClient *unversionedClien
172
174
PodIP : pod .Status .PodIP ,
173
175
NodeName : pod .Spec .NodeName ,
174
176
RestartCount : getRestartCount (pod ),
175
- Metrics : replicaSetMetricsByPod .MetricsMap [pod .Name ],
177
+ }
178
+ if replicaSetMetricsByPod != nil {
179
+ metric := replicaSetMetricsByPod .MetricsMap [pod .Name ]
180
+ podDetail .Metrics = & metric
181
+ replicaSetDetail .HasMetrics = true
176
182
}
177
183
replicaSetDetail .Pods = append (replicaSetDetail .Pods , podDetail )
178
184
}
@@ -183,7 +189,7 @@ func GetReplicaSetDetail(client *client.Client, heapsterClient *unversionedClien
183
189
// TODO(floreks): This should be transactional to make sure that RC will not be deleted without
184
190
// TODO(floreks): Should related services be deleted also?
185
191
// Deletes replica set with given name in given namespace and related pods
186
- func DeleteReplicaSetWithPods (client * client.Client , namespace , name string ) error {
192
+ func DeleteReplicaSetWithPods (client client.Interface , namespace , name string ) error {
187
193
log .Printf ("Deleting %s replica set from %s namespace" , name , namespace )
188
194
189
195
pods , err := getRawReplicaSetPods (client , namespace , name )
0 commit comments