Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log Hive CD on install failures #4026

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 102 additions & 14 deletions pkg/cluster/gatherlogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"strings"

configv1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand All @@ -28,15 +31,16 @@ func (m *manager) gatherFailureLogs(ctx context.Context, runType string) {

s := []diagnosticStep{
{f: m.logClusterVersion, isJSON: true},
{f: m.logNodes, isJSON: true},
{f: m.logClusterOperators, isJSON: true},
{f: m.logIngressControllers, isJSON: true},
{f: m.logNodes, isJSON: false},
{f: m.logClusterOperators, isJSON: false},
{f: m.logIngressControllers, isJSON: false},
{f: m.logPodLogs, isJSON: false},
}

// only log serial consoles on an install, not on updates/adminUpdates
// only log serial consoles and Hive CD on an install, not on updates/adminUpdates
if runType == "install" {
s = append(s, diagnosticStep{f: d.LogVMSerialConsole, isJSON: false})
s = append(s, diagnosticStep{f: m.logClusterDeployment, isJSON: true})
}

for _, f := range s {
Expand Down Expand Up @@ -68,6 +72,21 @@ func (m *manager) gatherFailureLogs(ctx context.Context, runType string) {
}
}

func (m *manager) logClusterDeployment(ctx context.Context) (interface{}, error) {
if m.doc == nil || m.hiveClusterManager == nil {
return nil, nil
}

cd, err := m.hiveClusterManager.GetClusterDeployment(ctx, m.doc)
if err != nil {
return nil, err
}

cd.ManagedFields = nil

return cd, nil
}

func (m *manager) logClusterVersion(ctx context.Context) (interface{}, error) {
if m.configcli == nil {
return nil, nil
Expand All @@ -93,11 +112,30 @@ func (m *manager) logNodes(ctx context.Context) (interface{}, error) {
return nil, err
}

for i := range nodes.Items {
nodes.Items[i].ManagedFields = nil
lines := make([]string, 0)
errs := make([]error, 0)

for _, node := range nodes.Items {
node.ManagedFields = nil

nodeReady := corev1.ConditionUnknown
for _, condition := range node.Status.Conditions {
if condition.Type == corev1.NodeReady {
nodeReady = condition.Status
break
}
}
lines = append(lines, fmt.Sprintf("%s - Ready: %s", node.Name, nodeReady))

json, err := json.Marshal(node)
if err != nil {
errs = append(errs, err)
continue
}
m.log.Info(string(json))
}

return nodes.Items, nil
return strings.Join(lines, "\n"), errors.Join(errs...)
}

func (m *manager) logClusterOperators(ctx context.Context) (interface{}, error) {
Expand All @@ -110,11 +148,36 @@ func (m *manager) logClusterOperators(ctx context.Context) (interface{}, error)
return nil, err
}

for i := range cos.Items {
cos.Items[i].ManagedFields = nil
lines := make([]string, 0)
errs := make([]error, 0)

for _, co := range cos.Items {
co.ManagedFields = nil

coAvailable := configv1.ConditionUnknown
coProgressing := configv1.ConditionUnknown
coDegraded := configv1.ConditionUnknown
for _, condition := range co.Status.Conditions {
switch condition.Type {
case configv1.OperatorAvailable:
coAvailable = condition.Status
case configv1.OperatorProgressing:
coProgressing = condition.Status
case configv1.OperatorDegraded:
coDegraded = condition.Status
}
}
lines = append(lines, fmt.Sprintf("%s - Available: %s, Progressing: %s, Degraded: %s", co.Name, coAvailable, coProgressing, coDegraded))

json, err := json.Marshal(co)
if err != nil {
errs = append(errs, err)
continue
}
m.log.Infof(string(json))
}

return cos.Items, nil
return strings.Join(lines, "\n"), errors.Join(errs...)
}

func (m *manager) logIngressControllers(ctx context.Context) (interface{}, error) {
Expand All @@ -127,15 +190,40 @@ func (m *manager) logIngressControllers(ctx context.Context) (interface{}, error
return nil, err
}

for i := range ics.Items {
ics.Items[i].ManagedFields = nil
lines := make([]string, 0)
errs := make([]error, 0)

for _, ic := range ics.Items {
ic.ManagedFields = nil

icAvailable := operatorv1.ConditionUnknown
icProgressing := operatorv1.ConditionUnknown
icDegraded := operatorv1.ConditionUnknown
for _, condition := range ic.Status.Conditions {
switch condition.Type {
case operatorv1.OperatorStatusTypeAvailable:
icAvailable = condition.Status
case operatorv1.OperatorStatusTypeProgressing:
icProgressing = condition.Status
case operatorv1.OperatorStatusTypeDegraded:
icDegraded = condition.Status
}
}
lines = append(lines, fmt.Sprintf("%s - Available: %s, Progressing: %s, Degraded: %s", ic.Name, icAvailable, icProgressing, icDegraded))

json, err := json.Marshal(ic)
if err != nil {
errs = append(errs, err)
continue
}
m.log.Infof(string(json))
}

return ics.Items, nil
return strings.Join(lines, "\n"), errors.Join(errs...)
}

func (m *manager) logPodLogs(ctx context.Context) (interface{}, error) {
if m.operatorcli == nil {
if m.kubernetescli == nil {
return nil, nil
}

Expand Down
Loading
Loading