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

fix: fix update bug when the dependency is from local path #214

Merged
merged 1 commit into from
Nov 15, 2023
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
6 changes: 5 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,11 @@ func (c *KpmClient) VendorDeps(kclPkg *pkg.KclPkg) error {

// FillDepInfo will fill registry information for a dependency.
func (c *KpmClient) FillDepInfo(dep *pkg.Dependency) error {
if dep.Source.Git == nil {
if dep.Source.Local != nil {
dep.LocalFullPath = dep.Source.Local.Path
return nil
}
if dep.Source.Oci != nil {
dep.Source.Oci.Reg = c.GetSettings().DefaultOciRegistry()
urlpath := utils.JoinPath(c.GetSettings().DefaultOciRepo(), dep.Name)
dep.Source.Oci.Repo = urlpath
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/cmd_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ func NewMetadataCmd(kpmcli *client.KpmClient) *cli.Command {
},
},
Action: func(c *cli.Context) error {
// acquire the lock of the package cache.
err := kpmcli.AcquirePackageCacheLock()
if err != nil {
return err
}

defer func() {
// release the lock of the package cache after the function returns.
releaseErr := kpmcli.ReleasePackageCacheLock()
if releaseErr != nil && err == nil {
err = releaseErr
}
}()

pwd, err := os.Getwd()
if err != nil {
return errors.InternalBug
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ func NewRunCmd(kpmcli *client.KpmClient) *cli.Command {
}

func KpmRun(c *cli.Context, kpmcli *client.KpmClient) error {
// acquire the lock of the package cache.
err := kpmcli.AcquirePackageCacheLock()
if err != nil {
return err
}

defer func() {
// release the lock of the package cache after the function returns.
releaseErr := kpmcli.ReleasePackageCacheLock()
if releaseErr != nil && err == nil {
err = releaseErr
}
}()

kclOpts := CompileOptionFromCli(c)
runEntry, errEvent := runner.FindRunEntryFrom(c.Args().Slice())
if errEvent != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd/cmd_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ func NewUpdateCmd(kpmcli *client.KpmClient) *cli.Command {
}

func KpmUpdate(c *cli.Context, kpmcli *client.KpmClient) error {
// acquire the lock of the package cache.
err := kpmcli.AcquirePackageCacheLock()
if err != nil {
return err
}

defer func() {
// release the lock of the package cache after the function returns.
releaseErr := kpmcli.ReleasePackageCacheLock()
if releaseErr != nil && err == nil {
err = releaseErr
}
}()

input_paths := c.Args().Slice()

pkg_paths := []string{}
Expand Down
4 changes: 4 additions & 0 deletions scripts/pull_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ if [ ! -d "./ghcr.io/kcl-lang/k8s/1.27" ]; then
$current_dir/bin/kpm pull k8s:1.27
fi

if [ ! -d "./ghcr.io/kcl-lang/helloworld" ]; then
$current_dir/bin/kpm pull helloworld
fi

cd "$current_dir"
6 changes: 6 additions & 0 deletions scripts/push_pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ $current_dir/bin/kpm push

cd "$current_dir"

# Push the package k8s/1.17 to the registry
cd ./scripts/pkg_in_reg/ghcr.io/kcl-lang/helloworld
$current_dir/bin/kpm push

cd "$current_dir"

# Push the package 'kcl1' depends on 'k8s' to the registry
cd ./scripts/pkg_in_reg/kcl1
$current_dir/bin/kpm push
Expand Down
27 changes: 25 additions & 2 deletions test/e2e/kpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,31 @@ var _ = ginkgo.Describe("Kpm CLI Testing", func() {
expectedStderr := ReplaceAllKeyByValue(ts.ExpectStderr, "<workspace>", workspace)

gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(stdout).To(gomega.Equal(expectedStdout))
gomega.Expect(stderr).To(gomega.Equal(expectedStderr))
gomega.Expect(stdout).To(gomega.ContainSubstring(expectedStdout))
gomega.Expect(stderr).To(gomega.ContainSubstring(expectedStderr))
})
}
})

ginkgo.Context("testing 'kpm update '", func() {
testSuitesRoot := filepath.Join(filepath.Join(filepath.Join(GetWorkDir(), TEST_SUITES_DIR), "kpm"), "kpm_update")
testSuites := LoadAllTestSuites(testSuitesRoot)
testDataRoot := filepath.Join(filepath.Join(GetWorkDir(), TEST_SUITES_DIR), "test_data")
for _, ts := range testSuites {
ts := ts
ginkgo.It(ts.GetTestSuiteInfo(), func() {
workspace := GetWorkspace()
CopyDir(filepath.Join(testDataRoot, ts.Name), filepath.Join(workspace, ts.Name))

input := ReplaceAllKeyByValue(ts.Input, "<workspace>", filepath.Join(workspace, ts.Name))
stdout, stderr, err := ExecKpmWithWorkDir(input, filepath.Join(workspace, ts.Name, "test_update"))

expectedStdout := ReplaceAllKeyByValue(ts.ExpectStdout, "<workspace>", workspace)
expectedStderr := ReplaceAllKeyByValue(ts.ExpectStderr, "<workspace>", workspace)

gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
gomega.Expect(stdout).To(gomega.ContainSubstring(expectedStdout))
gomega.Expect(stderr).To(gomega.ContainSubstring(expectedStderr))
})
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
KPM_HOME=""
KCLVM_VENDOR_HOME=""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kpm update
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "test_update"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
test_update_1 = { path = "./../test_update_1" }
helloworld = "0.1.1"
catalog = { git = "https://github.com/KusionStack/catalog.git", tag = "0.1.1" }
114 changes: 114 additions & 0 deletions test/e2e/test_suites/test_data/test_update_with_all/test_update/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import catalog.models.schema.v1 as ac
import catalog.models.schema.v1.trait as t
import catalog.models.schema.v1.workload as wl
import catalog.models.schema.v1.workload.container as c
import catalog.models.schema.v1.workload.container.probe as p
import catalog.models.schema.v1.workload.secret as sec
import catalog.models.schema.v1.workload.network as n
import catalog.models.schema.v1.monitoring as m

import test_update_1 as tu
import helloworld as oci_helloworld

local = tu.The_first_kcl_program
oci = oci_helloworld.The_first_kcl_program

# base.k declares reusable configurations for all stacks.
hello: ac.AppConfiguration {
workload: wl.Service {
containers: {
"nginx": c.Container {
image: "nginx:v1"
# Run the following command as defined
command: ["/bin/sh", "-c", "echo hi"]
# Extra arguments append to command defined above
args: ["/bin/sh", "-c", "echo hi"]
env: {
# An environment variable of name "env1" and value "VALUE" will be set
"env1": "VALUE"
# An environment variable of name "env2" and value of the key "key" in the
# secret named "sec-name" will be set.
"env2": "secret://sec-name/key"
}
# Run the command "/bin/sh -c echo hi", as defined above, in the directory "/tmp"
workingDir: "/tmp"
resources: {
"cpu": "2"
"memory": "4Gi"
}
# Configure a HTTP readiness probe
readinessProbe: p.Probe {
probeHandler: p.Http {
url: "http://localhost:80"
}
initialDelaySeconds: 10
}
}
}
secrets: {
"basic-auth": sec.Secret {
$type: "basic"
data: {
"username": "admin"
"password": "******"
}
}
}
replicas: 2
ports: [
n.Port {
type: "aliyun"
port: 80
targetPort: 8080
public: True
}
]
}
# Add the monitoring configuration backed by Prometheus
monitoring: m.Prometheus{
interval: "30s"
timeout: "15s"
path: "/metrics"
port: "web"
scheme: "http"
}
}

hellocollaset: ac.AppConfiguration {
workload: wl.Service {
type: "CollaSet"
containers: {
"nginx": c.Container {
image: "nginx:v1"
# Run the following command as defined
command: ["/bin/sh", "-c", "echo hi"]
# Extra arguments append to command defined above
args: ["/bin/sh", "-c", "echo hi"]
# Run the command "/bin/sh -c echo hi", as defined above, in the directory "/tmp"
workingDir: "/tmp"
}
}
ports: [
n.Port {
port: 80
}
]
}
opsRule: t.OpsRule {
maxUnavailable: "30%"
}
}

hellojob: ac.AppConfiguration {
workload: wl.Job {
containers: {
"busybox": c.Container {
image: "busybox:1.28"
# Run the following command as defined
command: ["/bin/sh", "-c", "echo hello"]
}
}
# Run every hour.
schedule: "0 * * * *"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "test_update_1"
edition = "0.0.1"
version = "0.0.1"

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello Local !'
Loading