Skip to content

Commit 6b9c2cd

Browse files
authored
feat: support runtime configurations in workspace (#1211)
1 parent a89353c commit 6b9c2cd

File tree

18 files changed

+237
-38
lines changed

18 files changed

+237
-38
lines changed

pkg/apis/api.kusion.io/v1/types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type Workspace struct {
9292
// SecretStore represents a secure external location for storing secrets.
9393
SecretStore *SecretStore `yaml:"secretStore,omitempty" json:"secretStore,omitempty"`
9494

95-
// Context contains workspace-level configurations, such as topologies, server endpoints, metadata, etc.
95+
// Context contains workspace-level configurations, such as runtimes, topologies, and metadata, etc.
9696
Context GenericConfig `yaml:"context,omitempty" json:"context,omitempty"`
9797
}
9898

@@ -475,6 +475,9 @@ const (
475475
EnvAwsSecretAccessKey = "AWS_SECRET_ACCESS_KEY"
476476
EnvAwsDefaultRegion = "AWS_DEFAULT_REGION"
477477
EnvAwsRegion = "AWS_REGION"
478+
EnvAlicloudAccessKey = "ALICLOUD_ACCESS_KEY"
479+
EnvAlicloudSecretKey = "ALICLOUD_SECRET_KEY"
480+
EnvAlicloudRegion = "ALICLOUD_REGION"
478481
)
479482

480483
// BackendConfigs contains the configuration of multiple backends and the current backend.
@@ -861,6 +864,8 @@ type Spec struct {
861864
Resources Resources `yaml:"resources" json:"resources"`
862865
// SecretSore represents a external secret store location for storing secrets.
863866
SecretStore *SecretStore `yaml:"secretStore" json:"secretStore"`
867+
// Context contains workspace-level configurations, such as runtimes, topologies, and metadata, etc.
868+
Context GenericConfig `yaml:"context" json:"context"`
864869
}
865870

866871
// State is a record of an operation's result. It is a mapping between resources in KCL and the actual

pkg/cmd/apply/apply.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ func Watch(
713713
watchErrCh <- *err
714714
}()
715715
// Init the runtimes according to the resource types.
716-
runtimes, s := runtimeinit.Runtimes(toBeWatched)
716+
runtimes, s := runtimeinit.Runtimes(*rel.Spec)
717717
if v1.IsErr(s) {
718718
panic(fmt.Errorf("failed to init runtimes: %s", s.String()))
719719
}

pkg/engine/operation/apply.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ func (ao *ApplyOperation) Apply(req *ApplyRequest) (rsp *ApplyResponse, s v1.Sta
7171
stateResourceIndex[k] = v
7272
}
7373

74-
resources := req.Release.Spec.Resources
75-
resources = append(resources, priorState.Resources...)
76-
runtimesMap, s := runtimeinit.Runtimes(resources)
74+
runtimesMap, s := runtimeinit.Runtimes(*req.Release.Spec)
7775
if v1.IsErr(s) {
7876
return nil, s
7977
}

pkg/engine/operation/apply_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func TestApplyOperation_Apply(t *testing.T) {
148148
return nil
149149
}).Build()
150150
mockey.Mock(runtimeinit.Runtimes).To(func(
151-
resources apiv1.Resources,
151+
spec apiv1.Spec,
152152
) (map[apiv1.Type]runtime.Runtime, v1.Status) {
153153
return map[apiv1.Type]runtime.Runtime{runtime.Kubernetes: &kubernetes.KubernetesRuntime{}}, nil
154154
}).Build()

pkg/engine/operation/destory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (do *DestroyOperation) Destroy(req *DestroyRequest) (rsp *DestroyResponse,
4848

4949
// only destroy resources we have recorded
5050
resources := priorState.Resources
51-
runtimesMap, s := runtimeinit.Runtimes(resources)
51+
runtimesMap, s := runtimeinit.Runtimes(*req.Release.Spec)
5252
if v1.IsErr(s) {
5353
return nil, s
5454
}

pkg/engine/operation/graph/resource_node.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (rn *ResourceNode) replaceK8sSecretRefs(o *models.Operation) v1.Status {
106106
continue
107107
}
108108

109-
externalSecretRef, err := parseExternalSecretDataRef(ref)
109+
externalSecretRef, err := ParseExternalSecretDataRef(ref)
110110
if err != nil {
111111
return v1.NewErrorStatus(err)
112112
}
@@ -513,8 +513,8 @@ func ReplaceRef(
513513
return result, v, nil
514514
}
515515

516-
// parseExternalSecretDataRef knows how to parse the remote data ref string, returns the corresponding ExternalSecretRef object.
517-
func parseExternalSecretDataRef(dataRefStr string) (*apiv1.ExternalSecretRef, error) {
516+
// ParseExternalSecretDataRef knows how to parse the remote data ref string, returns the corresponding ExternalSecretRef object.
517+
func ParseExternalSecretDataRef(dataRefStr string) (*apiv1.ExternalSecretRef, error) {
518518
uri, err := url.Parse(dataRefStr)
519519
if err != nil {
520520
return nil, err

pkg/engine/operation/graph/resource_node_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func TestParseExternalSecretDataRef(t *testing.T) {
303303
}
304304
for _, tt := range tests {
305305
t.Run(tt.name, func(t *testing.T) {
306-
got, err := parseExternalSecretDataRef(tt.dataRefStr)
306+
got, err := ParseExternalSecretDataRef(tt.dataRefStr)
307307
if (err != nil) != tt.wantErr {
308308
t.Errorf("parseExternalSecretDataRef() error = %v, wantErr %v", err, tt.wantErr)
309309
return

pkg/engine/operation/preview.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ func (po *PreviewOperation) Preview(req *PreviewRequest) (rsp *PreviewResponse,
5858
priorState := req.State
5959

6060
// Kusion is a multi-runtime system. We initialize runtimes dynamically by resource types
61-
resources := req.Spec.Resources
62-
resources = append(resources, priorState.Resources...)
63-
runtimesMap, s := runtimeinit.Runtimes(resources)
61+
runtimesMap, s := runtimeinit.Runtimes(*req.Spec)
6462
if v1.IsErr(s) {
6563
return nil, s
6664
}
@@ -75,7 +73,7 @@ func (po *PreviewOperation) Preview(req *PreviewRequest) (rsp *PreviewResponse,
7573
priorStateResourceIndex = priorState.Resources.Index()
7674
ag, s = newApplyGraph(req.Spec, priorState)
7775
case models.DestroyPreview:
78-
resources = req.Spec.Resources
76+
resources := req.Spec.Resources
7977
priorStateResourceIndex = resources.Index()
8078
ag, s = newDestroyGraph(resources)
8179
}

pkg/engine/operation/preview_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func TestPreviewOperation_Preview(t *testing.T) {
253253
}
254254

255255
mockey.Mock(runtimeinit.Runtimes).To(func(
256-
resources apiv1.Resources,
256+
spec apiv1.Spec,
257257
) (map[apiv1.Type]runtime.Runtime, v1.Status) {
258258
return map[apiv1.Type]runtime.Runtime{runtime.Kubernetes: &fakePreviewRuntime{}}, nil
259259
}).Build()

pkg/engine/operation/watch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (wo *WatchOperation) Watch(req *WatchRequest) error {
4343

4444
// init runtimes
4545
resources := req.Spec.Resources
46-
runtimes, s := runtimeinit.Runtimes(resources)
46+
runtimes, s := runtimeinit.Runtimes(*req.Spec)
4747
if v1.IsErr(s) {
4848
return errors.New(s.Message())
4949
}

0 commit comments

Comments
 (0)