mirror of https://github.com/databricks/cli.git
Make it possible to override the compute id in an environment
This commit is contained in:
parent
be2dd4f769
commit
d221d4d348
|
@ -32,8 +32,8 @@ type Bundle struct {
|
|||
// Determines the mode of the environment.
|
||||
// For example, 'mode: development' can be used for deployments for
|
||||
// development purposes.
|
||||
Mode Mode `json:"mode,omitempty"`
|
||||
Mode Mode `json:"mode,omitempty" bundle:"readonly"`
|
||||
|
||||
// Overrides the compute used for jobs and other supported assets.
|
||||
Compute string `json:"override_compute,omitempty" bundle:"readonly"`
|
||||
ComputeID string `json:"compute_id,omitempty"`
|
||||
}
|
||||
|
|
|
@ -9,8 +9,14 @@ type Environment struct {
|
|||
// by the user (through environment variable or command line argument).
|
||||
Default bool `json:"default,omitempty"`
|
||||
|
||||
// Determines the mode of the environment.
|
||||
// For example, 'mode: development' can be used for deployments for
|
||||
// development purposes.
|
||||
Mode Mode `json:"mode,omitempty"`
|
||||
|
||||
// Overrides the compute used for jobs and other supported assets.
|
||||
ComputeID string `json:"compute_id,omitempty"`
|
||||
|
||||
Bundle *Bundle `json:"bundle,omitempty"`
|
||||
|
||||
Workspace *Workspace `json:"workspace,omitempty"`
|
||||
|
|
|
@ -34,21 +34,22 @@ func overrideJobCompute(j *resources.Job, compute string) {
|
|||
|
||||
func (m *overrideCompute) Apply(ctx context.Context, b *bundle.Bundle) error {
|
||||
if b.Config.Bundle.Mode != config.Development {
|
||||
if b.Config.Bundle.Compute != "" {
|
||||
if b.Config.Bundle.ComputeID != "" {
|
||||
return fmt.Errorf("cannot override compute for an environment that does not use 'mode: development'")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if os.Getenv("DATABRICKS_CLUSTER_ID") != "" {
|
||||
b.Config.Bundle.Compute = os.Getenv("DATABRICKS_CLUSTER_ID")
|
||||
b.Config.Bundle.ComputeID = os.Getenv("DATABRICKS_CLUSTER_ID")
|
||||
}
|
||||
if b.Config.Bundle.Compute == "" {
|
||||
|
||||
if b.Config.Bundle.ComputeID == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
r := b.Config.Resources
|
||||
for i := range r.Jobs {
|
||||
overrideJobCompute(r.Jobs[i], b.Config.Bundle.Compute)
|
||||
overrideJobCompute(r.Jobs[i], b.Config.Bundle.ComputeID)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -20,8 +20,8 @@ func TestOverrideDevelopment(t *testing.T) {
|
|||
bundle := &bundle.Bundle{
|
||||
Config: config.Root{
|
||||
Bundle: config.Bundle{
|
||||
Mode: config.Development,
|
||||
Compute: "newClusterID",
|
||||
Mode: config.Development,
|
||||
ComputeID: "newClusterID",
|
||||
},
|
||||
Resources: config.Resources{
|
||||
Jobs: map[string]*resources.Job{
|
||||
|
@ -81,7 +81,7 @@ func TestOverrideProduction(t *testing.T) {
|
|||
bundle := &bundle.Bundle{
|
||||
Config: config.Root{
|
||||
Bundle: config.Bundle{
|
||||
Compute: "newClusterID",
|
||||
ComputeID: "newClusterID",
|
||||
},
|
||||
Resources: config.Resources{
|
||||
Jobs: map[string]*resources.Job{
|
||||
|
|
|
@ -194,5 +194,9 @@ func (r *Root) MergeEnvironment(env *Environment) error {
|
|||
r.Bundle.Mode = env.Mode
|
||||
}
|
||||
|
||||
if env.ComputeID != "" {
|
||||
r.Bundle.ComputeID = env.ComputeID
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ var deployCmd = &cobra.Command{
|
|||
func deploy(cmd *cobra.Command, b *bundle.Bundle) error {
|
||||
// If `--force` is specified, force acquisition of the deployment lock.
|
||||
b.Config.Bundle.Lock.Force = forceDeploy
|
||||
b.Config.Bundle.Compute = computeID
|
||||
b.Config.Bundle.ComputeID = computeID
|
||||
|
||||
return bundle.Apply(cmd.Context(), b, bundle.Seq(
|
||||
phases.Initialize(),
|
||||
|
@ -36,5 +36,5 @@ var computeID string
|
|||
func init() {
|
||||
AddCommand(deployCmd)
|
||||
deployCmd.Flags().BoolVar(&forceDeploy, "force", false, "Force acquisition of deployment lock.")
|
||||
deployCmd.Flags().StringVar(&computeID, "compute", "", "Override compute in the deployment with the given compute ID.")
|
||||
deployCmd.Flags().StringVarP(&computeID, "compute-id", "c", "", "Override compute in the deployment with the given compute ID.")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue