diff --git a/pkg/apis/internal.acorn.io/v1/appimage.go b/pkg/apis/internal.acorn.io/v1/appimage.go index d44aecfcf..e960aaae0 100644 --- a/pkg/apis/internal.acorn.io/v1/appimage.go +++ b/pkg/apis/internal.acorn.io/v1/appimage.go @@ -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 { diff --git a/pkg/cli/builder/table/funcs.go b/pkg/cli/builder/table/funcs.go index ed612e110..302ca5b4b 100644 --- a/pkg/cli/builder/table/funcs.go +++ b/pkg/cli/builder/table/funcs.go @@ -42,7 +42,7 @@ var ( "defaultMemory": DefaultMemory, "ownerName": OwnerReferenceName, "imageName": ImageName, - "imageDigest": ImageDigest, + "imageCommit": ImageCommit, } ) @@ -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 } @@ -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 } diff --git a/pkg/cli/ps_test.go b/pkg/cli/ps_test.go index 4c2049602..e4cf789e3 100644 --- a/pkg/cli/ps_test.go +++ b/pkg/cli/ps_test.go @@ -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{ @@ -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{ diff --git a/pkg/cli/testdata/all/all_test.txt b/pkg/cli/testdata/all/all_test.txt index 55b9dffe1..6d5c370e5 100644 --- a/pkg/cli/testdata/all/all_test.txt +++ b/pkg/cli/testdata/all/all_test.txt @@ -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: diff --git a/pkg/cli/testdata/all/all_test_i.txt b/pkg/cli/testdata/all/all_test_i.txt index dbea12c6a..49bed5c20 100644 --- a/pkg/cli/testdata/all/all_test_i.txt +++ b/pkg/cli/testdata/all/all_test_i.txt @@ -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: diff --git a/pkg/openapi/generated/openapi_generated.go b/pkg/openapi/generated/openapi_generated.go index a38b4ec6b..4c4679fa7 100644 --- a/pkg/openapi/generated/openapi_generated.go +++ b/pkg/openapi/generated/openapi_generated.go @@ -10883,10 +10883,25 @@ func schema_pkg_apis_internalacornio_v1_VCS(ref common.ReferenceCallback) common Format: "", }, }, + "clean": { + SchemaProps: spec.SchemaProps{ + Description: "Clean a true value indicates the build contained no modified or untracked files according to git", + Type: []string{"boolean"}, + Format: "", + }, + }, "modified": { SchemaProps: spec.SchemaProps{ - Type: []string{"boolean"}, - Format: "", + Description: "Modified a true value indicates the build contained modified files according to git", + Type: []string{"boolean"}, + Format: "", + }, + }, + "untracked": { + SchemaProps: spec.SchemaProps{ + Description: "Untracked a true value indicates the build contained untracked files according to git", + Type: []string{"boolean"}, + Format: "", }, }, }, diff --git a/pkg/tables/tables.go b/pkg/tables/tables.go index a6ff93171..aa9505d7f 100644 --- a/pkg/tables/tables.go +++ b/pkg/tables/tables.go @@ -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}}"}, diff --git a/pkg/tags/tags.go b/pkg/tags/tags.go index 2a835a831..eb35639a9 100644 --- a/pkg/tags/tags.go +++ b/pkg/tags/tags.go @@ -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" diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index 7f704b4d0..c364c6b81 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -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