Skip to content

Commit

Permalink
add friendly description to be shown as cli column
Browse files Browse the repository at this point in the history
  • Loading branch information
cppforlife committed Dec 2, 2019
1 parent 360fd0b commit f89ced1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
16 changes: 4 additions & 12 deletions config/crd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ spec:
served: true
storage: true
additionalPrinterColumns:
- name: Paused
type: boolean
description: Reconcilation is paused
JSONPath: .spec.paused
- name: DeployExitCode
type: integer
description: Exit code from last deploy
JSONPath: .Status.Deploy.exitCode
- name: DeployUpdatedAt
type: date
description: Last deploy finish time
JSONPath: .Status.Deploy.updatedAt
- name: Description
type: string
description: Friendly description
JSONPath: .status.friendlyDescription
- name: Age
type: date
description: |-
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kappctrl/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type AppStatus struct {

ObservedGeneration int64 `json:"observedGeneration"`
Conditions []AppCondition `json:"conditions"`

FriendlyDescription string `json:"friendlyDescription"`
}

type AppStatusFetch struct {
Expand Down
9 changes: 9 additions & 0 deletions pkg/app/app_reconcile.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"fmt"
"time"

"github.com/k14s/kapp-controller/pkg/apis/kappctrl/v1alpha1"
Expand All @@ -16,6 +17,7 @@ func (a *App) Reconcile() error {
case a.app.Spec.Canceled || a.app.Spec.Paused:
a.log.Info("App is canceled or paused, not reconciling")
a.markObservedLatest()
a.app.Status.FriendlyDescription = "Canceled/paused"
return a.updateStatus()

case a.app.DeletionTimestamp != nil:
Expand Down Expand Up @@ -199,6 +201,8 @@ func (a *App) setReconciling() {
Type: v1alpha1.Reconciling,
Status: corev1.ConditionTrue,
})

a.app.Status.FriendlyDescription = "Reconciling"
}

func (a *App) setReconcileCompleted(result exec.CmdRunResult) {
Expand All @@ -210,12 +214,14 @@ func (a *App) setReconcileCompleted(result exec.CmdRunResult) {
Status: corev1.ConditionTrue,
Message: result.ErrorStr(),
})
a.app.Status.FriendlyDescription = fmt.Sprintf("Reconcile failed: %s", result.ErrorStr())
} else {
a.app.Status.Conditions = append(a.app.Status.Conditions, v1alpha1.AppCondition{
Type: v1alpha1.ReconcileSucceeded,
Status: corev1.ConditionTrue,
Message: "",
})
a.app.Status.FriendlyDescription = "Reconcile succeeded"
}
}

Expand All @@ -226,6 +232,8 @@ func (a *App) setDeleting() {
Type: v1alpha1.Deleting,
Status: corev1.ConditionTrue,
})

a.app.Status.FriendlyDescription = "Deleting"
}

func (a *App) setDeleteCompleted(result exec.CmdRunResult) {
Expand All @@ -237,6 +245,7 @@ func (a *App) setDeleteCompleted(result exec.CmdRunResult) {
Status: corev1.ConditionTrue,
Message: result.ErrorStr(),
})
a.app.Status.FriendlyDescription = fmt.Sprintf("Delete failed: %s", result.ErrorStr())
} else {
// assume resource will be deleted, hence nothing to update
}
Expand Down
1 change: 1 addition & 0 deletions test/e2e/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ spec:
ExitCode: 0,
},
ObservedGeneration: 1,
FriendlyDescription: "Reconcile succeeded",
}

{
Expand Down
1 change: 1 addition & 0 deletions test/e2e/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ stringData:
ExitCode: 0,
},
ObservedGeneration: 1,
FriendlyDescription: "Reconcile succeeded",
}

{
Expand Down

0 comments on commit f89ced1

Please sign in to comment.