fix openpitrix return non nil client when enpoint is empty (#2165)
This commit is contained in:
@@ -188,24 +188,26 @@ func (mo monitoringOperator) GetKubeSphereStats() Metrics {
|
||||
openpitrix.RepoId: openpitrix.BuiltinRepoId,
|
||||
},
|
||||
}
|
||||
tmpls, err := mo.op.ListApps(cond, "", false, 0, 0)
|
||||
if err != nil {
|
||||
res.Results = append(res.Results, monitoring.Metric{
|
||||
MetricName: KubeSphereAppTmplCount,
|
||||
Error: err.Error(),
|
||||
})
|
||||
} else {
|
||||
res.Results = append(res.Results, monitoring.Metric{
|
||||
MetricName: KubeSphereAppTmplCount,
|
||||
MetricData: monitoring.MetricData{
|
||||
MetricType: monitoring.MetricTypeVector,
|
||||
MetricValues: []monitoring.MetricValue{
|
||||
{
|
||||
Sample: &monitoring.Point{now, float64(tmpls.TotalCount)},
|
||||
if mo.op != nil {
|
||||
tmpl, err := mo.op.ListApps(cond, "", false, 0, 0)
|
||||
if err != nil {
|
||||
res.Results = append(res.Results, monitoring.Metric{
|
||||
MetricName: KubeSphereAppTmplCount,
|
||||
Error: err.Error(),
|
||||
})
|
||||
} else {
|
||||
res.Results = append(res.Results, monitoring.Metric{
|
||||
MetricName: KubeSphereAppTmplCount,
|
||||
MetricData: monitoring.MetricData{
|
||||
MetricType: monitoring.MetricTypeVector,
|
||||
MetricValues: []monitoring.MetricValue{
|
||||
{
|
||||
Sample: &monitoring.Point{now, float64(tmpl.TotalCount)},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
|
||||
@@ -37,6 +37,10 @@ type openpitrixOperator struct {
|
||||
}
|
||||
|
||||
func NewOpenpitrixOperator(informers informers.SharedInformerFactory, opClient openpitrix.Client) Interface {
|
||||
if opClient == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &openpitrixOperator{
|
||||
ApplicationInterface: newApplicationOperator(informers, opClient),
|
||||
AppTemplateInterface: newAppTemplateOperator(opClient),
|
||||
|
||||
Reference in New Issue
Block a user