Skip to content

Commit f524c8a

Browse files
obaydullahmhsArnobKumarSaha
authored andcommitted
Added summary
Signed-off-by: obaydullahmhs <obaydullah@appscode.com>
1 parent c39cb67 commit f524c8a

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

pkg/debug/gitops.go

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ type GitOps struct {
6161
Status GitOpsStatus `json:"status,omitempty" yaml:"status,omitempty"`
6262
}
6363

64+
type Ops struct {
65+
Status *opsapi.OpsRequestStatus `json:"status,omitempty" yaml:"status,omitempty"`
66+
}
67+
6468
type dbInfo struct {
6569
resource string
6670
name string
@@ -77,6 +81,7 @@ type gitOpsOpts struct {
7781
dir string
7882
errWriter *bytes.Buffer
7983
resMap map[string]string
84+
summary []string
8085
}
8186

8287
func GitOpsDebugCMD(f cmdutil.Factory) *cobra.Command {
@@ -127,6 +132,12 @@ func GitOpsDebugCMD(f cmdutil.Factory) *cobra.Command {
127132
if err != nil {
128133
log.Fatal(err)
129134
}
135+
136+
fmt.Println("Summary:")
137+
for _, line := range opts.summary {
138+
fmt.Println("- ", line)
139+
}
140+
fmt.Println("--------------- Done ---------------")
130141
},
131142
}
132143

@@ -158,6 +169,8 @@ func newGitOpsOpts(f cmdutil.Factory) *gitOpsOpts {
158169
config: config,
159170
errWriter: &bytes.Buffer{},
160171
kubeClient: cs,
172+
resMap: make(map[string]string),
173+
summary: make([]string, 0),
161174
}
162175
return opts
163176
}
@@ -181,6 +194,23 @@ func (g *gitOpsOpts) collectGitOpsDatabase() error {
181194
return err
182195
}
183196

197+
statuses := []string{
198+
string(gitops.ChangeRequestStatusInCurrent), string(gitops.ChangeRequestStatusPending),
199+
string(gitops.ChangeRequestStatusInProgress), string(gitops.ChangeRequestStatusFailed),
200+
}
201+
statusIdx := 0
202+
for _, info := range gitOpsObj.Status.GitOps.GitOpsInfo {
203+
for i := range statuses {
204+
if string(info.ChangeRequestStatus) == statuses[i] {
205+
if i > statusIdx {
206+
statusIdx = i
207+
}
208+
}
209+
}
210+
}
211+
212+
g.summary = append(g.summary, fmt.Sprintf("GitOps Database Status for: %s/%s is %s", g.db.namespace, g.db.name, statuses[statusIdx]))
213+
184214
if err := g.collectOpsRequests(gitOpsObj.Status); err != nil {
185215
return err
186216
}
@@ -210,19 +240,19 @@ func (g *gitOpsOpts) collectOpsRequests(gitOpsStatus GitOpsStatus) error {
210240
if err != nil {
211241
return err
212242
}
213-
var opsStatus opsapi.OpsRequestStatus
214-
err = runtime.DefaultUnstructuredConverter.FromUnstructured(uns.Object, &opsStatus)
243+
var ops Ops
244+
err = runtime.DefaultUnstructuredConverter.FromUnstructured(uns.Object, &ops)
215245
if err != nil {
216246
log.Fatalf("failed to convert unstructured to opsrequest obj: %v", err)
217247
return err
218248
}
219-
// if opsStatus.Phase == opsapi.OpsRequestPhaseFailed {
220-
// for _, cond := range opsStatus.Conditions {
221-
// if cond.Type == opsapi.Failed {
222-
// // TODO: ()
223-
// }
224-
// }
225-
// }
249+
if ops.Status.Phase == opsapi.OpsRequestPhaseFailed {
250+
for _, cond := range ops.Status.Conditions {
251+
if cond.Reason == opsapi.Failed {
252+
g.summary = append(g.summary, fmt.Sprintf("RequestName %s: %s", op.Name, cond.Message))
253+
}
254+
}
255+
}
226256
}
227257
}
228258

0 commit comments

Comments
 (0)