fix openpitrix return non nil client when enpoint is empty (#2165)
This commit is contained in:
@@ -179,7 +179,7 @@ func (s *ServerRunOptions) NewAPIServer(stopCh <-chan struct{}) (*apiserver.APIS
|
|||||||
apiServer.AuditingClient = auditingClient
|
apiServer.AuditingClient = auditingClient
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.OpenPitrixOptions != nil {
|
if s.OpenPitrixOptions != nil && !s.OpenPitrixOptions.IsEmpty() {
|
||||||
opClient, err := openpitrix.NewClient(s.OpenPitrixOptions)
|
opClient, err := openpitrix.NewClient(s.OpenPitrixOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -188,7 +188,8 @@ func (mo monitoringOperator) GetKubeSphereStats() Metrics {
|
|||||||
openpitrix.RepoId: openpitrix.BuiltinRepoId,
|
openpitrix.RepoId: openpitrix.BuiltinRepoId,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tmpls, err := mo.op.ListApps(cond, "", false, 0, 0)
|
if mo.op != nil {
|
||||||
|
tmpl, err := mo.op.ListApps(cond, "", false, 0, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Results = append(res.Results, monitoring.Metric{
|
res.Results = append(res.Results, monitoring.Metric{
|
||||||
MetricName: KubeSphereAppTmplCount,
|
MetricName: KubeSphereAppTmplCount,
|
||||||
@@ -201,12 +202,13 @@ func (mo monitoringOperator) GetKubeSphereStats() Metrics {
|
|||||||
MetricType: monitoring.MetricTypeVector,
|
MetricType: monitoring.MetricTypeVector,
|
||||||
MetricValues: []monitoring.MetricValue{
|
MetricValues: []monitoring.MetricValue{
|
||||||
{
|
{
|
||||||
Sample: &monitoring.Point{now, float64(tmpls.TotalCount)},
|
Sample: &monitoring.Point{now, float64(tmpl.TotalCount)},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ type openpitrixOperator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewOpenpitrixOperator(informers informers.SharedInformerFactory, opClient openpitrix.Client) Interface {
|
func NewOpenpitrixOperator(informers informers.SharedInformerFactory, opClient openpitrix.Client) Interface {
|
||||||
|
if opClient == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return &openpitrixOperator{
|
return &openpitrixOperator{
|
||||||
ApplicationInterface: newApplicationOperator(informers, opClient),
|
ApplicationInterface: newApplicationOperator(informers, opClient),
|
||||||
AppTemplateInterface: newAppTemplateOperator(opClient),
|
AppTemplateInterface: newAppTemplateOperator(opClient),
|
||||||
|
|||||||
@@ -74,7 +74,15 @@ func parseToHostPort(endpoint string) (string, int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newRuntimeManagerClient(endpoint string) (pb.RuntimeManagerClient, error) {
|
func newRuntimeManagerClient(endpoint string) (pb.RuntimeManagerClient, error) {
|
||||||
|
if len(endpoint) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
host, port, err := parseToHostPort(endpoint)
|
host, port, err := parseToHostPort(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
conn, err := manager.NewClient(host, port)
|
conn, err := manager.NewClient(host, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -82,7 +90,14 @@ func newRuntimeManagerClient(endpoint string) (pb.RuntimeManagerClient, error) {
|
|||||||
return pb.NewRuntimeManagerClient(conn), nil
|
return pb.NewRuntimeManagerClient(conn), nil
|
||||||
}
|
}
|
||||||
func newClusterManagerClient(endpoint string) (pb.ClusterManagerClient, error) {
|
func newClusterManagerClient(endpoint string) (pb.ClusterManagerClient, error) {
|
||||||
|
if len(endpoint) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
host, port, err := parseToHostPort(endpoint)
|
host, port, err := parseToHostPort(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
conn, err := manager.NewClient(host, port)
|
conn, err := manager.NewClient(host, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -90,7 +105,14 @@ func newClusterManagerClient(endpoint string) (pb.ClusterManagerClient, error) {
|
|||||||
return pb.NewClusterManagerClient(conn), nil
|
return pb.NewClusterManagerClient(conn), nil
|
||||||
}
|
}
|
||||||
func newCategoryManagerClient(endpoint string) (pb.CategoryManagerClient, error) {
|
func newCategoryManagerClient(endpoint string) (pb.CategoryManagerClient, error) {
|
||||||
|
if len(endpoint) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
host, port, err := parseToHostPort(endpoint)
|
host, port, err := parseToHostPort(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
conn, err := manager.NewClient(host, port)
|
conn, err := manager.NewClient(host, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -99,7 +121,14 @@ func newCategoryManagerClient(endpoint string) (pb.CategoryManagerClient, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newAttachmentManagerClient(endpoint string) (pb.AttachmentManagerClient, error) {
|
func newAttachmentManagerClient(endpoint string) (pb.AttachmentManagerClient, error) {
|
||||||
|
if len(endpoint) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
host, port, err := parseToHostPort(endpoint)
|
host, port, err := parseToHostPort(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
conn, err := manager.NewClient(host, port)
|
conn, err := manager.NewClient(host, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -108,7 +137,14 @@ func newAttachmentManagerClient(endpoint string) (pb.AttachmentManagerClient, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newRepoManagerClient(endpoint string) (pb.RepoManagerClient, error) {
|
func newRepoManagerClient(endpoint string) (pb.RepoManagerClient, error) {
|
||||||
|
if len(endpoint) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
host, port, err := parseToHostPort(endpoint)
|
host, port, err := parseToHostPort(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
conn, err := manager.NewClient(host, port)
|
conn, err := manager.NewClient(host, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -117,7 +153,14 @@ func newRepoManagerClient(endpoint string) (pb.RepoManagerClient, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newRepoIndexer(endpoint string) (pb.RepoIndexerClient, error) {
|
func newRepoIndexer(endpoint string) (pb.RepoIndexerClient, error) {
|
||||||
|
if len(endpoint) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
host, port, err := parseToHostPort(endpoint)
|
host, port, err := parseToHostPort(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
conn, err := manager.NewClient(host, port)
|
conn, err := manager.NewClient(host, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -126,7 +169,14 @@ func newRepoIndexer(endpoint string) (pb.RepoIndexerClient, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newAppManagerClient(endpoint string) (pb.AppManagerClient, error) {
|
func newAppManagerClient(endpoint string) (pb.AppManagerClient, error) {
|
||||||
|
if len(endpoint) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
host, port, err := parseToHostPort(endpoint)
|
host, port, err := parseToHostPort(endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
conn, err := manager.NewClient(host, port)
|
conn, err := manager.NewClient(host, port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -134,52 +184,45 @@ func newAppManagerClient(endpoint string) (pb.AppManagerClient, error) {
|
|||||||
return pb.NewAppManagerClient(conn), nil
|
return pb.NewAppManagerClient(conn), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// will return a nil client and nil error if endpoint is empty
|
||||||
func NewClient(options *Options) (Client, error) {
|
func NewClient(options *Options) (Client, error) {
|
||||||
|
|
||||||
runtimeMangerClient, err := newRuntimeManagerClient(options.RuntimeManagerEndpoint)
|
runtimeMangerClient, err := newRuntimeManagerClient(options.RuntimeManagerEndpoint)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
clusterManagerClient, err := newClusterManagerClient(options.ClusterManagerEndpoint)
|
clusterManagerClient, err := newClusterManagerClient(options.ClusterManagerEndpoint)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
repoManagerClient, err := newRepoManagerClient(options.RepoManagerEndpoint)
|
repoManagerClient, err := newRepoManagerClient(options.RepoManagerEndpoint)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
repoIndexerClient, err := newRepoIndexer(options.RepoIndexerEndpoint)
|
repoIndexerClient, err := newRepoIndexer(options.RepoIndexerEndpoint)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
appManagerClient, err := newAppManagerClient(options.AppManagerEndpoint)
|
appManagerClient, err := newAppManagerClient(options.AppManagerEndpoint)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryManagerClient, err := newCategoryManagerClient(options.CategoryManagerEndpoint)
|
categoryManagerClient, err := newCategoryManagerClient(options.CategoryManagerEndpoint)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentManagerClient, err := newAttachmentManagerClient(options.AttachmentManagerEndpoint)
|
attachmentManagerClient, err := newAttachmentManagerClient(options.AttachmentManagerEndpoint)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user