Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix creating and updating hosted deployments with scaling specs #62

Merged
merged 9 commits into from
May 17, 2024

Conversation

vandyliu
Copy link
Collaborator

@vandyliu vandyliu commented May 15, 2024

Description

  • This PR fixes issues where you cannot create a deployment with a scaling spec
  • Terraform previously would error out

🎟 Issue(s)

#61

🧪 Functional Testing

  • Added lots of tests for scaling spec

📸 Screenshots

📋 Checklist

  • Rebased from the main (or release if patching) branch (before testing)
  • Added/updated applicable tests
  • Added/updated examples in the examples/ directory
  • Tested against Astro-API
  • Communicated to/tagged owners of respective clients potentially impacted by these changes.
  • Updated any related documentation

@vandyliu vandyliu marked this pull request as ready for review May 15, 2024 07:33
@vandyliu vandyliu requested review from sunkickr and a team as code owners May 15, 2024 07:33
}
obj := HibernationSpecOverride{
IsHibernating: types.BoolPointerValue(hibernationOverride.IsHibernating),
IsActive: types.BoolPointerValue(hibernationOverride.IsActive),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick note: IsActive is a property set on the API response, it's not something that can be set on the request.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! got confused a bit by this sometimes but this is for creating the "Terraform response" similar to other "computed" values we have like updatedAt
In resource_deployment.go, we create the request where isActive is not there

Copy link

@ianbuss ianbuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know the tf API well enough to approve this but it looks sane to me and I like the code style @vandyliu 👍

// Currently, the scaling status and spec are only available in development mode
// However, there is a bug in the API where the scaling status and spec are returned even if the deployment is not in development mode for updated deployments
// This is a workaround to handle the bug until the API is fixed
// Issue here: https://github.com/astronomer/astro/issues/21073
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue is fixed

@@ -459,11 +441,11 @@ func WorkerQueueDataSourceTypesObject(
}

type DeploymentScalingSpec struct {
HibernationSpec HibernationSpec `tfsdk:"hibernation_spec"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to change it to use types.Object for resource creation since it would error otherwise

@@ -282,7 +283,7 @@ func TestAcc_ResourceDeploymentStandard(t *testing.T) {
ResourceName: azureCeleryResourceVar,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"external_ips", "oidc_issuer_url", "environment_variables.1.value"}, // environment_variables.0.value is a secret value
ImportStateVerifyIgnore: []string{"external_ips", "oidc_issuer_url", "scaling_status", "environment_variables.1.value"}, // environment_variables.0.value is a secret value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity check: ImportStateVerifyIgnore means that TF won't return this in the output of terraform plan or terraform apply? How do these affect the assertions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that for this test case, we are just ignore those values after an import - we will not check if they are equivalent
Since the first 3 values are computed, it doesnt really matter that the values are not the same and the last value cannot be the same since its a secret
I had it this way since it was throwing errors for those 3

IsDevelopmentMode: true,
ScalingSpec: `scaling_spec = {}`,
}),
ExpectError: regexp.MustCompile(`Inappropriate value for attribute "scaling_spec"`),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: invalid over inappropriate is more accurate here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inappropriate is what the terraform error outputs through their library

Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(scalingSpecResourceVar, "scaling_spec.hibernation_spec.override.is_hibernating", "true"),
resource.TestCheckResourceAttr(scalingSpecResourceVar, "scaling_spec.hibernation_spec.override.override_until", "2075-01-01T00:00:00Z"),
resource.TestCheckNoResourceAttr(scalingSpecResourceVar, "scaling_spec.hibernation_spec.schedules"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for each config, can add comments in assertions on what we're checking - or maybe in the description field something like "Scaling Spec with Hibernation Spec Override Without Schedule" idk if it's overkill, but just an idea for test maintainability

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I refactored the tests to make it a lil more obvious as to what they do
I think I will skip adding comments just in case we update the tests but forget to update the comments but now the tests should be a lot simpler and readable and the main gist of what is going on should be extremely obvious
Also the tests aren't necessarily for asserting the responses but more importantly to check that it doesnt error or panic when it should succeed

@vandyliu vandyliu enabled auto-merge (squash) May 16, 2024 23:06
@vandyliu vandyliu merged commit 37b1be9 into main May 17, 2024
5 checks passed
@vandyliu vandyliu deleted the scaling-fix branch May 17, 2024 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants