Skip to content

Commit

Permalink
feat(monitor): decouple monitor and business
Browse files Browse the repository at this point in the history
  • Loading branch information
wangao1236 authored and tke-robot committed Aug 25, 2020
1 parent f649c2e commit 0ff8557
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 17 deletions.
8 changes: 8 additions & 0 deletions api/monitor/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ const (
AddonPhaseUnknown AddonPhase = "Unknown"
)

type OverviewProjectStatus int32

const (
OverviewProjectStatusNotFound OverviewProjectStatus = 0
OverviewProjectStatusError OverviewProjectStatus = -1
OverviewProjectStatusDisable OverviewProjectStatus = -2
)

// +genclient
// +genclient:nonNamespaced
// +genclient:onlyVerbs=create
Expand Down
9 changes: 5 additions & 4 deletions cmd/tke-installer/app/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1767,10 +1767,11 @@ func (t *TKE) installInfluxDB(ctx context.Context) error {

func (t *TKE) installTKEMonitorAPI(ctx context.Context) error {
options := map[string]interface{}{
"Replicas": t.Config.Replicas,
"Image": images.Get().TKEMonitorAPI.FullName(),
"EnableAuth": t.Para.Config.Auth.TKEAuth != nil,
"EnableAudit": t.auditEnabled(),
"Replicas": t.Config.Replicas,
"Image": images.Get().TKEMonitorAPI.FullName(),
"EnableAuth": t.Para.Config.Auth.TKEAuth != nil,
"EnableBusiness": t.businessEnabled(),
"EnableAudit": t.auditEnabled(),
}
if t.Para.Config.Auth.OIDCAuth != nil {
options["OIDCClientID"] = t.Para.Config.Auth.OIDCAuth.ClientID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ data:
api_server = "https://tke-platform-api"
api_server_client_config = "/app/conf/tke-platform-config.yaml"

{{- if .EnableBusiness }}
[client.business]
api_server = "https://tke-business-api"
api_server_client_config = "/app/conf/tke-business-config.yaml"
{{- end }}

tke-auth-webhook.yaml: |
apiVersion: v1
Expand Down Expand Up @@ -186,6 +188,8 @@ data:
user: admin-cert
name: tke
{{- if .EnableBusiness }}
tke-business-config.yaml: |
apiVersion: v1
kind: Config
Expand All @@ -205,6 +209,7 @@ data:
cluster: tke
user: admin-cert
name: tke
{{- end }}

tke-monitor-config.yaml: |
apiVersion: monitor.config.tkestack.io/v1
Expand Down
16 changes: 10 additions & 6 deletions cmd/tke-monitor-api/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,16 @@ func CreateConfigFromOptions(serverName string, opts *options.Options) (*Config,
if err != nil {
return nil, err
}
if !ok {
return nil, fmt.Errorf("failed to initialize client config of platform API server")
if !ok && opts.BusinessAPIClient.Required {
return nil, fmt.Errorf("failed to initialize client config of business API server")
}
businessClient, err := versionedclientset.NewForConfig(rest.AddUserAgent(businessAPIServerClientConfig, "tke-monitor-api"))
if err != nil {
return nil, err
var businessClientV1 businessversionedclient.BusinessV1Interface
if ok {
businessClient, err := versionedclientset.NewForConfig(rest.AddUserAgent(businessAPIServerClientConfig, "tke-monitor-api"))
if err != nil {
return nil, err
}
businessClientV1 = businessClient.BusinessV1()
}

return &Config{
Expand All @@ -189,7 +193,7 @@ func CreateConfigFromOptions(serverName string, opts *options.Options) (*Config,
VersionedSharedInformerFactory: versionedInformers,
StorageFactory: storageFactory,
PlatformClient: platformClient.PlatformV1(),
BusinessClient: businessClient.BusinessV1(),
BusinessClient: businessClientV1,
PrivilegedUsername: opts.Authentication.PrivilegedUsername,
MonitorConfig: monitorConfig,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/tke-monitor-api/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewOptions(serverName string) *Options {
Authentication: apiserveroptions.NewAuthenticationWithAPIOptions(),
Authorization: apiserveroptions.NewAuthorizationOptions(),
PlatformAPIClient: controlleroptions.NewAPIServerClientOptions("platform", true),
BusinessAPIClient: controlleroptions.NewAPIServerClientOptions("business", true),
BusinessAPIClient: controlleroptions.NewAPIServerClientOptions("business", false),
Audit: genericapiserveroptions.NewAuditOptions(),
}
}
Expand Down
20 changes: 15 additions & 5 deletions pkg/monitor/registry/overview/cluster/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,27 @@ func (r *REST) Create(ctx context.Context, obj runtime.Object, _ rest.ValidateOb
}
clusterOverview.Result = r.cacher.GetClusterOverviewResult(clusterIDs)

projectCount := 0
projectAbnormal := 0
if r.businessClient == nil {
log.Info("The client for Business API Server is not installed")
clusterOverview.Result.ProjectCount = int32(monitor.OverviewProjectStatusDisable)
clusterOverview.Result.ProjectAbnormal = int32(monitor.OverviewProjectStatusDisable)
return clusterOverview, nil
}

projectCount := int32(0)
projectAbnormal := int32(0)
if projectList, err := r.businessClient.Projects().List(ctx, listOptions); err == nil && projectList != nil {
projectCount = len(projectList.Items)
projectCount = int32(len(projectList.Items))
for _, prj := range projectList.Items {
if prj.Status.Phase == businessv1.ProjectFailed {
projectAbnormal++
}
}
} else {
projectCount = int32(monitor.OverviewProjectStatusError)
projectAbnormal = int32(monitor.OverviewProjectStatusError)
}
clusterOverview.Result.ProjectCount = int32(projectCount)
clusterOverview.Result.ProjectAbnormal = int32(projectAbnormal)
clusterOverview.Result.ProjectCount = projectCount
clusterOverview.Result.ProjectAbnormal = projectAbnormal
return clusterOverview, nil
}
4 changes: 3 additions & 1 deletion pkg/monitor/util/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ type Cacher interface {

type cacher struct {
sync.RWMutex
platformClient platformversionedclient.PlatformV1Interface
platformClient platformversionedclient.PlatformV1Interface

// businessClient is not required, and needed to determine if it's nil
businessClient businessversionedclient.BusinessV1Interface
clusterStatisticSet util.ClusterStatisticSet
clusterClientSets util.ClusterClientSets
Expand Down

0 comments on commit 0ff8557

Please sign in to comment.