package will now be listed, sorted by lastupdatedtime (#1334)

This commit is contained in:
Vivek Singh
2019-10-01 15:30:51 +08:00
committed by Ta-Ching Chen
parent b47b3ecb70
commit 96ae708163
3 changed files with 25 additions and 9 deletions
+5
View File
@@ -17,6 +17,8 @@ limitations under the License.
package v1
import (
"time"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@@ -280,6 +282,9 @@ type (
// BuildLog stores build log during the compilation.
BuildLog string `json:"buildlog,omitempty"` // output of the build (errors etc)
// LastUpdateTimestamp will store the timestamp the package was last updated
LastUpdateTimestamp time.Time `json:"lastUpdateTimestamp,omitempty"`
}
// PackageRef is a reference to the package.
+4 -2
View File
@@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"strings"
"time"
"github.com/dchest/uniuri"
"github.com/pkg/errors"
@@ -124,8 +125,9 @@ func updatePackage(logger *zap.Logger, fissionClient *crd.FissionClient,
uploadResp *types.ArchiveUploadResponse) (*fv1.Package, error) {
pkg.Status = fv1.PackageStatus{
BuildStatus: status,
BuildLog: buildLogs,
BuildStatus: status,
BuildLog: buildLogs,
LastUpdateTimestamp: time.Now().UTC(),
}
if uploadResp != nil {
+16 -7
View File
@@ -29,8 +29,10 @@ import (
"os"
"path"
"path/filepath"
"sort"
"strings"
"text/tabwriter"
"time"
"github.com/dchest/uniuri"
"github.com/fission/fission/pkg/utils"
@@ -209,7 +211,8 @@ func updatePackage(client *client.Client, pkg *fv1.Package, envName, envNamespac
if needToBuild || forceRebuild {
// change into pending state to trigger package build
pkg.Status = fv1.PackageStatus{
BuildStatus: fv1.BuildStatusPending,
BuildStatus: fv1.BuildStatusPending,
LastUpdateTimestamp: time.Now().UTC(),
}
}
@@ -331,20 +334,25 @@ func pkgList(c *cli.Context) error {
return err
}
// sort the package list by lastUpdatedTimestamp
sort.Slice(pkgList, func(i, j int) bool {
return pkgList[i].Status.LastUpdateTimestamp.After(pkgList[j].Status.LastUpdateTimestamp)
})
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
fmt.Fprintf(w, "%v\t%v\t%v\n", "NAME", "BUILD_STATUS", "ENV")
fmt.Fprintf(w, "%v\t%v\t%v\t%v\n", "NAME", "BUILD_STATUS", "ENV", "LASTUPDATEDAT")
if listOrphans {
for _, pkg := range pkgList {
fnList, err := getFunctionsByPackage(client, pkg.Metadata.Name, pkg.Metadata.Namespace)
util.CheckErr(err, fmt.Sprintf("get functions sharing package %s", pkg.Metadata.Name))
if len(fnList) == 0 {
fmt.Fprintf(w, "%v\t%v\t%v\n", pkg.Metadata.Name, pkg.Status.BuildStatus, pkg.Spec.Environment.Name)
fmt.Fprintf(w, "%v\t%v\t%v\t%v\n", pkg.Metadata.Name, pkg.Status.BuildStatus, pkg.Spec.Environment.Name, pkg.Status.LastUpdateTimestamp.Format(time.RFC3339))
}
}
} else {
for _, pkg := range pkgList {
fmt.Fprintf(w, "%v\t%v\t%v\n", pkg.Metadata.Name,
pkg.Status.BuildStatus, pkg.Spec.Environment.Name)
fmt.Fprintf(w, "%v\t%v\t%v\t%v\n", pkg.Metadata.Name,
pkg.Status.BuildStatus, pkg.Spec.Environment.Name, pkg.Status.LastUpdateTimestamp.Format(time.RFC3339))
}
}
@@ -621,12 +629,13 @@ func createPackage(c *cli.Context, client *client.Client, pkgNamespace string, e
},
Spec: pkgSpec,
Status: fv1.PackageStatus{
BuildStatus: pkgStatus,
BuildStatus: pkgStatus,
LastUpdateTimestamp: time.Now().UTC(),
},
}
if len(specFile) > 0 {
// if a package sith the same spec exists, don't create a new spec file
// if a package with the same spec exists, don't create a new spec file
fr, err := readSpecs(cmdutils.GetSpecDir(urfavecli.Parse(c)))
util.CheckErr(err, "read specs")
if m := fr.SpecExists(pkg, false, true); m != nil {