Repository navigation
feat(api): add IPAddressClass.spec.loadBalancerClass - #18
Conversation
A class names the spec.loadBalancerClass that a Service consuming one of its claims must carry, so the Service reaches the load-balancer implementation that owns the class's pool. Unset means the cluster's default implementation. The field is immutable, and it cannot be set or unset after creation either: a Service's own loadBalancerClass cannot change once set, so a new value would strand every Service already rendered for the class. A spec-level CEL transition rule enforces this, because a field-level self == oldSelf does not run when the field is added or removed. Auto-claim now claims a Service only when its loadBalancerClass equals its class's, with both unset counting as equal, so a class served by a non-default implementation can be the auto-claim class. It used to skip every Service that set a loadBalancerClass. A mismatch with a class the Service names through the annotation, or a named class that does not exist, is reported as a warning event. Assisted-by: LLM Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Aleksei Sviridkin (lexfrei)
left a comment
There was a problem hiding this comment.
LGTM. The field has the shape and meaning the EndpointAttachment controller in cozystack/cozystack#4324 already reads (a string at spec.loadBalancerClass, unset means the default implementation), and classes without it keep their current behaviour.
| ) | ||
|
|
||
| // IPAddressClassSpec defines the desired state of IPAddressClass. | ||
| // +kubebuilder:validation:XValidation:rule="has(self.loadBalancerClass) == has(oldSelf.loadBalancerClass) && (!has(self.loadBalancerClass) || self.loadBalancerClass == oldSelf.loadBalancerClass)",message="loadBalancerClass is immutable",fieldPath=".loadBalancerClass" |
There was a problem hiding this comment.
(non-blocking) Because the field cannot be set after creation, a class created before this release can never take a non-empty value. For a driver that fronts a non-default instance (metallb-iad with a non-empty --lb-class), obligation 5 in docs/design.md then has no in-place fix: the class has to be recreated, and it is held until its addresses are gone. One line about this under "Upgrading the CRDs" in docs/operating.md would save an operator the surprise.
| } | ||
| } | ||
|
|
||
| func TestAutoClaimWaitsForClassNamedByService(t *testing.T) { |
There was a problem hiding this comment.
(non-blocking) This pins that nothing is claimed while the named class is missing, but not the other half of the documented behaviour: the Service is claimed once the class is created. Creating otherClassName after the first reconcile, checking that servicesForClass returns the Service, and reconciling again would pin it.
The
ip-address-claimsproposal (cozystack/community#35) gives a class theloadBalancerClassthat a consuming Service must carry, so the Service reaches the load-balancer implementation that owns the class's pool.IPAddressClassSpechas no such field. A consumer that readsspec.loadBalancerClassfrom the class, such as theEndpointAttachmentcontroller in cozystack/cozystack#4324, always reads empty, and every Service it renders goes to the cluster's default implementation.Changes
IPAddressClass.spec.loadBalancerClass, an optional string with a minimum length of 1. It is thespec.loadBalancerClassa Service consuming a claim of this class must carry. Unset means the cluster's default implementation, and such a Service carries none. The core never sets it on a Service. The CRD and deepcopy are regenerated withmake manifests generate.has(self.loadBalancerClass) == has(oldSelf.loadBalancerClass) && (!has(self.loadBalancerClass) || self.loadBalancerClass == oldSelf.loadBalancerClass).A field-level
self == oldSelf, as onprovisioner, runs only when both the old and the new object have the field, so it would let the field be added or removed.spec.loadBalancerClassequals its class's, with both unset counting as equal. A mismatch with the marked auto-claim class is skipped silently. A mismatch with a class the Service names throughlocal.sdn.cozystack.io/ip-address-classis aLoadBalancerClassMismatchwarning event.docs/design.md§2. §7 obligation 5 says a driver does not associate a Service whoseloadBalancerClassdiffers from its claim's class's. §10 and the README describe the new auto-claim rule. The schema table indocs/operating.mdlists the field under the unreleased version.Why immutable
Kubernetes makes a Service's own
spec.loadBalancerClassimmutable once it is set. Suppose a class's value changed after Services were rendered for it. Those Services would keep the old value and stay with the old implementation, which no longer owns the pool, and nothing could move them short of deleting and recreating them. Unsetting the field has the same effect, and so does setting it on a class that has served claims. Recreating the class to change the field makes that cost visible. Reviewers who prefer a mutable field, for example to let a consumer recreate its Services after a change, can drop the rule. Nothing in the core depends on it.Behaviour to know
spec.loadBalancerClass. A Service that sets one now gets a claim when its class names the same value.ip-address-classannotation does not exist, the core used to create aPendingclaim for it. It now records aClassNotFoundwarning on the Service and claims nothing, because the class'sloadBalancerClasscannot be checked. The Service is claimed once the class is created: class events already requeue qualifying Services.loadBalancerClass. Existing auto-claims are untouched, because a Service that already names a claim never qualifies again. As with every API change, the CRDs must be reapplied (make install-crds), since Helm never upgradescrds/.Tests
test/crd(new, envtest): runs the CRD's validation against a real kube-apiserver. Creating with the field unset or set is admitted; creating with an empty string is refused. Setting it on a class without it, changing it, and removing it are refused. Rewriting the same value, and changing another field with the value kept or still unset, are admitted. With the rule disabled, the three refusals fail.internal/controller: auto-claim across both-unset, equal, class-only, Service-only and different values, each with the marked class and with a class named by the Service. The cases also check that only the named class records the mismatch warning. A further test covers the missing named class.make testandgolangci-lint runpass.