Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Configure instances on gatewayConfig #195

Merged
merged 2 commits into from
May 26, 2022

Conversation

sarahalsmiller
Copy link
Member

@sarahalsmiller sarahalsmiller commented May 12, 2022

Changes proposed in this PR:

  • Add optional deploy object to gatewayClassConfiguration that allows users

How I've tested this PR:

-Created a kind cluster and installed CRD and helmchart locally

  • need to test actually creating a gateway and making sure the instances scale appropriately

How I expect reviewers to test this PR:

  • Added builder unit test that makes sure the deployment gets built with the correct number of replicas set
  • Maybe need an end to end test to capture the bug I'm seeing where it doesn't actually set the replicas appropriately

Checklist:

  • [ X ] Tests added
  • [ X ] CHANGELOG entry added

    Run make changelog-entry for guidance in authoring a changelog entry, and
    commit the resulting file, which should have a name matching your PR number.
    Entries should use imperative present tense (e.g. Add support for...)

@sarahalsmiller sarahalsmiller marked this pull request as ready for review May 16, 2022 15:07
Copy link
Contributor

@andrewstucki andrewstucki left a comment

Choose a reason for hiding this comment

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

Biggest change is the need to not reset the replica count if changed out of band. Ideally what we'd do is pass in the count for an existing deployment (if it exists) and use it. If no deployment exists, then do the defaultInstances/in-code defaults.

Also, is this PR going to also incorporate the arguments for min/max?

@@ -149,18 +150,34 @@ func (b *GatewayDeploymentBuilder) Build() *v1.Deployment {
}
}

func (b *GatewayDeploymentBuilder) instances() *int32 {
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally this would take a parameter to not overwrite the instance count if it's modified by the user (via something like a kubectl scale operation)

Copy link
Member Author

Choose a reason for hiding this comment

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

Would the operation flow then be something like, check current current spec for override replicas value, check gateway class config, check default?

Copy link
Contributor

Choose a reason for hiding this comment

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

So, it'd be something like query the deployment for the gateway, if it exists, then use the replica count on it, if not, then set it via this method. Taking a look at the code, there's actually an even easier way to go about this then passing it in on deployment construction (what I'm recommending above).

Most of this is already abstracted and could be handled via adding in some replica overwriting code here:

func MergeDeployment(a, b *appsv1.Deployment) *appsv1.Deployment {

Which gets used as part of the "create or update" code here:

deployment := g.deploymentBuilder.Build()
mutated := deployment.DeepCopy()
if updated, err := g.client.CreateOrUpdateDeployment(ctx, mutated, func() error {
mutated = apigwv1alpha1.MergeDeployment(deployment, mutated)
return g.client.SetControllerOwnership(g.gateway, mutated)

The second argument b in the MergeDeployment function argument should be the already existing deployment, so you'll just want to keep its replica count from getting wiped out by the b.Spec.Template = a.Spec.Template operation.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like that might already be getting preserved since it looks like replicas is a layer above template. Might need you to double check on that though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, interesting, yeah, that would make sense, that's definitely not intended. We should probably audit what isn't handled by this merge operation apart from metadata (which was IIRC the intent of adding this create/update code that bypasses things like metadata).

Think best way to double check this and also make sure we're always allowing for manual modification is to probably add an e2e test for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added two e2e tests, one for normal replication and one for testing to make sure we can modify the replica number manually. Let me know your thoughts.

@sarahalsmiller
Copy link
Member Author

Biggest change is the need to not reset the replica count if changed out of band. Ideally what we'd do is pass in the count for an existing deployment (if it exists) and use it. If no deployment exists, then do the defaultInstances/in-code defaults.

I'll see if I can get that working. Is that why the replicas is always set to one on create no matter what?

Also, is this PR going to also incorporate the arguments for min/max?

Nathan said that we were going to breaking out the min/max into a different ticket, so likely not this PR.

@sarahalsmiller sarahalsmiller changed the title WIP- Configure instances on gatewayConfig Configure instances on gatewayConfig May 17, 2022
@sarahalsmiller sarahalsmiller force-pushed the sa-configure-instances-on-gateway branch 2 times, most recently from 9a48176 to d5c7d9b Compare May 17, 2022 20:42
@sarahalsmiller sarahalsmiller force-pushed the sa-configure-instances-on-gateway branch from a4eaf98 to e04e1b0 Compare May 18, 2022 01:58
Copy link
Member

@nathancoleman nathancoleman left a comment

Choose a reason for hiding this comment

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

Looking good! One big question about why pre-existing code is merging a deployment onto a copy of itself 🤔 . That's probs for Andrew though.

checkGatewayConfigAnnotation(t, gateway, gatewayClassConfig)

deployment := &appsv1.Deployment{}
assert.NoError(t, resources.Get(ctx, gatewayName, namespace, deployment))
Copy link
Member

Choose a reason for hiding this comment

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

Loving your distinction between require and assert ❤️

@sarahalsmiller sarahalsmiller force-pushed the sa-configure-instances-on-gateway branch from f42cf31 to b3f5893 Compare May 25, 2022 19:52
@sarahalsmiller sarahalsmiller merged commit 2362a73 into main May 26, 2022
@sarahalsmiller sarahalsmiller deleted the sa-configure-instances-on-gateway branch May 26, 2022 14:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants