@ -49,11 +49,21 @@ The historical release set is printed as a formatted table, e.g:
2 Mon Oct 3 10 : 15 : 13 2016 superseded alpine - 0.1 .0 1.0 Upgraded successfully
2 Mon Oct 3 10 : 15 : 13 2016 superseded alpine - 0.1 .0 1.0 Upgraded successfully
3 Mon Oct 3 10 : 15 : 13 2016 superseded alpine - 0.1 .0 1.0 Rolled back to 2
3 Mon Oct 3 10 : 15 : 13 2016 superseded alpine - 0.1 .0 1.0 Rolled back to 2
4 Mon Oct 3 10 : 15 : 13 2016 deployed alpine - 0.1 .0 1.0 Upgraded successfully
4 Mon Oct 3 10 : 15 : 13 2016 deployed alpine - 0.1 .0 1.0 Upgraded successfully
Use ' -- show - rollback - revision ' to include a column showing the revision that was rolled back to :
$ helm history angry - bird -- show - rollback - revision
REVISION UPDATED STATUS CHART APP VERSION ROLLBACK DESCRIPTION
1 Mon Oct 3 10 : 15 : 13 2016 superseded alpine - 0.1 .0 1.0 Initial install
2 Mon Oct 3 10 : 15 : 13 2016 superseded alpine - 0.1 .0 1.0 Upgraded successfully
3 Mon Oct 3 10 : 15 : 13 2016 superseded alpine - 0.1 .0 1.0 2 Rolled back to 2
4 Mon Oct 3 10 : 15 : 13 2016 deployed alpine - 0.1 .0 1.0 Upgraded successfully
`
`
func newHistoryCmd ( cfg * action . Configuration , out io . Writer ) * cobra . Command {
func newHistoryCmd ( cfg * action . Configuration , out io . Writer ) * cobra . Command {
client := action . NewHistory ( cfg )
client := action . NewHistory ( cfg )
var outfmt output . Format
var outfmt output . Format
var showRollback bool
cmd := & cobra . Command {
cmd := & cobra . Command {
Use : "history RELEASE_NAME" ,
Use : "history RELEASE_NAME" ,
@ -73,34 +83,40 @@ func newHistoryCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return err
return err
}
}
if showRollback {
return outfmt . Write ( out , releaseHistoryWithRollback ( history ) )
}
return outfmt . Write ( out , history )
return outfmt . Write ( out , history )
} ,
} ,
}
}
f := cmd . Flags ( )
f := cmd . Flags ( )
f . IntVar ( & client . Max , "max" , 256 , "maximum number of revision to include in history" )
f . IntVar ( & client . Max , "max" , 256 , "maximum number of revision to include in history" )
f . BoolVar ( & showRollback , "show-rollback-revision" , false , "show the rollback revision column in table output" )
bindOutputFlag ( cmd , & outfmt )
bindOutputFlag ( cmd , & outfmt )
return cmd
return cmd
}
}
type releaseInfo struct {
type releaseInfo struct {
Revision int ` json:"revision" `
Revision int ` json:"revision" `
Updated time . Time ` json:"updated,omitzero" `
Updated time . Time ` json:"updated,omitzero" `
Status string ` json:"status" `
Status string ` json:"status" `
Chart string ` json:"chart" `
Chart string ` json:"chart" `
AppVersion string ` json:"app_version" `
AppVersion string ` json:"app_version" `
Description string ` json:"description" `
RollbackRevision int ` json:"rollback_revision,omitempty" `
Description string ` json:"description" `
}
}
// releaseInfoJSON is used for custom JSON marshaling/unmarshaling
// releaseInfoJSON is used for custom JSON marshaling/unmarshaling
type releaseInfoJSON struct {
type releaseInfoJSON struct {
Revision int ` json:"revision" `
Revision int ` json:"revision" `
Updated * time . Time ` json:"updated,omitempty" `
Updated * time . Time ` json:"updated,omitempty" `
Status string ` json:"status" `
Status string ` json:"status" `
Chart string ` json:"chart" `
Chart string ` json:"chart" `
AppVersion string ` json:"app_version" `
AppVersion string ` json:"app_version" `
Description string ` json:"description" `
RollbackRevision int ` json:"rollback_revision,omitempty" `
Description string ` json:"description" `
}
}
// UnmarshalJSON implements the json.Unmarshaler interface.
// UnmarshalJSON implements the json.Unmarshaler interface.
@ -139,6 +155,7 @@ func (r *releaseInfo) UnmarshalJSON(data []byte) error {
r . Status = tmp . Status
r . Status = tmp . Status
r . Chart = tmp . Chart
r . Chart = tmp . Chart
r . AppVersion = tmp . AppVersion
r . AppVersion = tmp . AppVersion
r . RollbackRevision = tmp . RollbackRevision
r . Description = tmp . Description
r . Description = tmp . Description
return nil
return nil
@ -148,11 +165,12 @@ func (r *releaseInfo) UnmarshalJSON(data []byte) error {
// It omits zero-value time fields from the JSON output.
// It omits zero-value time fields from the JSON output.
func ( r releaseInfo ) MarshalJSON ( ) ( [ ] byte , error ) {
func ( r releaseInfo ) MarshalJSON ( ) ( [ ] byte , error ) {
tmp := releaseInfoJSON {
tmp := releaseInfoJSON {
Revision : r . Revision ,
Revision : r . Revision ,
Status : r . Status ,
Status : r . Status ,
Chart : r . Chart ,
Chart : r . Chart ,
AppVersion : r . AppVersion ,
AppVersion : r . AppVersion ,
Description : r . Description ,
RollbackRevision : r . RollbackRevision ,
Description : r . Description ,
}
}
if ! r . Updated . IsZero ( ) {
if ! r . Updated . IsZero ( ) {
@ -181,6 +199,30 @@ func (r releaseHistory) WriteTable(out io.Writer) error {
return output . EncodeTable ( out , tbl )
return output . EncodeTable ( out , tbl )
}
}
// releaseHistoryWithRollback wraps releaseHistory to include the rollback column in table output.
type releaseHistoryWithRollback releaseHistory
func ( r releaseHistoryWithRollback ) WriteJSON ( out io . Writer ) error {
return output . EncodeJSON ( out , releaseHistory ( r ) )
}
func ( r releaseHistoryWithRollback ) WriteYAML ( out io . Writer ) error {
return output . EncodeYAML ( out , releaseHistory ( r ) )
}
func ( r releaseHistoryWithRollback ) WriteTable ( out io . Writer ) error {
tbl := uitable . New ( )
tbl . AddRow ( "REVISION" , "UPDATED" , "STATUS" , "CHART" , "APP VERSION" , "ROLLBACK" , "DESCRIPTION" )
for _ , item := range r {
rollback := ""
if item . RollbackRevision > 0 {
rollback = strconv . Itoa ( item . RollbackRevision )
}
tbl . AddRow ( item . Revision , item . Updated . Format ( time . ANSIC ) , item . Status , item . Chart , item . AppVersion , rollback , item . Description )
}
return output . EncodeTable ( out , tbl )
}
func getHistory ( client * action . History , name string ) ( releaseHistory , error ) {
func getHistory ( client * action . History , name string ) ( releaseHistory , error ) {
histi , err := client . Run ( name )
histi , err := client . Run ( name )
if err != nil {
if err != nil {
@ -217,11 +259,12 @@ func getReleaseHistory(rls []*release.Release) (history releaseHistory) {
a := formatAppVersion ( r . Chart )
a := formatAppVersion ( r . Chart )
rInfo := releaseInfo {
rInfo := releaseInfo {
Revision : v ,
Revision : v ,
Status : s ,
Status : s ,
Chart : c ,
Chart : c ,
AppVersion : a ,
AppVersion : a ,
Description : d ,
RollbackRevision : r . Info . RollbackRevision ,
Description : d ,
}
}
if ! r . Info . LastDeployed . IsZero ( ) {
if ! r . Info . LastDeployed . IsZero ( ) {
rInfo . Updated = r . Info . LastDeployed
rInfo . Updated = r . Info . LastDeployed