Skip to content

Commit a70f803

Browse files
Merge pull request #18437 from wozniakjan/bz1538922/diagnostics/aggregatedlogging
Automatic merge from submit-queue (batch tested with PRs 18437, 18546, 18550, 18579). Bug 1538922 - Fix diagnostics for AggregatedLogging The `AssetConfig` section with the `loggingPublicURL` is being removed from the `masterConfig`, therefore, we need a different logic to obtain logging project name. Currently, no location can provide logging project nor `loggingPublicURL` so we make an assumption that logging is deployed by default to 'openshift-logging' with legacy fallback to 'logging'. Optionally user can override the behaior with `--logging-project=[project]` flag.
2 parents a585a17 + 7e2706c commit a70f803

File tree

5 files changed

+60
-84
lines changed

5 files changed

+60
-84
lines changed

contrib/completions/bash/oc

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zsh/oc

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/oc/admin/diagnostics/cluster.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ func (o DiagnosticsOptions) buildClusterDiagnostics(rawConfig *clientcmdapi.Conf
9494
var d types.Diagnostic
9595
switch diagnosticName {
9696
case agldiags.AggregatedLoggingName:
97-
d = agldiags.NewAggregatedLogging(o.MasterConfigLocation, kclusterClient, oauthClient.Oauth(), projectClient.Project(), routeClient.Route(), oauthorizationClient.Authorization(), appsClient.Apps(), securityClient.Security())
97+
p := o.ParameterizedDiagnostics[agldiags.AggregatedLoggingName].(*agldiags.AggregatedLogging).Project
98+
d = agldiags.NewAggregatedLogging(p, kclusterClient, oauthClient.Oauth(), projectClient.Project(), routeClient.Route(), oauthorizationClient.Authorization(), appsClient.Apps(), securityClient.Security())
9899
case clustdiags.NodeDefinitionsName:
99100
d = &clustdiags.NodeDefinitions{KubeClient: kclusterClient}
100101
case clustdiags.MasterNodeName:

pkg/oc/admin/diagnostics/diagnostics/cluster/aggregated_logging/diagnostic.go

+47-79
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package aggregated_logging
33
import (
44
"errors"
55
"fmt"
6-
"net/url"
76

87
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
98
"k8s.io/apimachinery/pkg/labels"
@@ -15,26 +14,24 @@ import (
1514
appstypedclient "github.com/openshift/origin/pkg/apps/generated/internalclientset/typed/apps/internalversion"
1615
authapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
1716
oauthorizationtypedclient "github.com/openshift/origin/pkg/authorization/generated/internalclientset/typed/authorization/internalversion"
18-
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
1917
oauthtypedclient "github.com/openshift/origin/pkg/oauth/generated/internalclientset/typed/oauth/internalversion"
20-
hostdiag "github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/host"
2118
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/log"
2219
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
2320
projecttypedclient "github.com/openshift/origin/pkg/project/generated/internalclientset/typed/project/internalversion"
2421
routesapi "github.com/openshift/origin/pkg/route/apis/route"
2522
routetypedclient "github.com/openshift/origin/pkg/route/generated/internalclientset/typed/route/internalversion"
2623
securityapi "github.com/openshift/origin/pkg/security/apis/security"
2724
securitytypedclient "github.com/openshift/origin/pkg/security/generated/internalclientset/typed/security/internalversion"
25+
kerrors "k8s.io/apimachinery/pkg/api/errors"
26+
"strings"
2827
)
2928

3029
// AggregatedLogging is a Diagnostic to check the configurations
3130
// and general integration of the OpenShift stack
3231
// for aggregating container logs
3332
// https://github.com/openshift/origin-aggregated-logging
3433
type AggregatedLogging struct {
35-
masterConfig *configapi.MasterConfig
36-
loggingURL string
37-
MasterConfigFile string
34+
Project string
3835
OAuthClientClient oauthtypedclient.OAuthClientsGetter
3936
ProjectClient projecttypedclient.ProjectsGetter
4037
RouteClient routetypedclient.RoutesGetter
@@ -54,13 +51,16 @@ const (
5451
openshiftValue = "openshift"
5552

5653
fluentdServiceAccountName = "aggregated-logging-fluentd"
54+
55+
flagLoggingProject = "logging-project"
5756
)
5857

5958
var loggingSelector = labels.Set{loggingInfraKey: "support"}
59+
var defaultLoggingProjects = []string{"openshift-logging", "logging"}
6060

6161
//NewAggregatedLogging returns the AggregatedLogging Diagnostic
6262
func NewAggregatedLogging(
63-
masterConfigFile string,
63+
project string,
6464
kclient kclientset.Interface,
6565
oauthClientClient oauthtypedclient.OAuthClientsGetter,
6666
projectClient projecttypedclient.ProjectsGetter,
@@ -70,10 +70,7 @@ func NewAggregatedLogging(
7070
sccClient securitytypedclient.SecurityContextConstraintsGetter,
7171
) *AggregatedLogging {
7272
return &AggregatedLogging{
73-
masterConfig: nil,
74-
// TODO this needs to be plumbed because the master-config no longer has it.
75-
loggingURL: "",
76-
MasterConfigFile: masterConfigFile,
73+
Project: project,
7774
OAuthClientClient: oauthClientClient,
7875
ProjectClient: projectClient,
7976
RouteClient: routeClient,
@@ -153,20 +150,30 @@ func (d *AggregatedLogging) Requirements() (client bool, host bool) {
153150
}
154151

155152
func (d *AggregatedLogging) Complete(logger *log.Logger) error {
156-
if len(d.MasterConfigFile) > 0 {
157-
var err error
158-
d.masterConfig, err = hostdiag.GetMasterConfig(d.MasterConfigFile, logger)
153+
if len(d.Project) > 0 {
154+
return nil
155+
}
156+
157+
// Check if any of the default logging projects are present in the cluster
158+
for _, project := range defaultLoggingProjects {
159+
d.Debug("AGL0031", fmt.Sprintf("Trying default logging project %q", project))
160+
_, err := d.ProjectClient.Projects().Get(project, metav1.GetOptions{})
159161
if err != nil {
160-
return err
162+
if kerrors.IsNotFound(err) {
163+
d.Debug("AGL0032", fmt.Sprintf("Project %q not found", project))
164+
continue
165+
}
166+
return fmt.Errorf("failed fetching one of the default logging projects %q: %v", project, err)
161167
}
168+
169+
d.Debug("AGL0033", fmt.Sprintf("Found default logging project %q", project))
170+
d.Project = project
171+
return nil
162172
}
163-
return nil
173+
return fmt.Errorf("default logging project not found, use '--%s' to specify logging project", flagLoggingProject)
164174
}
165175

166176
func (d *AggregatedLogging) CanRun() (bool, error) {
167-
if len(d.MasterConfigFile) == 0 || d.masterConfig == nil {
168-
return false, errors.New("No master config file was provided")
169-
}
170177
if d.OAuthClientClient == nil || d.ProjectClient == nil || d.RouteClient == nil || d.CRBClient == nil || d.DCClient == nil {
171178
return false, errors.New("Config must include a cluster-admin context to run this diagnostic")
172179
}
@@ -177,24 +184,33 @@ func (d *AggregatedLogging) CanRun() (bool, error) {
177184
}
178185

179186
func (d *AggregatedLogging) Check() types.DiagnosticResult {
180-
if len(d.loggingURL) == 0 {
187+
d.Debug("AGL0015", fmt.Sprintf("Trying diagnostics for project '%s'", d.Project))
188+
p, err := d.ProjectClient.Projects().Get(d.Project, metav1.GetOptions{})
189+
if err != nil {
190+
d.Error("AGL0018", err, fmt.Sprintf("There was an error retrieving project '%s' which is most likely a transient error: %s", d.Project, err))
181191
return d.result
182192
}
183-
184-
project := retrieveLoggingProject(d.result, d.loggingURL, d.ProjectClient, d.RouteClient)
185-
if len(project) != 0 {
186-
checkServiceAccounts(d, d, project)
187-
checkClusterRoleBindings(d, d, project)
188-
checkSccs(d, d, project)
189-
checkDeploymentConfigs(d, d, project)
190-
checkDaemonSets(d, d, project)
191-
checkServices(d, d, project)
192-
checkRoutes(d, d, project)
193-
checkKibana(d.result, d.RouteClient, d.OAuthClientClient, d.KubeClient, project)
193+
nodeSelector, ok := p.ObjectMeta.Annotations["openshift.io/node-selector"]
194+
if !ok || len(nodeSelector) != 0 {
195+
d.Warn("AGL0030", nil, fmt.Sprintf(projectNodeSelectorWarning, d.Project))
194196
}
197+
checkServiceAccounts(d, d, d.Project)
198+
checkClusterRoleBindings(d, d, d.Project)
199+
checkSccs(d, d, d.Project)
200+
checkDeploymentConfigs(d, d, d.Project)
201+
checkDaemonSets(d, d, d.Project)
202+
checkServices(d, d, d.Project)
203+
checkRoutes(d, d, d.Project)
204+
checkKibana(d, d.RouteClient, d.OAuthClientClient, d.KubeClient, d.Project)
195205
return d.result
196206
}
197207

208+
func (d *AggregatedLogging) AvailableParameters() []types.Parameter {
209+
return []types.Parameter{
210+
{flagLoggingProject, fmt.Sprintf("Project that has deployed aggregated logging. Default projects: %s", strings.Join(defaultLoggingProjects, " or ")), &d.Project, ""},
211+
}
212+
}
213+
198214
const projectNodeSelectorWarning = `
199215
The project '%[1]s' was found with either a missing or non-empty node selector annotation.
200216
This could keep Fluentd from running on certain nodes and collecting logs from the entire cluster.
@@ -207,51 +223,3 @@ and updating the annotation:
207223
'openshift.io/node-selector' : ""
208224
209225
`
210-
211-
func retrieveLoggingProject(r types.DiagnosticResult, loggingURL string, projectClient projecttypedclient.ProjectsGetter, routeClient routetypedclient.RoutesGetter) string {
212-
r.Debug("AGL0010", fmt.Sprintf("masterConfig.AssetConfig.LoggingPublicURL: '%s'", loggingURL))
213-
projectName := ""
214-
if len(loggingURL) == 0 {
215-
r.Debug("AGL0017", "masterConfig.AssetConfig.LoggingPublicURL is empty")
216-
return projectName
217-
}
218-
219-
loggingUrl, err := url.Parse(loggingURL)
220-
if err != nil {
221-
r.Error("AGL0011", err, fmt.Sprintf("Unable to parse the loggingPublicURL from the masterConfig '%s'", loggingURL))
222-
return projectName
223-
}
224-
225-
routeList, err := routeClient.Routes(metav1.NamespaceAll).List(metav1.ListOptions{LabelSelector: loggingSelector.AsSelector().String()})
226-
if err != nil {
227-
r.Error("AGL0012", err, fmt.Sprintf("There was an error while trying to find the route associated with '%s' which is probably transient: %s", loggingUrl, err))
228-
return projectName
229-
}
230-
231-
for _, route := range routeList.Items {
232-
r.Debug("AGL0013", fmt.Sprintf("Comparing URL to route.Spec.Host: %s", route.Spec.Host))
233-
if loggingUrl.Host == route.Spec.Host {
234-
if len(projectName) == 0 {
235-
projectName = route.ObjectMeta.Namespace
236-
r.Info("AGL0015", fmt.Sprintf("Found route '%s' matching logging URL '%s' in project: '%s'", route.ObjectMeta.Name, loggingUrl.Host, projectName))
237-
} else {
238-
r.Warn("AGL0019", nil, fmt.Sprintf("Found additional route '%s' matching logging URL '%s' in project: '%s'. This could mean you have multiple logging deployments.", route.ObjectMeta.Name, loggingUrl.Host, projectName))
239-
}
240-
}
241-
}
242-
if len(projectName) == 0 {
243-
message := fmt.Sprintf("Unable to find a route matching the loggingPublicURL defined in the master config '%s'. Check that the URL is correct and aggregated logging is deployed.", loggingUrl)
244-
r.Error("AGL0014", errors.New(message), message)
245-
return ""
246-
}
247-
project, err := projectClient.Projects().Get(projectName, metav1.GetOptions{})
248-
if err != nil {
249-
r.Error("AGL0018", err, fmt.Sprintf("There was an error retrieving project '%s' which is most likely a transient error: %s", projectName, err))
250-
return ""
251-
}
252-
nodeSelector, ok := project.ObjectMeta.Annotations["openshift.io/node-selector"]
253-
if !ok || len(nodeSelector) != 0 {
254-
r.Warn("AGL0030", nil, fmt.Sprintf(projectNodeSelectorWarning, projectName))
255-
}
256-
return projectName
257-
}

pkg/oc/admin/diagnostics/diagnostics/cluster/aggregated_logging/kibana.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
oauthapi "github.com/openshift/origin/pkg/oauth/apis/oauth"
1515
oauthtypedclient "github.com/openshift/origin/pkg/oauth/generated/internalclientset/typed/oauth/internalversion"
16-
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
1716
routetypedclient "github.com/openshift/origin/pkg/route/generated/internalclientset/typed/route/internalversion"
1817
)
1918

@@ -24,7 +23,7 @@ const (
2423
)
2524

2625
//checkKibana verifies the various integration points between Kibana and logging
27-
func checkKibana(r types.DiagnosticResult, routeClient routetypedclient.RoutesGetter, oauthClientClient oauthtypedclient.OAuthClientsGetter, kClient kclientset.Interface, project string) {
26+
func checkKibana(r diagnosticReporter, routeClient routetypedclient.RoutesGetter, oauthClientClient oauthtypedclient.OAuthClientsGetter, kClient kclientset.Interface, project string) {
2827
oauthclient, err := oauthClientClient.OAuthClients().Get(kibanaProxyOauthClientName, metav1.GetOptions{})
2928
if err != nil {
3029
r.Error("AGL0115", err, fmt.Sprintf("Error retrieving the OauthClient '%s': %s. Unable to check Kibana", kibanaProxyOauthClientName, err))
@@ -35,7 +34,7 @@ func checkKibana(r types.DiagnosticResult, routeClient routetypedclient.RoutesGe
3534
}
3635

3736
//checkKibanaSecret confirms the secret used by kibana matches that configured in the oauth client
38-
func checkKibanaSecret(r types.DiagnosticResult, kClient kclientset.Interface, project string, oauthclient *oauthapi.OAuthClient) {
37+
func checkKibanaSecret(r diagnosticReporter, kClient kclientset.Interface, project string, oauthclient *oauthapi.OAuthClient) {
3938
r.Debug("AGL0100", "Checking oauthclient secrets...")
4039
secret, err := kClient.Core().Secrets(project).Get(kibanaProxySecretName, metav1.GetOptions{})
4140
if err != nil {
@@ -56,7 +55,7 @@ func checkKibanaSecret(r types.DiagnosticResult, kClient kclientset.Interface, p
5655
}
5756

5857
//checkKibanaRoutesInOauthClient verifies the client contains the correct redirect uris
59-
func checkKibanaRoutesInOauthClient(r types.DiagnosticResult, routeClient routetypedclient.RoutesGetter, project string, oauthclient *oauthapi.OAuthClient) {
58+
func checkKibanaRoutesInOauthClient(r diagnosticReporter, routeClient routetypedclient.RoutesGetter, project string, oauthclient *oauthapi.OAuthClient) {
6059
r.Debug("AGL0141", "Checking oauthclient redirectURIs for the logging routes...")
6160
routeList, err := routeClient.Routes(project).List(metav1.ListOptions{LabelSelector: loggingSelector.AsSelector().String()})
6261
if err != nil {

0 commit comments

Comments
 (0)