Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PLATFORMS ?= linux/amd64,linux/arm64

CHART := chart/address-controller
# Override to package a different version than the one in Chart.yaml.
CHART_VERSION ?= 0.2.0
CHART_VERSION ?= 0.3.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ All kinds live in the `local.sdn.cozystack.io/v1alpha1` API group.

| storage | addresses | scope | role |
|---|---|---|---|
| `StorageClass` | `IPAddressClass` | cluster | which pool, which driver (`spec.provisioner`), which reclaim policy, which load-balancer implementation (`spec.loadBalancerClass`) |
| `StorageClass` | `IPAddressClass` | cluster | which pool, which driver (`spec.provisioner`), which reclaim policy; the driver reports its load-balancer implementation in `status.loadBalancerClass` |
| `PersistentVolume` | `IPAddress` | cluster | the address itself, with a `claimRef`, a reclaim policy, and a `fromClass`/`providerRef` source union |
| `PersistentVolumeClaim` | `IPAddressClaim` | namespaced | "give me one" — the whole tenant-facing API |

Expand Down Expand Up @@ -76,9 +76,10 @@ core controller as follows:
reconciles live Service assignments against the ledger and sets the
`Conflict` phase when an address is held by a Service its binding does not
authorize, and `Lost` when the backing allocation disappears.
A Service consuming a claim carries its class's `spec.loadBalancerClass`
(none when the class leaves it unset), so it reaches the load-balancer
implementation that owns the class's pool. The field is immutable.
A Service consuming a claim carries the `loadBalancerClass` the driver
reports in its class's `status.loadBalancerClass` (none when empty), so
it reaches the load-balancer implementation the driver fronts. The value
is valid once the class's `Accepted` condition is `True`.

## Auto-claim for LoadBalancer Services

Expand All @@ -102,9 +103,10 @@ nothing:
`local.sdn.cozystack.io/auto-claim: "false"`, set `spec.loadBalancerIP`,
carry a MetalLB pool, pin or sharing annotation, or already have an
address, and Services whose `spec.loadBalancerClass` differs from the
class's (both unset counts as a match). A Service that names its class
with the annotation gets a warning event for a mismatch or a missing
class.
class's `status.loadBalancerClass` (unset matches empty). Nothing is
claimed from a class its driver has not accepted yet. A Service that names
its class with the annotation gets a warning event for a mismatch, an
unaccepted class or a missing class.

Apart from auto-claim, the core controller never touches Services. It
never parses class parameters and never puts a packet on a wire.
Expand Down
53 changes: 39 additions & 14 deletions api/v1alpha1/ipaddressclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
Expand All @@ -38,7 +39,6 @@ const (
)

