-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
There was a problem hiding this 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?
config/crd/bases/api-gateway.consul.hashicorp.com_gatewayclassconfigs.yaml
Outdated
Show resolved
Hide resolved
@@ -149,18 +150,34 @@ func (b *GatewayDeploymentBuilder) Build() *v1.Deployment { | |||
} | |||
} | |||
|
|||
func (b *GatewayDeploymentBuilder) instances() *int32 { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
consul-api-gateway/pkg/apis/v1alpha1/types.go
Line 196 in 1c099ab
func MergeDeployment(a, b *appsv1.Deployment) *appsv1.Deployment { |
Which gets used as part of the "create or update" code here:
consul-api-gateway/internal/k8s/reconciler/gateway.go
Lines 471 to 475 in 1c099ab
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I'll see if I can get that working. Is that why the replicas is always set to one on create no matter what?
Nathan said that we were going to breaking out the min/max into a different ticket, so likely not this PR. |
9a48176
to
d5c7d9b
Compare
a4eaf98
to
e04e1b0
Compare
There was a problem hiding this 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.
config/crd/bases/api-gateway.consul.hashicorp.com_gatewayclassconfigs.yaml
Outdated
Show resolved
Hide resolved
config/crd/bases/api-gateway.consul.hashicorp.com_gatewayclassconfigs.yaml
Outdated
Show resolved
Hide resolved
checkGatewayConfigAnnotation(t, gateway, gatewayClassConfig) | ||
|
||
deployment := &appsv1.Deployment{} | ||
assert.NoError(t, resources.Get(ctx, gatewayName, namespace, deployment)) |
There was a problem hiding this comment.
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
❤️
internal/k8s/builder/testdata/multiple-instances.deployment.golden.yaml
Outdated
Show resolved
Hide resolved
f42cf31
to
b3f5893
Compare
Changes proposed in this PR:
How I've tested this PR:
-Created a kind cluster and installed CRD and helmchart locally
How I expect reviewers to test this PR:
Checklist: