Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove pulumi deplendency, use third_party instead #68

Merged
merged 1 commit into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-sql-driver/mysql v1.6.0
github.com/goccy/go-yaml v1.8.9
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/gonvenience/bunt v1.1.1
github.com/gonvenience/neat v1.3.0
github.com/gonvenience/term v1.0.0
Expand All @@ -38,11 +37,12 @@ require (
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/lucasb-eyer/go-colorful v1.0.3
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/hashstructure v1.0.0
github.com/nxadm/tail v1.4.8 // indirect
github.com/pkg/errors v0.9.1
github.com/pterm/pterm v0.12.42-0.20220427210824-6bb8c6e6cc77
github.com/pulumi/pulumi/sdk/v3 v3.24.0
github.com/sergi/go-diff v1.2.0
github.com/spf13/cobra v1.1.1
github.com/stretchr/objx v0.3.0 // indirect
Expand Down
49 changes: 0 additions & 49 deletions go.sum

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions pkg/kusionctl/cmd/init/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/AlecAivazis/survey/v2"
"github.com/pterm/pterm"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"

"kusionstack.io/kusion/pkg/log"
"kusionstack.io/kusion/pkg/scaffold"
)

Expand Down Expand Up @@ -77,7 +77,9 @@ func (o *InitOptions) Run() error {
return err
}
defer func() {
contract.IgnoreError(repo.Delete())
if err := repo.Delete(); err != nil {
log.Warnf("Explicitly ignoring and discarding error: %v", err)
}
}()

// List the templates from the repo.
Expand Down
2 changes: 1 addition & 1 deletion pkg/projectstack/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"os"
"path/filepath"

"github.com/pulumi/pulumi/sdk/v3/go/common/util/fsutil"
"k8s.io/apimachinery/pkg/util/sets"

"kusionstack.io/kusion/pkg/log"
"kusionstack.io/kusion/pkg/util/yaml"
"kusionstack.io/kusion/third_party/pulumi/fsutil"
)

// IsProject determine whether the given path is Project directory
Expand Down
3 changes: 2 additions & 1 deletion pkg/projectstack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"os"
"path/filepath"

"github.com/pulumi/pulumi/sdk/v3/go/common/util/fsutil"
"k8s.io/apimachinery/pkg/util/sets"

"kusionstack.io/kusion/pkg/log"
"kusionstack.io/kusion/pkg/util/yaml"
"kusionstack.io/kusion/third_party/pulumi/fsutil"
)

// IsStack determine whether the given path is Stack directory
Expand Down
29 changes: 19 additions & 10 deletions pkg/scaffold/external_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (
"text/template"

"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/gitutil"
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
"github.com/texttheater/golang-levenshtein/levenshtein"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"

"kusionstack.io/kusion/pkg/log"
"kusionstack.io/kusion/pkg/projectstack"
"kusionstack.io/kusion/pkg/util/io"
"kusionstack.io/kusion/pkg/util/kfile"
"kusionstack.io/kusion/third_party/pulumi/gitutil"
"kusionstack.io/kusion/third_party/pulumi/workspace"
)

// These are variables instead of constants in order that they can be set using the `-X`
Expand Down Expand Up @@ -238,7 +238,7 @@ func retrieveKusionTemplates(templateName string, online bool) (TemplateReposito
if os.IsNotExist(err) {
return TemplateRepository{}, newTemplateNotFoundError(templateDir, templateName)
}
contract.IgnoreError(err)
log.Warnf("Explicitly ignoring and discarding error: %v", err)
}
}

