Skip to content

Commit

Permalink
deployment ci cd enforcement control (#1207)
Browse files Browse the repository at this point in the history
* deployment ci cd enforcement control

* Adding tests

* ci cd enforcement on deployment inspect

* Separating variables for create and update flags

* Changing to boolean flag

* Updating flag description
  • Loading branch information
kushalmalani committed May 18, 2023
1 parent 783ec69 commit af54f72
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 98 deletions.
2 changes: 2 additions & 0 deletions astro-client/mutations.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var (
dagDeployEnabled
schedulerSize
isHighAvailability
apiKeyOnlyDeployments
cluster {
id
name
Expand Down Expand Up @@ -91,6 +92,7 @@ var (
dagDeployEnabled
schedulerSize
isHighAvailability
apiKeyOnlyDeployments
cluster {
id
name
Expand Down
1 change: 1 addition & 0 deletions astro-client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
description
releaseName
dagDeployEnabled
apiKeyOnlyDeployments
schedulerSize
isHighAvailability
cluster {
Expand Down
57 changes: 30 additions & 27 deletions astro-client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,25 @@ type AuthUser struct {

// Deployment defines structure of a astrohub response Deployment object
type Deployment struct {
ID string `json:"id"`
Label string `json:"label"`
Description string `json:"description"`
WebserverStatus string `json:"webserverStatus"`
Status string `json:"status"`
ReleaseName string `json:"releaseName"`
Version string `json:"version"`
DagDeployEnabled bool `json:"dagDeployEnabled"`
AlertEmails []string `json:"alertEmails"`
Cluster Cluster `json:"cluster"`
Workspace Workspace `json:"workspace"`
RuntimeRelease RuntimeRelease `json:"runtimeRelease"`
DeploymentSpec DeploymentSpec `json:"deploymentSpec"`
SchedulerSize string `json:"schedulerSize"`
IsHighAvailability bool `json:"isHighAvailability"`
WorkerQueues []WorkerQueue `json:"workerQueues"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
ID string `json:"id"`
Label string `json:"label"`
Description string `json:"description"`
WebserverStatus string `json:"webserverStatus"`
Status string `json:"status"`
ReleaseName string `json:"releaseName"`
Version string `json:"version"`
DagDeployEnabled bool `json:"dagDeployEnabled"`
APIKeyOnlyDeployments bool `json:"apiKeyOnlyDeployments"`
AlertEmails []string `json:"alertEmails"`
Cluster Cluster `json:"cluster"`
Workspace Workspace `json:"workspace"`
RuntimeRelease RuntimeRelease `json:"runtimeRelease"`
DeploymentSpec DeploymentSpec `json:"deploymentSpec"`
SchedulerSize string `json:"schedulerSize"`
IsHighAvailability bool `json:"isHighAvailability"`
WorkerQueues []WorkerQueue `json:"workerQueues"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}

// Cluster contains all components of an Astronomer Cluster
Expand Down Expand Up @@ -338,6 +339,7 @@ type CreateDeploymentInput struct {
WorkerQueues []WorkerQueue `json:"workerQueues"`
IsHighAvailability bool `json:"isHighAvailability"`
SchedulerSize string `json:"schedulerSize"`
APIKeyOnlyDeployments bool `json:"apiKeyOnlyDeployments"`
}

type DeploymentCreateSpec struct {
Expand All @@ -346,15 +348,16 @@ type DeploymentCreateSpec struct {
}

type UpdateDeploymentInput struct {
ID string `json:"id"`
ClusterID string `json:"clusterId"`
Label string `json:"label"`
Description string `json:"description"`
DagDeployEnabled bool `json:"dagDeployEnabled"`
DeploymentSpec DeploymentCreateSpec `json:"deploymentSpec"`
IsHighAvailability bool `json:"isHighAvailability"`
SchedulerSize string `json:"schedulerSize"`
WorkerQueues []WorkerQueue `json:"workerQueues"`
ID string `json:"id"`
ClusterID string `json:"clusterId"`
Label string `json:"label"`
Description string `json:"description"`
DagDeployEnabled bool `json:"dagDeployEnabled"`
APIKeyOnlyDeployments bool `json:"apiKeyOnlyDeployments"`
DeploymentSpec DeploymentCreateSpec `json:"deploymentSpec"`
IsHighAvailability bool `json:"isHighAvailability"`
SchedulerSize string `json:"schedulerSize"`
WorkerQueues []WorkerQueue `json:"workerQueues"`
}

type DeleteDeploymentInput struct {
Expand Down
29 changes: 18 additions & 11 deletions cloud/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
ErrInvalidDeploymentKey = errors.New("invalid Deployment selected")
ErrInvalidRegionKey = errors.New("invalid Region selected")
errTimedOut = errors.New("timed out waiting for the deployment to become healthy")
ErrWrongEnforceInput = errors.New("the input to the `--enforce-cicd` flag")
// Monkey patched to write unit tests
createDeployment = Create
CleanOutput = false
Expand All @@ -53,15 +54,15 @@ func newTableOut() *printutil.Table {
return &printutil.Table{
Padding: []int{30, 50, 10, 50, 10, 10, 10},
DynamicPadding: true,
Header: []string{"NAME", "NAMESPACE", "CLUSTER", "DEPLOYMENT ID", "RUNTIME VERSION", "DAG DEPLOY ENABLED"},
Header: []string{"NAME", "NAMESPACE", "CLUSTER", "DEPLOYMENT ID", "RUNTIME VERSION", "DAG DEPLOY ENABLED", "CI-CD ENFORCEMENT"},
}
}

func newTableOutAll() *printutil.Table {
return &printutil.Table{
Padding: []int{30, 50, 10, 50, 10, 10, 10},
DynamicPadding: true,
Header: []string{"NAME", "WORKSPACE", "NAMESPACE", "CLUSTER", "DEPLOYMENT ID", "RUNTIME VERSION", "DAG DEPLOY ENABLED"},
Header: []string{"NAME", "WORKSPACE", "NAMESPACE", "CLUSTER", "DEPLOYMENT ID", "RUNTIME VERSION", "DAG DEPLOY ENABLED", "CI-CD ENFORCEMENT"},
}
}

Expand Down Expand Up @@ -95,9 +96,9 @@ func List(ws string, all bool, client astro.Client, out io.Writer) error {
}

if all {
tab.AddRow([]string{d.Label, d.Workspace.Label, releaseName, clusterName, d.ID, runtimeVersionText, strconv.FormatBool(d.DagDeployEnabled)}, false)
tab.AddRow([]string{d.Label, d.Workspace.Label, releaseName, clusterName, d.ID, runtimeVersionText, strconv.FormatBool(d.DagDeployEnabled), strconv.FormatBool(d.APIKeyOnlyDeployments)}, false)
} else {
tab.AddRow([]string{d.Label, releaseName, clusterName, d.ID, runtimeVersionText, strconv.FormatBool(d.DagDeployEnabled)}, false)
tab.AddRow([]string{d.Label, releaseName, clusterName, d.ID, runtimeVersionText, strconv.FormatBool(d.DagDeployEnabled), strconv.FormatBool(d.APIKeyOnlyDeployments)}, false)
}
}

Expand Down Expand Up @@ -154,7 +155,7 @@ func Logs(deploymentID, ws, deploymentName string, warnLogs, errorLogs, infoLogs
return nil
}

func Create(label, workspaceID, description, clusterID, runtimeVersion, dagDeploy, executor, cloudProvider, region, schedulerSize, highAvailability string, schedulerAU, schedulerReplicas int, client astro.Client, coreClient astrocore.CoreClient, waitForStatus bool) error { //nolint
func Create(label, workspaceID, description, clusterID, runtimeVersion, dagDeploy, executor, cloudProvider, region, schedulerSize, highAvailability string, schedulerAU, schedulerReplicas int, client astro.Client, coreClient astrocore.CoreClient, waitForStatus bool, enforceCD *bool) error { //nolint
var organizationID string
var currentWorkspace astro.Workspace
var dagDeployEnabled bool
Expand Down Expand Up @@ -271,6 +272,7 @@ func Create(label, workspaceID, description, clusterID, runtimeVersion, dagDeplo
DagDeployEnabled: dagDeployEnabled,
RuntimeReleaseVersion: runtimeVersion,
DeploymentSpec: spec,
APIKeyOnlyDeployments: *enforceCD,
}

if organization.IsOrgHosted() {
Expand Down Expand Up @@ -316,8 +318,7 @@ func createOutput(workspaceID string, d *astro.Deployment) error {
clusterName = d.Cluster.Region
releaseName = notApplicable
}
tab.AddRow([]string{d.Label, releaseName, clusterName, d.ID, runtimeVersionText, strconv.FormatBool(d.DagDeployEnabled)}, false)

tab.AddRow([]string{d.Label, releaseName, clusterName, d.ID, runtimeVersionText, strconv.FormatBool(d.DagDeployEnabled), strconv.FormatBool(d.APIKeyOnlyDeployments)}, false)
deploymentURL, err := GetDeploymentURL(d.ID, workspaceID)
if err != nil {
return err
Expand Down Expand Up @@ -569,7 +570,7 @@ func healthPoll(deploymentID, ws string, client astro.Client) error {
}
}

func Update(deploymentID, label, ws, description, deploymentName, dagDeploy, executor, schedulerSize, highAvailability string, schedulerAU, schedulerReplicas int, wQueueList []astro.WorkerQueue, forceDeploy bool, client astro.Client) error { //nolint
func Update(deploymentID, label, ws, description, deploymentName, dagDeploy, executor, schedulerSize, highAvailability string, schedulerAU, schedulerReplicas int, wQueueList []astro.WorkerQueue, forceDeploy bool, enforceCD *bool, client astro.Client) error { //nolint
var queueCreateUpdate, confirmWithUser bool
// get deployment
currentDeployment, err := GetDeployment(ws, deploymentID, deploymentName, client, nil)
Expand Down Expand Up @@ -623,6 +624,12 @@ func Update(deploymentID, label, ws, description, deploymentName, dagDeploy, exe
deploymentUpdate.Description = currentDeployment.Description
}

if enforceCD == nil {
deploymentUpdate.APIKeyOnlyDeployments = currentDeployment.APIKeyOnlyDeployments
} else {
deploymentUpdate.APIKeyOnlyDeployments = *enforceCD
}

if organization.IsOrgHosted() {
if schedulerSize != "" {
deploymentUpdate.SchedulerSize = schedulerSize
Expand Down Expand Up @@ -702,7 +709,7 @@ func Update(deploymentID, label, ws, description, deploymentName, dagDeploy, exe
clusterName = d.Cluster.Region
releaseName = notApplicable
}
tabDeployment.AddRow([]string{d.Label, releaseName, clusterName, d.ID, runtimeVersionText, strconv.FormatBool(d.DagDeployEnabled)}, false)
tabDeployment.AddRow([]string{d.Label, releaseName, clusterName, d.ID, runtimeVersionText, strconv.FormatBool(d.DagDeployEnabled), strconv.FormatBool(d.APIKeyOnlyDeployments)}, false)
tabDeployment.SuccessMsg = "\n Successfully updated Deployment"
tabDeployment.Print(os.Stdout)
}
Expand Down Expand Up @@ -874,9 +881,9 @@ func deploymentSelectionProcess(ws string, deployments []astro.Deployment, clien

schedulerAU := configOption.Components.Scheduler.AU.Default
schedulerReplicas := configOption.Components.Scheduler.Replicas.Default

cicdEnforcement := false
// walk user through creating a deployment
err = createDeployment("", ws, "", "", runtimeVersion, "disable", CeleryExecutor, "", "", "medium", "", schedulerAU, schedulerReplicas, client, coreClient, false)
err = createDeployment("", ws, "", "", runtimeVersion, "disable", CeleryExecutor, "", "", "medium", "", schedulerAU, schedulerReplicas, client, coreClient, false, &cicdEnforcement)
if err != nil {
return astro.Deployment{}, err
}
Expand Down
Loading

0 comments on commit af54f72

Please sign in to comment.