Skip to content

Commit

Permalink
package will now be listed, sorted by lastupdatedtime (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
viveksinghggits authored and life1347 committed Oct 1, 2019
1 parent b47b3ec commit 96ae708
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions pkg/apis/fission.io/v1/types.go
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions pkg/buildermgr/common.go
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"strings"
"time"

"github.com/dchest/uniuri"
"github.com/pkg/errors"
Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 16 additions & 7 deletions pkg/fission-cli/package.go
Expand Up @@ -29,8 +29,10 @@ import (
"os"
"path"
"path/filepath"
"sort"
"strings"
"text/tabwriter"
"time"

"github.com/dchest/uniuri"
"github.com/fission/fission/pkg/utils"
Expand Down Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 96ae708

Please sign in to comment.