Skip to content

Commit

Permalink
Add ability to manually set releaseName during create deployment (#327)
Browse files Browse the repository at this point in the history
* add ability to manually set releaseName during create deployment

* set release name based on appConfig

* fix typo
  • Loading branch information
andriisoldatenko committed May 6, 2020
1 parent 1a18452 commit bb4da75
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cmd/deployment.go
Expand Up @@ -19,6 +19,7 @@ var (
systemSA bool
category string
label string
releaseName string
CreateExample = `
# Create new deployment with Celery executor (default: celery without params).
$ astro deployment create new-deployment-name --executor=celery
Expand Down Expand Up @@ -76,6 +77,7 @@ func newDeploymentCreateCmd(client *houston.Client, out io.Writer) *cobra.Comman
RunE: deploymentCreate,
}
cmd.Flags().StringVarP(&executor, "executor", "e", "", "Add executor parameter: local or celery")
cmd.Flags().StringVarP(&releaseName, "release-name", "r", "", "Set custom release-name if possible")
return cmd
}

Expand Down Expand Up @@ -212,7 +214,7 @@ func deploymentCreate(cmd *cobra.Command, args []string) error {
return errors.New("please specify correct executor, one of: local, celery, kubernetes, k8s")
}

return deployment.Create(args[0], ws, deploymentConfig)
return deployment.Create(args[0], ws, releaseName, deploymentConfig)
}

func deploymentDelete(cmd *cobra.Command, args []string) error {
Expand Down
22 changes: 20 additions & 2 deletions deployment/deployment.go
Expand Up @@ -20,10 +20,28 @@ var (
}
)

func Create(label, ws string, deploymentConfig map[string]string) error {
func checkManualReleaseNames() bool {
req := houston.Request{
Query: houston.AppConfigRequest,
}
r, err := req.Do()
if err != nil {
return false
}

return r.Data.GetAppConfig.ManualReleaseNames
}

func Create(label, ws, releaseName string, deploymentConfig map[string]string) error {
vars := map[string]interface{}{"label": label, "workspaceId": ws, "config": deploymentConfig}

if releaseName != "" && checkManualReleaseNames() {
vars["releaseName"] = releaseName
}

req := houston.Request{
Query: houston.DeploymentCreateRequest,
Variables: map[string]interface{}{"label": label, "workspaceId": ws, "config": deploymentConfig},
Variables: vars,
}

r, err := req.Do()
Expand Down
11 changes: 11 additions & 0 deletions houston/queries.go
Expand Up @@ -19,13 +19,15 @@ var (
mutation CreateDeployment(
$label: String!
$type: String = "airflow"
$releaseName: String
$workspaceId: Uuid!
$config: JSON!
) {
createDeployment(
label: $label
type: $type
workspaceUuid: $workspaceId
releaseName: $releaseName
config: $config
) {
id
Expand Down Expand Up @@ -438,4 +440,13 @@ var (
defaultAirflowImageTag
}
}`
AppConfigRequest = `
query AppConfig {
appConfig {
version
baseDomain
smtpConfigured
manualReleaseNames
}
}`
)
9 changes: 9 additions & 0 deletions houston/types.go
Expand Up @@ -17,6 +17,7 @@ type Response struct {
DeleteWorkspace *Workspace `json:"deleteWorkspace,omitempty"`
GetDeployments []Deployment `json:"workspaceDeployments,omitempty"`
GetAuthConfig *AuthConfig `json:"authConfig,omitempty"`
GetAppConfig *AppConfig `json:"appConfig,omitempty"`
GetServiceAccounts []ServiceAccount `json:"serviceAccounts,omitempty"`
GetUsers []User `json:"users,omitempty"`
GetWorkspaces []Workspace `json:"workspaces,omitempty"`
Expand Down Expand Up @@ -226,3 +227,11 @@ func (config *DeploymentConfig) IsValidTag(tag string) bool {
}
return false
}

// AppConfig contains current houston config
type AppConfig struct {
Version string `json:"version"`
BaseDomain string `json:"baseDomain"`
SmtpConfigured bool `json:"smtpConfigured"`
ManualReleaseNames bool `json:"manualReleaseNames"`
}

0 comments on commit bb4da75

Please sign in to comment.