Skip to content

Commit

Permalink
Add logic for PartitionSet reconciliation
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Giloux <fgiloux@redhat.com>
  • Loading branch information
fgiloux committed Dec 20, 2022
1 parent bf9c3ab commit 7294cce
Show file tree
Hide file tree
Showing 11 changed files with 1,162 additions and 104 deletions.
122 changes: 77 additions & 45 deletions config/crds/topology.kcp.dev_partitionsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,56 +51,88 @@ spec:
items:
type: string
type: array
selector:
description: selector (optional) is a label selector that filters
shard targets.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that
contains values, a key, and an operator that relates the key
and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship to
a set of values. Valid operators are In, NotIn, Exists
and DoesNotExist.
type: string
values:
description: values is an array of string values. If the
operator is In or NotIn, the values array must be non-empty.
If the operator is Exists or DoesNotExist, the values
array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
matchExpressions:
description: MatchExpressions (optional) specifies filtering for shard
targets. MatchExpressions are used here instead of Selector to avoid
possible collisions with the MatchLabels generated for the Partition
according to the dimensions in the PartitionSet. This does not limit
the filtering as any MatchLabel can also be expressed as a MatchExpression.
items:
description: A label selector requirement is a selector that contains
values, a key, and an operator that relates the key and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship to a set
of values. Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
values:
description: values is an array of string values. If the operator
is In or NotIn, the values array must be non-empty. If the
operator is Exists or DoesNotExist, the values array must
be empty. This array is replaced during a strategic merge
patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
type: object
status:
description: status holds information about the current status
properties:
conditions:
description: conditions is a list of conditions that apply to the
APIExportEndpointSlice.
items:
description: Condition defines an observation of a object operational
state.
properties:
lastTransitionTime:
description: 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: A human readable message indicating details about
the transition. This field may be empty.
type: string
reason:
description: The reason for the condition's last transition
in CamelCase. The specific API may choose whether or not this
field is considered a guaranteed API. This field may not be
empty.
type: string
severity:
description: Severity provides an explicit classification of
Reason code, so the users or machines can immediately understand
the current situation and act accordingly. The Severity field
MUST be set only when Status=False.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
count:
description: count is the total number of partitions.
type: integer
Expand Down
2 changes: 1 addition & 1 deletion config/root-phase0/apiexport-topology.kcp.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ metadata:
spec:
latestResourceSchemas:
- v221115-9b370eb8.partitions.topology.kcp.dev
- v221118-9364e75c.partitionsets.topology.kcp.dev
- v221216-965f6e97.partitionsets.topology.kcp.dev
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apis.kcp.dev/v1alpha1
kind: APIResourceSchema
metadata:
creationTimestamp: null
name: v221118-9364e75c.partitionsets.topology.kcp.dev
name: v221216-965f6e97.partitionsets.topology.kcp.dev
spec:
group: topology.kcp.dev
names:
Expand Down Expand Up @@ -47,55 +47,84 @@ spec:
items:
type: string
type: array
selector:
description: selector (optional) is a label selector that filters shard
targets.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that contains
values, a key, and an operator that relates the key and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship to a
set of values. Valid operators are In, NotIn, Exists and
DoesNotExist.
type: string
values:
description: values is an array of string values. If the operator
is In or NotIn, the values array must be non-empty. If the
operator is Exists or DoesNotExist, the values array must
be empty. This array is replaced during a strategic merge
patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
matchExpressions:
description: MatchExpressions (optional) specifies filtering for shard
targets. MatchExpressions are used here instead of Selector to avoid
possible collisions with the MatchLabels generated for the Partition
according to the dimensions in the PartitionSet. This does not limit
the filtering as any MatchLabel can also be expressed as a MatchExpression.
items:
description: A label selector requirement is a selector that contains
values, a key, and an operator that relates the key and values.
properties:
key:
description: key is the label key that the selector applies to.
type: string
operator:
description: operator represents a key's relationship to a set
of values. Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator is
"In", and the values array contains only "value". The requirements
are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
values:
description: values is an array of string values. If the operator
is In or NotIn, the values array must be non-empty. If the operator
is Exists or DoesNotExist, the values array must be empty. This
array is replaced during a strategic merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
type: object
status:
description: status holds information about the current status
properties:
conditions:
description: conditions is a list of conditions that apply to the APIExportEndpointSlice.
items:
description: Condition defines an observation of a object operational
state.
properties:
lastTransitionTime:
description: 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: A human readable message indicating details about
the transition. This field may be empty.
type: string
reason:
description: The reason for the condition's last transition in
CamelCase. The specific API may choose whether or not this field
is considered a guaranteed API. This field may not be empty.
type: string
severity:
description: Severity provides an explicit classification of Reason
code, so the users or machines can immediately understand the
current situation and act accordingly. The Severity field MUST
be set only when Status=False.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
count:
description: count is the total number of partitions.
type: integer
Expand Down
39 changes: 36 additions & 3 deletions pkg/apis/topology/v1alpha1/types_partitionset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

conditionsv1alpha1 "github.com/kcp-dev/kcp/pkg/apis/third_party/conditions/apis/conditions/v1alpha1"
)

// +crd
Expand Down Expand Up @@ -58,16 +60,47 @@ type PartitionSetSpec struct {

// +optional

// selector (optional) is a label selector that filters shard targets.
Selector *metav1.LabelSelector `json:"selector,omitempty"`
// MatchExpressions (optional) specifies filtering for shard targets.
// MatchExpressions are used here instead of Selector to avoid possible collisions with
// the MatchLabels generated for the Partition according to the dimensions in the PartitionSet.
// This does not limit the filtering as any MatchLabel can also be expressed as
// a MatchExpression.
MatchExpressions []metav1.LabelSelectorRequirement `json:"matchExpressions,omitempty"`
}

// PartitionSetStaus records the status of the PartitionSet.
// PartitionSetStatus records the status of the PartitionSet.
type PartitionSetStatus struct {
// count is the total number of partitions.
Count uint16 `json:"count,omitempty"`

// +optional

// conditions is a list of conditions that apply to the APIExportEndpointSlice.
Conditions conditionsv1alpha1.Conditions `json:"conditions,omitempty"`
}

func (in *PartitionSet) GetConditions() conditionsv1alpha1.Conditions {
return in.Status.Conditions
}

func (in *PartitionSet) SetConditions(conditions conditionsv1alpha1.Conditions) {
in.Status.Conditions = conditions
}

// These are valid conditions of PartitionSet.
const (
// PartitionSetValid reflects the validity of the PartitionSet spec.
PartitionSetValid conditionsv1alpha1.ConditionType = "PartitionSetValid"
// PartitionsReady indicates whether matching partitions could be created.
PartitionsReady conditionsv1alpha1.ConditionType = "PartitionsReady"

// PartitionSetInvalidSelectorReason indicates that the specified selector could not be
// marshalled into a valid one.
PartitionSetInvalidSelectorReason = "InvalidSelector"
// ErrorGeneratingPartitionsReason indicates that the partitions could not be generated
ErrorGeneratingPartitionsReason = "ErrorGeneratingPartitions"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PartitionSetList is a list of PartitionSet resources
Expand Down
21 changes: 16 additions & 5 deletions pkg/apis/topology/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit 7294cce

Please sign in to comment.