Skip to content

Commit a99672b

Browse files
committed
feat(crd): add memcached port support
1 parent 0dedd9c commit a99672b

File tree

5 files changed

+432
-183
lines changed

5 files changed

+432
-183
lines changed

api/v1alpha1/dragonfly_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ type DragonflySpec struct {
7777
// +kubebuilder:validation:Optional
7878
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
7979

80+
// (Optional) Dragonfly memcached port
81+
// +optional
82+
// +kubebuilder:validation:Optional
83+
MemcachedPort int32 `json:"memcachedPort,omitempty"`
84+
8085
// (Optional) Dragonfly pod tolerations
8186
// +optional
8287
// +kubebuilder:validation:Optional

config/crd/bases/dragonflydb.io_dragonflies.yaml

Lines changed: 136 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,10 @@ spec:
10541054
type: string
10551055
description: (Optional) Labels to add to the Dragonfly pods.
10561056
type: object
1057+
memcachedPort:
1058+
description: (Optional) Dragonfly memcached port
1059+
format: int32
1060+
type: integer
10571061
nodeSelector:
10581062
additionalProperties:
10591063
type: string
@@ -1413,98 +1417,169 @@ spec:
14131417
topologySpreadConstraints:
14141418
description: (Optional) Dragonfly pod topologySpreadConstraints
14151419
items:
1416-
description: The pod this TopologySpreadConstraints is attached
1420+
description: TopologySpreadConstraint specifies how to spread matching
1421+
pods among the given topology.
14171422
properties:
1418-
maxSkew:
1419-
description: the degree to which Pods may be unevenly distributed.
1420-
You must specify this field and the number must be greater than zero.
1421-
Its semantics differ according to the value of whenUnsatisfiable
1422-
format: int32
1423-
type: integer
1424-
minDomains:
1425-
description: (Optional) indicates a minimum number of eligible domains.
1426-
This field is optional. A domain is a particular instance of a topology.
1427-
An eligible domain is a domain whose nodes match the node selector
1428-
format: int32
1429-
type: integer
1430-
topologyKey:
1431-
description: the key of node labels. Nodes that have a label with this key and
1432-
identical values are considered to be in the same topology. We call each
1433-
instance of a topology (in other words, a <key, value> pair) a domain.
1434-
The scheduler will try to put a balanced number of pods into each domain.
1435-
Also, we define an eligible domain as a domain whose nodes meet the
1436-
requirements of nodeAffinityPolicy and nodeTaintsPolicy.
1437-
type: string
1438-
whenUnsatisfiable:
1439-
description: DoNotSchedule (default) tells the scheduler not to schedule it.
1440-
ScheduleAnyway tells the scheduler to still schedule it while prioritizing
1441-
nodes that minimize the skew.
1442-
type: string
14431423
labelSelector:
1444-
description: A label query over a set of resources,
1445-
in this case pods.
1424+
description: LabelSelector is used to find matching pods. Pods
1425+
that match this label selector are counted to determine the
1426+
number of pods in their corresponding topology domain.
14461427
properties:
14471428
matchExpressions:
1448-
description: matchExpressions is a list of label
1449-
selector requirements. The requirements are
1450-
ANDed.
1429+
description: matchExpressions is a list of label selector
1430+
requirements. The requirements are ANDed.
14511431
items:
1452-
description: A label selector requirement
1453-
is a selector that contains values, a key,
1454-
and an operator that relates the key and
1455-
values.
1432+
description: A label selector requirement is a selector
1433+
that contains values, a key, and an operator that relates
1434+
the key and values.
14561435
properties:
14571436
key:
1458-
description: key is the label key that
1459-
the selector applies to.
1437+
description: key is the label key that the selector
1438+
applies to.
14601439
type: string
14611440
operator:
1462-
description: operator represents a key's
1463-
relationship to a set of values. Valid
1464-
operators are In, NotIn, Exists and
1465-
DoesNotExist.
1441+
description: operator represents a key's relationship
1442+
to a set of values. Valid operators are In, NotIn,
1443+
Exists and DoesNotExist.
14661444
type: string
14671445
values:
1468-
description: values is an array of string
1469-
values. If the operator is In or NotIn,
1470-
the values array must be non-empty.
1471-
If the operator is Exists or DoesNotExist,
1472-
the values array must be empty. This
1473-
array is replaced during a strategic
1474-
merge patch.
1446+
description: values is an array of string values.
1447+
If the operator is In or NotIn, the values array
1448+
must be non-empty. If the operator is Exists or
1449+
DoesNotExist, the values array must be empty. This
1450+
array is replaced during a strategic merge patch.
14751451
items:
14761452
type: string
14771453
type: array
14781454
required:
1479-
- key
1480-
- operator
1455+
- key
1456+
- operator
14811457
type: object
14821458
type: array
14831459
matchLabels:
14841460
additionalProperties:
14851461
type: string
1486-
description: matchLabels is a map of {key,value}
1487-
pairs. A single {key,value} in the matchLabels
1488-
map is equivalent to an element of matchExpressions,
1489-
whose key field is "key", the operator is
1490-
"In", and the values array contains only "value".
1491-
The requirements are ANDed.
1462+
description: matchLabels is a map of {key,value} pairs.
1463+
A single {key,value} in the matchLabels map is equivalent
1464+
to an element of matchExpressions, whose key field is
1465+
"key", the operator is "In", and the values array contains
1466+
only "value". The requirements are ANDed.
14921467
type: object
14931468
type: object
14941469
x-kubernetes-map-type: atomic
14951470
matchLabelKeys:
1496-
description: field is a beta-level field and enabled by default in 1.27.
1497-
You can disable it by disabling the MatchLabelKeysInPodTopologySpread
1471+
description: MatchLabelKeys is a set of pod label keys to select
1472+
the pods over which spreading will be calculated. The keys
1473+
are used to lookup values from the incoming pod labels, those
1474+
key-value labels are ANDed with labelSelector to select the
1475+
group of existing pods over which spreading will be calculated
1476+
for the incoming pod. Keys that don't exist in the incoming
1477+
pod labels will be ignored. A null or empty list means only
1478+
match against labelSelector.
14981479
items:
14991480
type: string
15001481
type: array
1482+
x-kubernetes-list-type: atomic
1483+
maxSkew:
1484+
description: 'MaxSkew describes the degree to which pods may
1485+
be unevenly distributed. When `whenUnsatisfiable=DoNotSchedule`,
1486+
it is the maximum permitted difference between the number
1487+
of matching pods in the target topology and the global minimum.
1488+
The global minimum is the minimum number of matching pods
1489+
in an eligible domain or zero if the number of eligible domains
1490+
is less than MinDomains. For example, in a 3-zone cluster,
1491+
MaxSkew is set to 1, and pods with the same labelSelector
1492+
spread as 2/2/1: In this case, the global minimum is 1. |
1493+
zone1 | zone2 | zone3 | | P P | P P | P | - if MaxSkew
1494+
is 1, incoming pod can only be scheduled to zone3 to become
1495+
2/2/2; scheduling it onto zone1(zone2) would make the ActualSkew(3-1)
1496+
on zone1(zone2) violate MaxSkew(1). - if MaxSkew is 2, incoming
1497+
pod can be scheduled onto any zone. When `whenUnsatisfiable=ScheduleAnyway`,
1498+
it is used to give higher precedence to topologies that satisfy
1499+
it. It''s a required field. Default value is 1 and 0 is not
1500+
allowed.'
1501+
format: int32
1502+
type: integer
1503+
minDomains:
1504+
description: "MinDomains indicates a minimum number of eligible
1505+
domains. When the number of eligible domains with matching
1506+
topology keys is less than minDomains, Pod Topology Spread
1507+
treats \"global minimum\" as 0, and then the calculation of
1508+
Skew is performed. And when the number of eligible domains
1509+
with matching topology keys equals or greater than minDomains,
1510+
this value has no effect on scheduling. As a result, when
1511+
the number of eligible domains is less than minDomains, scheduler
1512+
won't schedule more than maxSkew Pods to those domains. If
1513+
value is nil, the constraint behaves as if MinDomains is equal
1514+
to 1. Valid values are integers greater than 0. When value
1515+
is not nil, WhenUnsatisfiable must be DoNotSchedule. \n For
1516+
example, in a 3-zone cluster, MaxSkew is set to 2, MinDomains
1517+
is set to 5 and pods with the same labelSelector spread as
1518+
2/2/2: | zone1 | zone2 | zone3 | | P P | P P | P P |
1519+
The number of domains is less than 5(MinDomains), so \"global
1520+
minimum\" is treated as 0. In this situation, new pod with
1521+
the same labelSelector cannot be scheduled, because computed
1522+
skew will be 3(3 - 0) if new Pod is scheduled to any of the
1523+
three zones, it will violate MaxSkew. \n This is a beta field
1524+
and requires the MinDomainsInPodTopologySpread feature gate
1525+
to be enabled (enabled by default)."
1526+
format: int32
1527+
type: integer
15011528
nodeAffinityPolicy:
1502-
description: indicates how we will treat Pod's nodeAffinity/nodeSelector
1503-
when calculating pod topology spread skew. Options are Honor or Ignore
1529+
description: "NodeAffinityPolicy indicates how we will treat
1530+
Pod's nodeAffinity/nodeSelector when calculating pod topology
1531+
spread skew. Options are: - Honor: only nodes matching nodeAffinity/nodeSelector
1532+
are included in the calculations. - Ignore: nodeAffinity/nodeSelector
1533+
are ignored. All nodes are included in the calculations. \n
1534+
If this value is nil, the behavior is equivalent to the Honor
1535+
policy. This is a beta-level feature default enabled by the
1536+
NodeInclusionPolicyInPodTopologySpread feature flag."
15041537
type: string
15051538
nodeTaintsPolicy:
1506-
description: indicates how we will treat node taints when calculating pod topology spread skew. Honor or Ignore
1539+
description: "NodeTaintsPolicy indicates how we will treat node
1540+
taints when calculating pod topology spread skew. Options
1541+
are: - Honor: nodes without taints, along with tainted nodes
1542+
for which the incoming pod has a toleration, are included.
1543+
- Ignore: node taints are ignored. All nodes are included.
1544+
\n If this value is nil, the behavior is equivalent to the
1545+
Ignore policy. This is a beta-level feature default enabled
1546+
by the NodeInclusionPolicyInPodTopologySpread feature flag."
1547+
type: string
1548+
topologyKey:
1549+
description: TopologyKey is the key of node labels. Nodes that
1550+
have a label with this key and identical values are considered
1551+
to be in the same topology. We consider each <key, value>
1552+
as a "bucket", and try to put balanced number of pods into
1553+
each bucket. We define a domain as a particular instance of
1554+
a topology. Also, we define an eligible domain as a domain
1555+
whose nodes meet the requirements of nodeAffinityPolicy and
1556+
nodeTaintsPolicy. e.g. If TopologyKey is "kubernetes.io/hostname",
1557+
each Node is a domain of that topology. And, if TopologyKey
1558+
is "topology.kubernetes.io/zone", each zone is a domain of
1559+
that topology. It's a required field.
15071560
type: string
1561+
whenUnsatisfiable:
1562+
description: 'WhenUnsatisfiable indicates how to deal with a
1563+
pod if it doesn''t satisfy the spread constraint. - DoNotSchedule
1564+
(default) tells the scheduler not to schedule it. - ScheduleAnyway
1565+
tells the scheduler to schedule the pod in any location, but
1566+
giving higher precedence to topologies that would help reduce
1567+
the skew. A constraint is considered "Unsatisfiable" for an
1568+
incoming pod if and only if every possible node assignment
1569+
for that pod would violate "MaxSkew" on some topology. For
1570+
example, in a 3-zone cluster, MaxSkew is set to 1, and pods
1571+
with the same labelSelector spread as 3/1/1: | zone1 | zone2
1572+
| zone3 | | P P P | P | P | If WhenUnsatisfiable is
1573+
set to DoNotSchedule, incoming pod can only be scheduled to
1574+
zone2(zone3) to become 3/2/1(3/1/2) as ActualSkew(2-1) on
1575+
zone2(zone3) satisfies MaxSkew(1). In other words, the cluster
1576+
can still be imbalanced, but scheduler won''t make it *more*
1577+
imbalanced. It''s a required field.'
1578+
type: string
1579+
required:
1580+
- maxSkew
1581+
- topologyKey
1582+
- whenUnsatisfiable
15081583
type: object
15091584
type: array
15101585
type: object

internal/resources/resources.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ func GetDragonflyResources(ctx context.Context, df *resourcesv1.Dragonfly) ([]cl
168168
if df.Spec.Args != nil {
169169
statefulset.Spec.Template.Spec.Containers[0].Args = append(statefulset.Spec.Template.Spec.Containers[0].Args, df.Spec.Args...)
170170
}
171+
if df.Spec.MemcachedPort != 0 {
172+
statefulset.Spec.Template.Spec.Containers[0].Args = append(statefulset.Spec.Template.Spec.Containers[0].Args, fmt.Sprintf("--memcached_port=%d", df.Spec.MemcachedPort))
173+
}
171174

172175
if df.Spec.AclFromSecret != nil {
173176
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, corev1.Volume{
@@ -374,6 +377,12 @@ func GetDragonflyResources(ctx context.Context, df *resourcesv1.Dragonfly) ([]cl
374377
service.Spec.Type = df.Spec.ServiceSpec.Type
375378
service.Annotations = df.Spec.ServiceSpec.Annotations
376379
}
380+
if df.Spec.MemcachedPort != 0 {
381+
service.Spec.Ports = append(service.Spec.Ports, corev1.ServicePort{
382+
Name: "memcached",
383+
Port: df.Spec.MemcachedPort,
384+
})
385+
}
377386

378387
resources = append(resources, &service)
379388

0 commit comments

Comments
 (0)