mirror of https://github.com/databricks/cli.git
fixes
This commit is contained in:
parent
032a74a6bd
commit
bb58bd1341
|
@ -169,7 +169,7 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
normalisedKey := b.Tagging.NormalizeKey(tag.Key)
|
normalisedKey := b.Tagging.NormalizeKey(tag.Key)
|
||||||
normalisedValue := b.Tagging.NormalizeValue(tag.Value)
|
normalisedValue := b.Tagging.NormalizeValue(tag.Value)
|
||||||
if c.CustomTags[normalisedKey] == "" {
|
if _, ok := c.CustomTags[normalisedKey]; !ok {
|
||||||
c.CustomTags[normalisedKey] = normalisedValue
|
c.CustomTags[normalisedKey] = normalisedValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,35 +19,53 @@ func (m *computeIdToClusterId) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *computeIdToClusterId) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
func (m *computeIdToClusterId) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
|
||||||
// If the "compute_id" key is not set, just skip
|
|
||||||
if b.Config.Bundle.ComputeId == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var diags diag.Diagnostics
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
// The "compute_id" key is set; rewrite it to "cluster_id".
|
// The "compute_id" key is set; rewrite it to "cluster_id".
|
||||||
err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) {
|
err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) {
|
||||||
computeId, err := dyn.Get(v, "bundle.compute_id")
|
v, d := rewriteComputeIdToClusterId(v, dyn.NewPath(dyn.Key("bundle")))
|
||||||
if err != nil {
|
diags = diags.Extend(d)
|
||||||
return v, err
|
|
||||||
|
// Check if the "compute_id" key is set in any target overrides.
|
||||||
|
return dyn.MapByPattern(v, dyn.NewPattern(dyn.Key("targets"), dyn.AnyKey()), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
|
||||||
|
v, d := rewriteComputeIdToClusterId(v, dyn.Path{})
|
||||||
|
diags = diags.Extend(d)
|
||||||
|
return v, nil
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
diags = diags.Extend(diag.FromErr(err))
|
||||||
|
return diags
|
||||||
|
}
|
||||||
|
|
||||||
|
func rewriteComputeIdToClusterId(v dyn.Value, p dyn.Path) (dyn.Value, diag.Diagnostics) {
|
||||||
|
var diags diag.Diagnostics
|
||||||
|
computeIdPath := p.Append(dyn.Key("compute_id"))
|
||||||
|
computeId, err := dyn.GetByPath(v, computeIdPath)
|
||||||
|
|
||||||
|
// If the "compute_id" key is not set, we don't need to do anything.
|
||||||
|
if err != nil {
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if computeId.Kind() == dyn.KindInvalid {
|
||||||
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if computeId.Kind() != dyn.KindInvalid {
|
|
||||||
p := dyn.NewPath(dyn.Key("bundle"), dyn.Key("compute_id"))
|
|
||||||
diags = diags.Append(diag.Diagnostic{
|
diags = diags.Append(diag.Diagnostic{
|
||||||
Severity: diag.Warning,
|
Severity: diag.Warning,
|
||||||
Summary: "compute_id is deprecated, please use cluster_id instead",
|
Summary: "compute_id is deprecated, please use cluster_id instead",
|
||||||
Locations: computeId.Locations(),
|
Locations: computeId.Locations(),
|
||||||
Paths: []dyn.Path{p},
|
Paths: []dyn.Path{computeIdPath},
|
||||||
})
|
})
|
||||||
|
|
||||||
nv, err := dyn.Set(v, "bundle.cluster_id", computeId)
|
clusterIdPath := p.Append(dyn.Key("cluster_id"))
|
||||||
|
nv, err := dyn.SetByPath(v, clusterIdPath, computeId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return dyn.InvalidValue, err
|
return dyn.InvalidValue, diag.FromErr(err)
|
||||||
}
|
}
|
||||||
// Drop the "compute_id" key.
|
// Drop the "compute_id" key.
|
||||||
return dyn.Walk(nv, func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
|
vout, err := dyn.Walk(nv, func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
|
||||||
switch len(p) {
|
switch len(p) {
|
||||||
case 0, 1:
|
case 0, 1:
|
||||||
return v, nil
|
return v, nil
|
||||||
|
@ -58,11 +76,7 @@ func (m *computeIdToClusterId) Apply(ctx context.Context, b *bundle.Bundle) diag
|
||||||
}
|
}
|
||||||
return v, dyn.ErrSkip
|
return v, dyn.ErrSkip
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
return v, nil
|
|
||||||
})
|
|
||||||
|
|
||||||
diags = diags.Extend(diag.FromErr(err))
|
diags = diags.Extend(diag.FromErr(err))
|
||||||
return diags
|
return vout, diags
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,3 +29,24 @@ func TestComputeIdToClusterId(t *testing.T) {
|
||||||
assert.Equal(t, "compute_id is deprecated, please use cluster_id instead", diags[0].Summary)
|
assert.Equal(t, "compute_id is deprecated, please use cluster_id instead", diags[0].Summary)
|
||||||
assert.Equal(t, diag.Warning, diags[0].Severity)
|
assert.Equal(t, diag.Warning, diags[0].Severity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestComputeIdToClusterIdInTargetOverride(t *testing.T) {
|
||||||
|
b := &bundle.Bundle{
|
||||||
|
Config: config.Root{
|
||||||
|
Targets: map[string]*config.Target{
|
||||||
|
"dev": {
|
||||||
|
ComputeId: "compute-id-dev",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
diags := bundle.Apply(context.Background(), b, bundle.Seq(mutator.ComputeIdToClusterId(), mutator.SelectTarget("dev")))
|
||||||
|
assert.NoError(t, diags.Error())
|
||||||
|
assert.Equal(t, "compute-id-dev", b.Config.Bundle.ClusterId)
|
||||||
|
assert.Empty(t, b.Config.Bundle.ComputeId)
|
||||||
|
|
||||||
|
assert.Len(t, diags, 1)
|
||||||
|
assert.Equal(t, "compute_id is deprecated, please use cluster_id instead", diags[0].Summary)
|
||||||
|
assert.Equal(t, diag.Warning, diags[0].Severity)
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,12 @@ func (clusterConverter) Convert(ctx context.Context, key string, vin dyn.Value,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We always set no_wait as it allows DABs not to wait for cluster to be started.
|
||||||
|
vout, err = dyn.Set(vout, "no_wait", dyn.V(true))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Add the converted resource to the output.
|
// Add the converted resource to the output.
|
||||||
out.Cluster[key] = vout.AsAny()
|
out.Cluster[key] = vout.AsAny()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue