Skip to content

Commit

Permalink
updated triggerer replicas defaults in create & update deployment flo…
Browse files Browse the repository at this point in the history
…ws (#648)
  • Loading branch information
neel-astro committed Jul 15, 2022
1 parent eb8ee15 commit 56023cf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
11 changes: 6 additions & 5 deletions cmd/software/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var (
releaseName string
nfsLocation string
dagDeploymentType string
triggererReplicas int
createTriggererReplicas int
updateTriggererReplicas int
gitRevision string
gitRepoURL string
gitBranchName string
Expand Down Expand Up @@ -141,7 +142,7 @@ func newDeploymentCreateCmd(out io.Writer) *cobra.Command {
}

if triggererEnabled {
cmd.Flags().IntVarP(&triggererReplicas, "triggerer-replicas", "", 0, "Number of replicas to use for triggerer airflow component, valid 0-2")
cmd.Flags().IntVarP(&createTriggererReplicas, "triggerer-replicas", "", 1, "Number of replicas to use for triggerer airflow component, valid 0-2")
}

if runtimeEnabled {
Expand Down Expand Up @@ -228,7 +229,7 @@ $ astro deployment update [deployment ID] --dag-deployment-type=volume --nfs-loc
}

if triggererEnabled {
cmd.Flags().IntVarP(&triggererReplicas, "triggerer-replicas", "", 0, "Number of replicas to use for triggerer airflow component, valid 0-2")
cmd.Flags().IntVarP(&updateTriggererReplicas, "triggerer-replicas", "", -1, "Number of replicas to use for triggerer airflow component, valid 0-2")
}

//noline:dupl
Expand Down Expand Up @@ -388,7 +389,7 @@ func deploymentCreate(cmd *cobra.Command, out io.Writer) error {
SSHKey: sshKey,
KnownHosts: knowHosts,
GitSyncInterval: gitSyncInterval,
TriggererReplicas: triggererReplicas,
TriggererReplicas: createTriggererReplicas,
}
return deployment.Create(req, houstonClient, out)
}
Expand Down Expand Up @@ -459,7 +460,7 @@ func deploymentUpdate(cmd *cobra.Command, args []string, dagDeploymentType, nfsL
}
}

return deployment.Update(args[0], cloudRole, argsMap, dagDeploymentType, nfsLocation, gitRepoURL, gitRevision, gitBranchName, gitDAGDir, sshKey, knowHosts, executorType, gitSyncInterval, triggererReplicas, houstonClient, out)
return deployment.Update(args[0], cloudRole, argsMap, dagDeploymentType, nfsLocation, gitRepoURL, gitRevision, gitBranchName, gitDAGDir, sshKey, knowHosts, executorType, gitSyncInterval, updateTriggererReplicas, houstonClient, out)
}

func deploymentAirflowUpgrade(cmd *cobra.Command, out io.Writer) error {
Expand Down
22 changes: 18 additions & 4 deletions software/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var (
errDeploymentAlreadyOnRuntime = errors.New("deployment is already using runtime image")
errRuntimeUpdateFailed = errors.New("failed to update the deployment runtime version")
errInvalidAirflowVersion = errors.New("invalid Airflow version to migrate the deployment to Runtime, please upgrade the deployment to 2.2.4 Airflow version before trying to migrate to Runtime image")

triggererAllowedAirflowVersion = semver.MustParse("2.2.0")
)

const (
Expand Down Expand Up @@ -138,6 +140,19 @@ func CheckTriggererEnabled(client houston.ClientInterface) bool {
return config.Flags.TriggererEnabled
}

func addTriggererReplicasArg(vars map[string]interface{}, client houston.ClientInterface, airflowVersion string, triggererReplicas int) {
// reset triggerer count to zero in case airflowVersion < 2.2.0
if airflowVersion != "" {
if version := semver.MustParse(airflowVersion); version != nil && version.LessThan(triggererAllowedAirflowVersion) {
triggererReplicas = 0
}
}

if CheckTriggererEnabled(client) {
vars["triggererReplicas"] = triggererReplicas
}
}

// Create airflow deployment
func Create(req *CreateDeploymentRequest, client houston.ClientInterface, out io.Writer) error {
vars := map[string]interface{}{"label": req.Label, "workspaceId": req.WS, "executor": req.Executor, "cloudRole": req.CloudRole}
Expand Down Expand Up @@ -173,9 +188,8 @@ func Create(req *CreateDeploymentRequest, client houston.ClientInterface, out io
return err
}

if CheckTriggererEnabled(client) {
vars["triggererReplicas"] = req.TriggererReplicas
}
addTriggererReplicasArg(vars, client, req.AirflowVersion, req.TriggererReplicas)

d, err := client.CreateDeployment(vars)
if err != nil {
return err
Expand Down Expand Up @@ -338,7 +352,7 @@ func Update(id, cloudRole string, args map[string]string, dagDeploymentType, nfs
return err
}

if CheckTriggererEnabled(client) {
if CheckTriggererEnabled(client) && triggererReplicas != -1 {
vars["triggererReplicas"] = triggererReplicas
}

Expand Down

0 comments on commit 56023cf

Please sign in to comment.