// 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"
type IPAddressClassSpec struct {
// provisioner names the per-class driver that fulfils claims of this
// class, exactly as StorageClass.provisioner names a CSI driver. The
Expand All @@ -62,18 +62,6 @@ type IPAddressClassSpec struct {
// +optional
ReleaseDelay *metav1.Duration `json:"releaseDelay,omitempty"`

// loadBalancerClass is the spec.loadBalancerClass a Service consuming a
// claim of this class must carry, so that the Service reaches the
// load-balancer implementation that owns this class's pool. Unset means
// the cluster's default implementation: such a Service carries no
// loadBalancerClass. The core controller never sets it on a Service.
// Immutable, including setting or unsetting it after creation: a
// Service's own loadBalancerClass cannot change once set, so a new value
// would strand every Service already rendered for the class.
// +optional
// +kubebuilder:validation:MinLength=1
LoadBalancerClass *string `json:"loadBalancerClass,omitempty"`

// parameters is an opaque, driver-specific configuration blob (for
// example the address ranges to carve from). The core controller never
// interprets it.
Expand All @@ -82,10 +70,33 @@ type IPAddressClassSpec struct {
Parameters *runtime.RawExtension `json:"parameters,omitempty"`
}

// IPAddressClassStatus is written by the provisioner that serves the class.
// The core controller never writes it.
type IPAddressClassStatus struct {
// loadBalancerClass is the spec.loadBalancerClass a Service consuming a
// claim of this class must carry, so that the Service reaches the
// load-balancer implementation the provisioner fronts. Empty means the
// cluster's default implementation, and such a Service carries none. It
// is meaningful only while the Accepted condition is True for the
// class's current generation: before that, an empty value is not yet
// reported rather than the default.
// +optional
LoadBalancerClass string `json:"loadBalancerClass,omitempty"`

// conditions holds the provisioner's Accepted condition.
// +optional
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Provisioner",type=string,JSONPath=`.spec.provisioner`
// +kubebuilder:printcolumn:name="ReclaimPolicy",type=string,JSONPath=`.spec.reclaimPolicy`
// +kubebuilder:printcolumn:name="LoadBalancerClass",type=string,JSONPath=`.status.loadBalancerClass`
// +kubebuilder:printcolumn:name="Accepted",type=string,JSONPath=`.status.conditions[?(@.type=="Accepted")].status`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

// IPAddressClass describes an address source: which pool, which driver.
Expand All @@ -96,7 +107,8 @@ type IPAddressClass struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec IPAddressClassSpec `json:"spec,omitempty"`
Spec IPAddressClassSpec `json:"spec,omitempty"`
Status IPAddressClassStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
Expand All @@ -111,3 +123,16 @@ type IPAddressClassList struct {
func init() {
SchemeBuilder.Register(&IPAddressClass{}, &IPAddressClassList{})
}

// AcceptedLoadBalancerClass returns the loadBalancerClass the class's
// provisioner reports, and whether it has reported one: the Accepted
// condition is True for the class's current generation. A consumer that
// creates a Service for a claim of the class waits until ok is true, since
// a Service's loadBalancerClass cannot change after creation.
func (c *IPAddressClass) AcceptedLoadBalancerClass() (lbClass string, ok bool) {
cond := meta.FindStatusCondition(c.Status.Conditions, ConditionAccepted)
if cond == nil || cond.Status != metav1.ConditionTrue || cond.ObservedGeneration != c.Generation {
return "", false
}
return c.Status.LoadBalancerClass, true
}
8 changes: 8 additions & 0 deletions api/v1alpha1/well_known.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ const (
ConditionClassResolved = "ClassResolved"
// ConditionBound reports whether every requested family is bound.
ConditionBound = "Bound"
// ConditionAccepted, on an IPAddressClass, is set by the provisioner
// that serves the class. True means the provisioner serves it and
// status.loadBalancerClass holds the value its consumers must carry.
ConditionAccepted = "Accepted"

ReasonResolved = "Resolved"
ReasonAccepted = "Accepted"
ReasonClassNotFound = "ClassNotFound"
ReasonNoDefaultClass = "NoDefaultClass"
ReasonMultipleDefaultClasses = "MultipleDefaultClasses"
Expand All @@ -115,4 +120,7 @@ const (
// ReasonLoadBalancerClassMismatch is recorded when a Service names a
// class whose loadBalancerClass differs from its own.
ReasonLoadBalancerClassMismatch = "LoadBalancerClassMismatch"
// ReasonClassNotAccepted is recorded when a Service names a class its
// provisioner has not accepted yet.
ReasonClassNotAccepted = "ClassNotAccepted"
)
28 changes: 23 additions & 5 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chart/address-controller/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: address-controller
description: Core controllers for IP addresses as a first-class resource — IPAddressClass, IPAddress, IPAddressClaim (local.sdn.cozystack.io)
type: application
version: 0.2.0
appVersion: "0.2.0"
version: 0.3.0
appVersion: "0.3.0"
# CEL validation rules on the CRDs (immutability, union exactness) need 1.29+.
kubeVersion: ">=1.29.0-0"
keywords:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ spec:
- jsonPath: .spec.reclaimPolicy
name: ReclaimPolicy
type: string
- jsonPath: .status.loadBalancerClass
name: LoadBalancerClass
type: string
- jsonPath: .status.conditions[?(@.type=="Accepted")].status
name: Accepted
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
Expand Down Expand Up @@ -53,18 +59,6 @@ spec:
spec:
description: IPAddressClassSpec defines the desired state of IPAddressClass.
properties:
loadBalancerClass:
description: |-
loadBalancerClass is the spec.loadBalancerClass a Service consuming a
claim of this class must carry, so that the Service reaches the
load-balancer implementation that owns this class's pool. Unset means
the cluster's default implementation: such a Service carries no
loadBalancerClass. The core controller never sets it on a Service.
Immutable, including setting or unsetting it after creation: a
Service's own loadBalancerClass cannot change once set, so a new value
would strand every Service already rendered for the class.
minLength: 1
type: string
parameters:
description: |-
parameters is an opaque, driver-specific configuration blob (for
Expand Down Expand Up @@ -103,12 +97,84 @@ spec:
required:
- provisioner
type: object
x-kubernetes-validations:
- fieldPath: .loadBalancerClass
message: loadBalancerClass is immutable
rule: has(self.loadBalancerClass) == has(oldSelf.loadBalancerClass)
&& (!has(self.loadBalancerClass) || self.loadBalancerClass == oldSelf.loadBalancerClass)
status:
description: |-
IPAddressClassStatus is written by the provisioner that serves the class.
The core controller never writes it.
properties:
conditions:
description: conditions holds the provisioner's Accepted condition.
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
loadBalancerClass:
description: |-
loadBalancerClass is the spec.loadBalancerClass a Service consuming a
claim of this class must carry, so that the Service reaches the
load-balancer implementation the provisioner fronts. Empty means the
cluster's default implementation, and such a Service carries none. It
is meaningful only while the Accepted condition is True for the
class's current generation: before that, an empty value is not yet
reported rather than the default.
type: string
type: object
type: object
served: true
storage: true
subresources: {}
subresources:
status: {}
Loading