Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Change ps output to have the git commit and auto upgrade setting
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Shepherd <[email protected]>
  • Loading branch information
ibuildthecloud committed Jul 21, 2023
1 parent 547b290 commit f870e8e
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 15 deletions.
7 changes: 6 additions & 1 deletion pkg/apis/internal.acorn.io/v1/appimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ type AppImage struct {
type VCS struct {
Remotes []string `json:"remotes,omitempty"`
Revision string `json:"revision,omitempty"`
Modified bool `json:"modified,omitempty"`
// Clean a true value indicates the build contained no modified or untracked files according to git
Clean bool `json:"clean,omitempty"`
// Modified a true value indicates the build contained modified files according to git
Modified bool `json:"modified,omitempty"`
// Untracked a true value indicates the build contained untracked files according to git
Untracked bool `json:"untracked,omitempty"`
}

type Platform struct {
Expand Down
18 changes: 13 additions & 5 deletions pkg/cli/builder/table/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
"defaultMemory": DefaultMemory,
"ownerName": OwnerReferenceName,
"imageName": ImageName,
"imageDigest": ImageDigest,
"imageCommit": ImageCommit,
}
)

Expand All @@ -62,6 +62,9 @@ func Trunc(s string) string {
if tags.SHAPattern.MatchString(s) && len(s) > 12 {
return s[:12]
}
if tags.CommitPattern.MatchString(s) && len(s) > 12 {
return s[:12]
}
return s
}

Expand Down Expand Up @@ -302,17 +305,22 @@ func ImageName(obj metav1.Object) string {
return ""
}

suffix := ""
if app.Status.ObservedAutoUpgrade {
suffix = "*"
}

if original, exists := app.ObjectMeta.Annotations[labels.AcornOriginalImage]; exists {
return original
return original + suffix
}
return app.Status.AppImage.Name
return app.Status.AppImage.Name + suffix
}

func ImageDigest(obj metav1.Object) string {
func ImageCommit(obj metav1.Object) string {
app, ok := obj.(*apiv1.App)
if !ok {
return ""
}

return strings.TrimPrefix(app.Status.AppImage.Digest, "sha256:")
return app.Status.AppImage.VCS.Revision
}
4 changes: 2 additions & 2 deletions pkg/cli/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestApp(t *testing.T) {
client: &testdata.MockClient{},
},
wantErr: false,
wantOut: "NAME IMAGE DIGEST HEALTHY UP-TO-DATE CREATED ENDPOINTS MESSAGE\nfound 292y ago \n",
wantOut: "NAME IMAGE COMMIT HEALTHY UP-TO-DATE CREATED ENDPOINTS MESSAGE\nfound 292y ago \n",
},
{
name: "acorn app found", fields: fields{
Expand All @@ -67,7 +67,7 @@ func TestApp(t *testing.T) {
client: &testdata.MockClient{},
},
wantErr: false,
wantOut: "NAME IMAGE DIGEST HEALTHY UP-TO-DATE CREATED ENDPOINTS MESSAGE\nfound 292y ago \n",
wantOut: "NAME IMAGE COMMIT HEALTHY UP-TO-DATE CREATED ENDPOINTS MESSAGE\nfound 292y ago \n",
},
{
name: "acorn app dne", fields: fields{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/testdata/all/all_test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

ACORNS:
NAME IMAGE DIGEST HEALTHY UP-TO-DATE CREATED ENDPOINTS MESSAGE
NAME IMAGE COMMIT HEALTHY UP-TO-DATE CREATED ENDPOINTS MESSAGE
found 292y ago

CONTAINERS:
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/testdata/all/all_test_i.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

ACORNS:
NAME IMAGE DIGEST HEALTHY UP-TO-DATE CREATED ENDPOINTS MESSAGE
NAME IMAGE COMMIT HEALTHY UP-TO-DATE CREATED ENDPOINTS MESSAGE
found 292y ago

CONTAINERS:
Expand Down
19 changes: 17 additions & 2 deletions pkg/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var (
App = [][]string{
{"Name", "{{ . | name }}"},
{"Image", "{{ . | imageName | trunc }}"},
{"Digest", "{{ . | imageDigest | trunc }}"},
{"Commit", "{{ . | imageCommit | trunc }}"},
{"Healthy", "Status.Columns.Healthy"},
{"Up-To-Date", "Status.Columns.UpToDate"},
{"Created", "{{ago .CreationTimestamp}}"},
Expand Down
1 change: 1 addition & 0 deletions pkg/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
var (
SHAPermissivePrefixPattern = regexp.MustCompile(`^[a-f\d]{3,64}$`)
SHAPattern = regexp.MustCompile(`^[a-f\d]{64}$`)
CommitPattern = regexp.MustCompile(`^[a-f\d]{40}$`)
DigestPattern = regexp.MustCompile(`^sha256:[a-f\d]{64}$`)
// Can't use the NoDefaultRegistry const from the images packages without causing a dependency cycle
noDefaultRegistry = "xxx-no-reg"
Expand Down
20 changes: 18 additions & 2 deletions pkg/vcs/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,25 @@ func VCS(path string) (result v1.VCS) {
return
}

var (
modified, untracked bool
)
for _, status := range s {
if status.Worktree == git.Untracked {
untracked = true
continue
}
if status.Worktree != git.Unmodified || status.Staging != git.Unmodified {
modified = true
continue
}
}

result = v1.VCS{
Revision: head.Hash().String(),
Modified: !s.IsClean(),
Revision: head.Hash().String(),
Clean: !modified && !untracked,
Modified: modified,
Untracked: untracked,
}

// Set optional remotes field
Expand Down

0 comments on commit f870e8e

Please sign in to comment.