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

feat: parse dev config mod's namespace and version form kcl.mod #959

Merged
merged 1 commit into from
Mar 26, 2024
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ help: ## This help message :)
# If you encounter an error like "panic: permission denied" on MacOS,
# please visit https://github.com/eisenxp/macos-golink-wrapper to find the solution.
test: ## Run the tests
go test -gcflags=all=-l -timeout=10m `go list $(SOURCE_PATHS)` ${TEST_FLAGS}
go test -gcflags="all=-l -N" -timeout=10m `go list $(SOURCE_PATHS)` ${TEST_FLAGS}

cover: ## Generates coverage report
go test -gcflags=all=-l -timeout=10m `go list $(SOURCE_PATHS)` -coverprofile $(COVER_FILE) ${TEST_FLAGS}
go test -gcflags="all=-l -N" -timeout=10m `go list $(SOURCE_PATHS)` -coverprofile $(COVER_FILE) ${TEST_FLAGS}

cover-html: ## Generates coverage report and displays it in the browser
go tool cover -html=$(COVER_FILE)
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/fluxcd/pkg/tar v0.4.0
github.com/go-git/go-git/v5 v5.11.0
github.com/go-sql-driver/mysql v1.7.0
github.com/go-test/deep v1.0.3
github.com/go-test/deep v1.0.8
github.com/goccy/go-yaml v1.11.3
github.com/gonvenience/bunt v1.1.1
github.com/gonvenience/neat v1.3.0
Expand Down Expand Up @@ -72,9 +72,9 @@ require (
k8s.io/component-base v0.27.2
k8s.io/kubectl v0.27.1
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
kcl-lang.io/kcl-go v0.8.1
kcl-lang.io/kcl-go v0.8.2
kcl-lang.io/kcl-plugin v0.5.0
kcl-lang.io/kpm v0.8.1
kcl-lang.io/kpm v0.8.3-0.20240321122901-fd054837ea5c
kusionstack.io/kube-api v0.1.1
sigs.k8s.io/controller-runtime v0.15.1
)
Expand Down Expand Up @@ -137,7 +137,7 @@ require (
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
kcl-lang.io/lib v0.8.1 // indirect
kcl-lang.io/lib v0.8.2 // indirect
oras.land/oras-go v1.2.4 // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
Expand Down Expand Up @@ -272,7 +272,7 @@ require (
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/goccy/go-yaml v1.11.3 h1:B3W9IdWbvrUu2OYQGwvU1nZtvMQJPBKgBUuweJjLj6I=
github.com/goccy/go-yaml v1.11.3/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
Expand Down Expand Up @@ -970,8 +970,8 @@ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
Expand Down Expand Up @@ -1749,12 +1749,12 @@ k8s.io/kubectl v0.27.1 h1:9T5c5KdpburYiW8XKQSH0Uly1kMNE90aGSnbYUZNdcA=
k8s.io/kubectl v0.27.1/go.mod h1:QsAkSmrRsKTPlAFzF8kODGDl4p35BIwQnc9XFhkcsy8=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kcl-lang.io/kcl-go v0.8.1 h1:gUm3IIe3UHNPWFwu5dym+0k7gwEy3WHAhswQ3aOgJZ8=
kcl-lang.io/kcl-go v0.8.1/go.mod h1:MByhCXOWNnmFlU/vUqnxO8r+fVtoPHxp9fN8D25Py9U=
kcl-lang.io/kcl-go v0.8.2 h1:XbF7NJ2dHXREmZx/dJSvEdMdaOM9NA8ePZj3LdcEZ34=
kcl-lang.io/kcl-go v0.8.2/go.mod h1:KLPIalP4jr19KUqnXWbe2sVNEMEH7EhnsXH+ihnTUQw=
kcl-lang.io/kcl-plugin v0.5.0 h1:eoh6y4l81rwA8yhJXU4hN7YmJeTUNB1nfYCP9OffSxc=
kcl-lang.io/kcl-plugin v0.5.0/go.mod h1:QnZ5OLcyBw5nOnHpChRHtvBq8wvjwiHu/ZZ8j1dfz48=
kcl-lang.io/lib v0.8.1 h1:MBDPvLE3wSEqdOoKJqCMUv5maWL3SKubBNU8ZPVirmo=
kcl-lang.io/lib v0.8.1/go.mod h1:ubsalGXxJaa5II/EsHmsI/tL2EluYHIcW+BwzQPt+uY=
kcl-lang.io/lib v0.8.2 h1:G8Fm+eHSMpVOSNJhd5T41XgoKZjysHRU290q6Xotepk=
kcl-lang.io/lib v0.8.2/go.mod h1:ubsalGXxJaa5II/EsHmsI/tL2EluYHIcW+BwzQPt+uY=
kusionstack.io/kube-api v0.1.1 h1:ieoZhaUfK78hsyQ7GsU6ZuxBAcVU+ZuKs7vedGkO8sI=
kusionstack.io/kube-api v0.1.1/go.mod h1:QIQrH+MK9xuV+mXCAkk6DN8z6b8oyf4XN0VRccmHH/k=
oras.land/oras-go v1.2.4 h1:djpBY2/2Cs1PV87GSJlxv4voajVOMZxqqtq9AB8YNvY=
Expand Down
5 changes: 4 additions & 1 deletion pkg/apis/core/group.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package core

const Group = "api.kusionstack.io"
const (
Group = "api.kusionstack.io"
BuiltinModulePrefix = "kam."
)
1 change: 0 additions & 1 deletion pkg/apis/core/v1/appconfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ type AppConfiguration struct {
// Workload defines how to run your application code.
Workload *workload.Workload `json:"workload" yaml:"workload"`
// Accessories defines a collection of accessories that will be attached to the workload.
// The key in this map represents the module source. e.g. kusionstack/mysql@v0.1.0
Accessories map[string]Accessory `json:"accessories,omitempty" yaml:"accessories,omitempty"`
// Labels and Annotations can be used to attach arbitrary metadata as key-value pairs to resources.
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
Expand Down
56 changes: 33 additions & 23 deletions pkg/apis/core/v1/workload/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@ package container
import (
"encoding/json"
"errors"
"fmt"

"gopkg.in/yaml.v2"

"kusionstack.io/kusion/pkg/apis/core"
)

const (
ProbePrefix = "v1.workload.container.probe."
TypeHTTP = core.BuiltinModulePrefix + ProbePrefix + "Http"
TypeExec = core.BuiltinModulePrefix + ProbePrefix + "Exec"
TypeTCP = core.BuiltinModulePrefix + ProbePrefix + "Tcp"
)

// Container describes how the App's tasks are expected to be run.
Expand Down Expand Up @@ -136,23 +146,23 @@ type LifecycleHandler struct {
// MarshalJSON implements the json.Marshaler interface for ProbeHandler.
func (p *ProbeHandler) MarshalJSON() ([]byte, error) {
switch p.Type {
case "Http":
case TypeHTTP:
return json.Marshal(struct {
TypeWrapper `json:",inline"`
*HTTPGetAction `json:",inline"`
}{
TypeWrapper: TypeWrapper{p.Type},
HTTPGetAction: p.HTTPGetAction,
})
case "Exec":
case TypeExec:
return json.Marshal(struct {
TypeWrapper `json:",inline"`
*ExecAction `json:",inline"`
}{
TypeWrapper: TypeWrapper{p.Type},
ExecAction: p.ExecAction,
})
case "Tcp":
case TypeTCP:
return json.Marshal(struct {
TypeWrapper `json:",inline"`
*TCPSocketAction `json:",inline"`
Expand All @@ -161,7 +171,7 @@ func (p *ProbeHandler) MarshalJSON() ([]byte, error) {
TCPSocketAction: p.TCPSocketAction,
})
default:
return nil, errors.New("unrecognized probe handler type")
return nil, fmt.Errorf("unrecognized probe handler type: %s", p.Type)
}
}

Expand All @@ -175,20 +185,20 @@ func (p *ProbeHandler) UnmarshalJSON(data []byte) error {

p.Type = probeType.Type
switch p.Type {
case "Http":
case TypeHTTP:
handler := &HTTPGetAction{}
err = json.Unmarshal(data, handler)
p.HTTPGetAction = handler
case "Exec":
case TypeExec:
handler := &ExecAction{}
err = json.Unmarshal(data, handler)
p.ExecAction = handler
case "Tcp":
case TypeTCP:
handler := &TCPSocketAction{}
err = json.Unmarshal(data, handler)
p.TCPSocketAction = handler
default:
return errors.New("unrecognized probe handler type")
return fmt.Errorf("unrecognized probe handler type: %s", p.Type)
}

return err
Expand All @@ -197,23 +207,23 @@ func (p *ProbeHandler) UnmarshalJSON(data []byte) error {
// MarshalYAML implements the yaml.Marshaler interface for ProbeHandler.
func (p *ProbeHandler) MarshalYAML() (interface{}, error) {
switch p.Type {
case "Http":
case TypeHTTP:
return struct {
TypeWrapper `yaml:",inline" json:",inline"`
HTTPGetAction `yaml:",inline" json:",inline"`
}{
TypeWrapper: TypeWrapper{Type: p.Type},
HTTPGetAction: *p.HTTPGetAction,
}, nil
case "Exec":
case TypeExec:
return struct {
TypeWrapper `yaml:",inline" json:",inline"`
ExecAction `yaml:",inline" json:",inline"`
}{
TypeWrapper: TypeWrapper{Type: p.Type},
ExecAction: *p.ExecAction,
}, nil
case "Tcp":
case TypeTCP:
return struct {
TypeWrapper `yaml:",inline" json:",inline"`
TCPSocketAction `yaml:",inline" json:",inline"`
Expand All @@ -236,20 +246,20 @@ func (p *ProbeHandler) UnmarshalYAML(unmarshal func(interface{}) error) error {

p.Type = probeType.Type
switch p.Type {
case "Http":
case TypeHTTP:
handler := &HTTPGetAction{}
err = unmarshal(handler)
p.HTTPGetAction = handler
case "Exec":
case TypeExec:
handler := &ExecAction{}
err = unmarshal(handler)
p.ExecAction = handler
case "Tcp":
case TypeTCP:
handler := &TCPSocketAction{}
err = unmarshal(handler)
p.TCPSocketAction = handler
default:
return errors.New("unrecognized probe handler type")
return fmt.Errorf("unrecognized probe handler type: %s", p.Type)
}

return err
Expand All @@ -258,15 +268,15 @@ func (p *ProbeHandler) UnmarshalYAML(unmarshal func(interface{}) error) error {
// MarshalJSON implements the json.Marshaler interface for LifecycleHandler.
func (l *LifecycleHandler) MarshalJSON() ([]byte, error) {
switch l.Type {
case "Http":
case TypeHTTP:
return json.Marshal(struct {
TypeWrapper `json:",inline"`
*HTTPGetAction `json:",inline"`
}{
TypeWrapper: TypeWrapper{l.Type},
HTTPGetAction: l.HTTPGetAction,
})
case "Exec":
case TypeExec:
return json.Marshal(struct {
TypeWrapper `json:",inline"`
*ExecAction `json:",inline"`
Expand All @@ -289,11 +299,11 @@ func (l *LifecycleHandler) UnmarshalJSON(data []byte) error {

l.Type = handlerType.Type
switch l.Type {
case "Http":
case TypeHTTP:
handler := &HTTPGetAction{}
err = json.Unmarshal(data, handler)
l.HTTPGetAction = handler
case "Exec":
case TypeExec:
handler := &ExecAction{}
err = json.Unmarshal(data, handler)
l.ExecAction = handler
Expand All @@ -307,15 +317,15 @@ func (l *LifecycleHandler) UnmarshalJSON(data []byte) error {
// MarshalYAML implements the yaml.Marshaler interface for LifecycleHandler.
func (l *LifecycleHandler) MarshalYAML() (interface{}, error) {
switch l.Type {
case "Http":
case TypeHTTP:
return struct {
TypeWrapper `yaml:",inline" json:",inline"`
HTTPGetAction `yaml:",inline" json:",inline"`
}{
TypeWrapper: TypeWrapper{Type: l.Type},
HTTPGetAction: *l.HTTPGetAction,
}, nil
case "Exec":
case TypeExec:
return struct {
TypeWrapper `yaml:",inline" json:",inline"`
ExecAction `yaml:",inline" json:",inline"`
Expand All @@ -338,11 +348,11 @@ func (l *LifecycleHandler) UnmarshalYAML(unmarshal func(interface{}) error) erro

l.Type = handlerType.Type
switch l.Type {
case "Http":
case TypeHTTP:
handler := &HTTPGetAction{}
err = unmarshal(handler)
l.HTTPGetAction = handler
case "Exec":
case TypeExec:
handler := &ExecAction{}
err = unmarshal(handler)
l.ExecAction = handler
Expand Down
Loading
Loading