fix openpitrix return non nil client when enpoint is empty (#2165)

This commit is contained in:
zryfish
2020-06-07 20:00:27 +08:00
committed by GitHub
parent df348b199f
commit 9b16c0589c
4 changed files with 74 additions and 25 deletions

View File

@@ -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

View File

@@ -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),