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: support kusion modules #901

Closed
wants to merge 16 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ linters:
- predeclared
- stylecheck
- tparallel
- typecheck
# - typecheck
- unconvert
- whitespace
# - wsl
Expand Down
179 changes: 0 additions & 179 deletions docs/design/appconfiguration_generator.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/design/kusion_module/kusion_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ service Module {
type Intent.Resource struct {
...
// Add a new field to represent patchers
Patchers []Patcher
Patcher Patcher
}

// Kusion will patch these fields into the workload corresponding fields
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.25.8
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.24.2
github.com/blang/semver/v4 v4.0.0
github.com/bytedance/mockey v1.2.4
github.com/bytedance/mockey v1.2.10
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
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd h1:rFt+Y/IK1aEZ
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b h1:otBG+dV+YK+Soembjv71DPz3uX/V/6MMlSyD9JBQ6kQ=
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0 h1:nvj0OLI3YqYXer/kZD8Ri1aaunCxIEsOst1BVJswV0o=
github.com/bwesterb/go-ristretto v1.2.3/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/bytedance/mockey v1.2.10 h1:4JlMpkm7HMXmTUtItid+iCu2tm61wvq+ca1X2u7ymzE=
github.com/bytedance/mockey v1.2.10/go.mod h1:bNrUnI1u7+pAc0TYDgPATM+wF2yzHxmNH+iDXg4AOCU=
github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c=
github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -737,7 +737,6 @@ 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.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
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=
Expand Down Expand Up @@ -1010,7 +1009,6 @@ oras.land/oras-go v1.2.3 h1:v8PJl+gEAntI1pJ/LCrDgsuk+1PKVavVEPsYIHFE5uY=
oras.land/oras-go v1.2.3/go.mod h1:M/uaPdYklze0Vf3AakfarnpoEckvw0ESbRdN8Z1vdJg=
oras.land/oras-go/v2 v2.3.0 h1:lqX1aXdN+DAmDTKjiDyvq85cIaI4RkIKp/PghWlAGIU=
oras.land/oras-go/v2 v2.3.0/go.mod h1:GeAwLuC4G/JpNwkd+bSZ6SkDMGaaYglt6YK2WvZP7uQ=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
sigs.k8s.io/controller-runtime v0.15.1 h1:9UvgKD4ZJGcj24vefUFgZFP3xej/3igL9BsOUTb/+4c=
sigs.k8s.io/controller-runtime v0.15.1/go.mod h1:7ngYvp1MLT+9GeZ+6lH3LOlcHkp/+tzA/fmHa4iq9kk=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
Expand Down
22 changes: 0 additions & 22 deletions pkg/apis/core/v1/intent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,3 @@ type Intent struct {
// Resources is the list of Resource this Intent contains.
Resources Resources `json:"resources" yaml:"resources"`
}

type Resources []Resource

// Resource is the representation of a resource in the state.
type Resource struct {
// ID is the unique key of this resource in the whole State.
// ApiVersion:Kind:Namespace:Name is an idiomatic way for Kubernetes resources.
// providerNamespace:providerName:resourceType:resourceName for Terraform resources
ID string `json:"id" yaml:"id"`

// Type represents all Runtimes we supported like Kubernetes and Terraform
Type Type `json:"type" yaml:"type"`

// Attributes represents all specified attributes of this resource
Attributes map[string]interface{} `json:"attributes" yaml:"attributes"`

// DependsOn contains all resources this resource depends on
DependsOn []string `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`

// Extensions specifies arbitrary metadata of this resource
Extensions map[string]interface{} `json:"extensions,omitempty" yaml:"extensions,omitempty"`
}
40 changes: 39 additions & 1 deletion pkg/apis/core/v1/resource.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
package v1

import "encoding/json"
import (
"encoding/json"

v1 "k8s.io/api/core/v1"
)

// Resource is the representation of a resource in the state.
type Resource struct {

Check failure on line 10 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

other declaration of Resource

Check failure on line 10 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

other declaration of Resource

Check failure on line 10 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

other declaration of Resource

Check failure on line 10 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

other declaration of Resource

Check failure on line 10 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

other declaration of Resource

Check failure on line 10 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

other declaration of Resource
// ID is the unique key of this resource in the whole State.
// ApiVersion:Kind:Namespace:Name is an idiomatic way for Kubernetes resources.
// providerNamespace:providerName:resourceType:resourceName for Terraform resources
ID string `json:"id" yaml:"id"`

// Type represents all Runtimes we supported like Kubernetes and Terraform
Type Type `json:"type" yaml:"type"`

// Attributes represents all specified attributes of this resource
Attributes map[string]interface{} `json:"attributes" yaml:"attributes"`

// DependsOn contains all resources this resource depends on
DependsOn []string `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`

// Patcher contains fields should be patched into the workload corresponding fields
Patcher *Patcher `json:"patcher,omitempty" yaml:"patcher,omitempty"`

// Extensions specifies arbitrary metadata of this resource
Extensions map[string]interface{} `json:"extensions,omitempty" yaml:"extensions,omitempty"`
}

type Patcher struct {

Check failure on line 32 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

other declaration of Patcher (typecheck)

Check failure on line 32 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

other declaration of Patcher

Check failure on line 32 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

other declaration of Patcher (typecheck)

Check failure on line 32 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

other declaration of Patcher

Check failure on line 32 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

other declaration of Patcher

Check failure on line 32 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

other declaration of Patcher
// Environments represent the environment variables patched to all containers in the workload.
Environments []v1.EnvVar `json:"environments" yaml:"environments"`
// Labels represent the labels patched to both the workload and pod.
Labels map[string]string `json:"labels" yaml:"labels"`
// Annotations represent the annotations patched to both the workload and pod.
Annotations map[string]string `json:"annotations" yaml:"annotations"`
}

type Resources []Resource

Check failure on line 41 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

other declaration of Resources

Check failure on line 41 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

other declaration of Resources

Check failure on line 41 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

other declaration of Resources

Check failure on line 41 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

other declaration of Resources

Check failure on line 41 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

other declaration of Resources

Check failure on line 41 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

other declaration of Resources

Check failure on line 41 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

other declaration of Resources

Check failure on line 41 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

other declaration of Resources

func (r *Resource) ResourceKey() string {

Check failure on line 43 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

Resources redeclared in this block

Check failure on line 43 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

Resources redeclared in this block

Check failure on line 43 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

Resources redeclared in this block

Check failure on line 43 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

Resources redeclared in this block

Check failure on line 43 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

Resources redeclared in this block

Check failure on line 43 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

Resources redeclared in this block

Check failure on line 43 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

Resources redeclared in this block

Check failure on line 43 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

Resources redeclared in this block
return r.ID
}

Check failure on line 46 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

Resource redeclared in this block

Check failure on line 46 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

Resource redeclared in this block

Check failure on line 46 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

Resource redeclared in this block

Check failure on line 46 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

Resource redeclared in this block

Check failure on line 46 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

Resource redeclared in this block

Check failure on line 46 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

Resource redeclared in this block
// DeepCopy return a copy of resource
func (r *Resource) DeepCopy() *Resource {
var out Resource
Expand All @@ -27,7 +65,7 @@

// GVKIndex returns a map of GVK to resources, for now, only Kubernetes resources.
func (rs Resources) GVKIndex() map[string][]*Resource {
m := make(map[string][]*Resource)

Check failure on line 68 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

Patcher redeclared in this block

Check failure on line 68 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

Patcher redeclared in this block

Check failure on line 68 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Golang Lint

Patcher redeclared in this block

Check failure on line 68 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

Patcher redeclared in this block

Check failure on line 68 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / Unit tests with coverage

Patcher redeclared in this block

Check failure on line 68 in pkg/apis/core/v1/resource.go

View workflow job for this annotation

GitHub Actions / e2e test

Patcher redeclared in this block
for i := range rs {
resource := &rs[i]
if resource.Type != Kubernetes {
Expand Down
53 changes: 53 additions & 0 deletions pkg/apis/core/v1/state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package v1

import (
"time"

"kusionstack.io/kusion/pkg/version"
)

// State is a record of an operation's result. It is a mapping between resources in KCL and the actual infra
// resource and often used as a datasource for 3-way merge/diff in operations like Apply or Preview.
type State struct {
// State ID
ID int64 `json:"id" yaml:"id"`

// Project name
Project string `json:"project" yaml:"project"`

// Stack name
Stack string `json:"stack" yaml:"stack"`

// Workspace name
Workspace string `json:"workspace" yaml:"workspace"`

// State version
Version int `json:"version" yaml:"version"`

// KusionVersion represents the Kusion's version when this State is created
KusionVersion string `json:"kusionVersion" yaml:"kusionVersion"`

// Serial is an auto-increase number that represents how many times this State is modified
Serial uint64 `json:"serial" yaml:"serial"`

// Operator represents the person who triggered this operation
Operator string `json:"operator,omitempty" yaml:"operator,omitempty"`

// Resources records all resources in this operation
Resources Resources `json:"resources" yaml:"resources"`

// CreateTime is the time State is created
CreateTime time.Time `json:"createTime" yaml:"createTime"`

// ModifiedTime is the time State is modified each time
ModifiedTime time.Time `json:"modifiedTime,omitempty" yaml:"modifiedTime,omitempty"`
}

func NewState() *State {
s := &State{
KusionVersion: version.ReleaseVersion(),
Version: 1,
Resources: []Resource{},
}
return s
}
Loading
Loading