Expand Down Expand Up @@ -297,7 +297,9 @@ func GetTemplateDir(subDir string) (string, error) {
// newExistingFilesError returns a new error from a list of existing file names
// that would be overwritten.
func newExistingFilesError(existing []string) error {
contract.Assert(len(existing) > 0)
if len(existing) == 0 {
return errors.New("no existing files")
}

message := "creating this template will make changes to existing files:\n"

Expand All @@ -318,7 +320,7 @@ func newTemplateNotFoundError(templateDir string, templateName string) error {
// Attempt to read the directory to offer suggestions.
infos, err := ioutil.ReadDir(templateDir)
if err != nil {
contract.IgnoreError(err)
log.Errorf("ioutil.ReadDir(%s) error: %v", templateDir, err)
return errors.New(message)
}

Expand Down Expand Up @@ -431,8 +433,12 @@ func CopyTemplateFiles(
// walkFiles is a helper that walks the directories/files in a source directory
// and performs an action for each item.
func walkFiles(sourceDir string, destDir string, force bool, configMap map[string]interface{}) error {
contract.Require(sourceDir != "", "sourceDir")
contract.Require(destDir != "", "destDir")
if sourceDir == "" {
return errors.New("sourceDir cannot be empty")
}
if destDir == "" {
return errors.New("destDir cannot be empty")
}

// sub dir, eg: template/prod
if err := mkdirWithForce(destDir, force); err != nil {
Expand Down Expand Up @@ -550,8 +556,11 @@ func writeAllBytes(filename string, bytes []byte, overwrite bool, mode os.FileMo
if err != nil {
return err
}
defer contract.IgnoreClose(f)

defer func() {
if err := f.Close(); err != nil {
log.Warnf("Explicitly ignoring and discarding error: %v", err)
}
}()
_, err = f.Write(bytes)
return err
}
3 changes: 2 additions & 1 deletion pkg/scaffold/external_templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (

"bou.ke/monkey"
"github.com/jinzhu/copier"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/gitutil"
"github.com/stretchr/testify/assert"
"gopkg.in/src-d/go-git.v4/plumbing"

"kusionstack.io/kusion/third_party/pulumi/gitutil"
)

const (
Expand Down
6 changes: 4 additions & 2 deletions pkg/scaffold/loader.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package scaffold

import (
"errors"
"io/ioutil"
"sync"

"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"gopkg.in/yaml.v3"
)

Expand All @@ -22,7 +22,9 @@ type projectTemplateLoader struct {

// LoadProjectTemplate reads a project definition from a file.
func LoadProjectTemplate(path string) (*ProjectTemplate, error) {
contract.Require(path != "", "path")
if path == "" {
return nil, errors.New("path is empty")
}

return projectTemplateSingleton.load(path)
}
Expand Down
76 changes: 76 additions & 0 deletions third_party/pulumi/fsutil/walkup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2016-2018, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package fsutil

import (
"io/ioutil"
"os"
"path/filepath"
)

// WalkUp walks each file in path, passing the full path to `walkFn`. If walkFn returns true,
// this method returns the path that was passed to walkFn. Before visiting the parent directory,
// visitParentFn is called, if that returns false, WalkUp stops its search
func WalkUp(path string, walkFn func(string) bool, visitParentFn func(string) bool) (string, error) {
if visitParentFn == nil {
visitParentFn = func(dir string) bool { return true }
}

curr := pathDir(path)

for {
// visit each file
files, err := ioutil.ReadDir(curr)
if err != nil {
return "", err
}
for _, file := range files {
name := file.Name()
path := filepath.Join(curr, name)
if walkFn(path) {
return path, nil
}
}

// If we are at the root, stop walking
if isTop(curr) {
break
}

if !visitParentFn(curr) {
break
}

// visit the parent
curr = filepath.Dir(curr)
}

return "", nil
}

// pathDir returns the nearest directory to the given path (identity if a directory; parent otherwise).
func pathDir(path string) string {
// If the path is a file, we want the directory it is in
info, err := os.Stat(path)
if err != nil || info.IsDir() {
return path
}
return filepath.Dir(path)
}

// isTop returns true if the path represents the top of the filesystem.
func isTop(path string) bool {
return os.IsPathSeparator(path[len(path)-1])
}
Loading