Skip to content

Commit

Permalink
1. parse Cluster from Resource.Extensions
Browse files Browse the repository at this point in the history
2. rollback yaml.v3 to v2 for a known bug in v3
  • Loading branch information
SparkYuan committed Jul 13, 2022
1 parent 182d162 commit 55f8a30
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/engine/operation/graph/resource_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (rn *ResourceNode) applyResource(operation *opsmodels.Operation, priorState
// compatible with delete action
if res != nil {
res.DependsOn = planedState.DependsOn
res.Extensions = planedState.Extensions
}
key := rn.state.ResourceKey()
if e := operation.RefreshResourceIndex(key, res, rn.Action); e != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/states/local/filesystem_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"kusionstack.io/kusion/pkg/engine/states"

"gopkg.in/yaml.v3"
"gopkg.in/yaml.v2"

"github.com/zclconf/go-cty/cty"

Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/states/remote/db_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/didi/gendry/scanner"
"github.com/jinzhu/copier"
"gopkg.in/yaml.v3"
"gopkg.in/yaml.v2"

"kusionstack.io/kusion/pkg/engine/dal/mapper"
"kusionstack.io/kusion/pkg/log"
Expand Down
19 changes: 17 additions & 2 deletions pkg/kusionctl/cmd/apply/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,15 @@ func Preview(

log.Info("Start call pc.Preview() ...")

cluster := parseCluster(planResources)
rsp, s := pc.Preview(&operation.PreviewRequest{
Request: opsmodels.Request{
Tenant: project.Tenant,
Project: project.Name,
Operator: o.Operator,
Stack: stack.Name,
Operator: o.Operator,
Spec: planResources,
Cluster: cluster,
},
})
if status.IsErr(s) {
Expand All @@ -204,6 +206,17 @@ func Preview(
return opsmodels.NewChanges(project, stack, rsp.Order), nil
}

// parseCluster try to parse Cluster from resource extensions.
// All resources in one compile MUST have the same Cluster and this constraint will be guaranteed by KCL compile logic
func parseCluster(planResources *models.Spec) string {
resources := planResources.Resources
var cluster string
if len(resources) != 0 && resources[0].Extensions != nil && resources[0].Extensions["Cluster"] != nil {
cluster = resources[0].Extensions["Cluster"].(string)
}
return cluster
}

// The Apply function will apply the resources changes
// through the execution Kusion Engine, and will save
// the state to specified storage.
Expand Down Expand Up @@ -319,12 +332,14 @@ func Apply(
}
close(ac.MsgCh)
} else {
cluster := parseCluster(planResources)
_, st := ac.Apply(&operation.ApplyRequest{
Request: opsmodels.Request{
Tenant: changes.Project().Tenant,
Project: changes.Project().Name,
Operator: o.Operator,
Stack: changes.Stack().Name,
Cluster: cluster,
Operator: o.Operator,
Spec: planResources,
},
})
Expand Down

0 comments on commit 55f8a30

Please sign in to comment.