Skip to content

Commit

Permalink
feat: kusion support spec as input
Browse files Browse the repository at this point in the history
  • Loading branch information
妙明 committed Jul 21, 2023
1 parent 3c2fb72 commit 0b1e827
Show file tree
Hide file tree
Showing 9 changed files with 389 additions and 67 deletions.
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/aliyun/aliyun-oss-go-sdk v2.1.8+incompatible
github.com/aws/aws-sdk-go v1.42.35
github.com/blang/semver/v4 v4.0.0
github.com/bytedance/mockey v1.2.4
github.com/chai2010/gettext-go v1.0.2
github.com/davecgh/go-spew v1.1.1
github.com/didi/gendry v1.7.0
Expand Down Expand Up @@ -62,6 +63,14 @@ require (
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
golang.org/x/arch v0.1.0 // indirect
)

require (
atomicgo.dev/cursor v0.1.1 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/bytedance/mockey v1.2.4 h1:gvqdl3AqEdY3PFnne09Pn3uFGBE4qEUJH3emWOQJoi4=
github.com/bytedance/mockey v1.2.4/go.mod h1:+Jm/fzWZAuhEDrPXVjDf/jLM2BlLXJkwk94zf2JZ3X4=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -780,6 +782,7 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
Expand Down Expand Up @@ -858,6 +861,8 @@ go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI=
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff/go.mod h1:flIaEI6LNU6xOCD5PaJvn9wGP0agmIOqjrtsKGRguv4=
golang.org/x/arch v0.1.0 h1:oMxhUYsO9VsR1dcoVUjJjIGhx1LXol3989T/yZ59Xsw=
golang.org/x/arch v0.1.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
3 changes: 2 additions & 1 deletion pkg/cmd/apply/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ func (o *ApplyOptions) Run() error {
}

// generate Spec
sp, err := spec.GenerateSpecWithSpinner(&generator.Options{
sp, err := spec.GenerateSpec(&generator.Options{
SpecFile: o.SpecFile,
WorkDir: o.WorkDir,
Filenames: o.Filenames,
Settings: o.Settings,
Expand Down
39 changes: 37 additions & 2 deletions pkg/cmd/preview/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package preview

import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/pterm/pterm"

"github.com/pkg/errors"
compilecmd "kusionstack.io/kusion/pkg/cmd/compile"
"kusionstack.io/kusion/pkg/cmd/spec"
"kusionstack.io/kusion/pkg/cmd/util"
Expand Down Expand Up @@ -37,6 +38,7 @@ type PreviewFlags struct {
All bool
NoStyle bool
Output string
SpecFile string
IgnoreFields []string
}

Expand All @@ -57,6 +59,38 @@ func (o *PreviewOptions) Validate() error {
if o.Output != "" && o.Output != jsonOutput {
return errors.New("invalid output type, supported types: json")
}
if err := o.ValidateSpecFile(); err != nil {
return err
}
return nil
}

func (o *PreviewOptions) ValidateSpecFile() error {
if o.SpecFile == "" {
return nil
}
absSF, err := filepath.Abs(o.SpecFile)
if err != nil {
return err
}
fi, err := os.Stat(absSF)
if err != nil {
return err
}
if fi.IsDir() || !fi.Mode().IsRegular() {
return fmt.Errorf("spec file must be a regular file")
}
absWD, err := filepath.Abs(o.WorkDir)
if err != nil {
return err
}
rel, err := filepath.Rel(absWD, absSF)
if err != nil {
return err
}
if rel[:3] == ".."+string(filepath.Separator) {
return fmt.Errorf("spec file must be located in workDir's directory or its subdirectory")
}
return nil
}

Expand All @@ -78,7 +112,8 @@ func (o *PreviewOptions) Run() error {
}

// Get compile result
sp, err := spec.GenerateSpecWithSpinner(&generator.Options{
sp, err := spec.GenerateSpec(&generator.Options{
SpecFile: o.SpecFile,
WorkDir: o.WorkDir,
Filenames: o.Filenames,
Settings: o.Settings,
Expand Down
Loading

0 comments on commit 0b1e827

Please sign in to comment.