Skip to content

Commit

Permalink
Add placementStrategy API
Browse files Browse the repository at this point in the history
Signed-off-by: melserngawy <melserng@redhat.com>
  • Loading branch information
serngawy committed May 29, 2023
1 parent b0c740d commit 02c9225
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,144 @@ spec:
items:
type: string
type: array
decisionStrategy:
description: Decision Strategy divide the created placement decision
to groups and define number of clusters per decision group.
properties:
clustersPerDecisionGroup:
anyOf:
- type: integer
- type: string
default: 100%
description: ClustersPerDecisionGroup is a specific number or
percentage of the total selected clusters. The specific number
will divide the placementDecisions to decisionGroups each group
has max number of clusters equal to that specific number. The
percentage will divide the placementDecisions to decisionGroups
each group has max number of clusters based on the total num
of selected clusters and percentage. ex; for a total 100 clusters
selected, ClustersPerDecisionGroup equal to 20% will divide
the placement decision to 5 groups each group should have 20
clusters. Default is having all clusters in a single group.
enum:
- 5%
- 10%
- 15%
- 20%
- 25%
- 30%
- 40%
- 50%
- 75%
- 100%
x-kubernetes-int-or-string: true
decisionGroups:
description: Define subsets of the created placement decisions
and add labels to the placementDecision.
items:
description: Subset of the created placementDecision with label.
properties:
groupClusterSelector:
description: LabelSelector to select clusters subset by
label.
properties:
claimSelector:
description: ClaimSelector represents a selector of
ManagedClusters by clusterClaims in status
properties:
matchExpressions:
description: matchExpressions is a list of cluster
claim 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
type: object
labelSelector:
description: LabelSelector represents a selector of
ManagedClusters by label
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:
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
type: object
name:
description: name to be added to the created placement Decisions
labels with label key cluster.open-cluster-management.io/decisiongroupname
type: string
required:
- groupClusterSelector
- name
type: object
type: array
type: object
numberOfClusters:
description: NumberOfClusters represents the desired number of ManagedClusters
to be selected which meet the placement requirements. 1) If not
Expand Down Expand Up @@ -466,6 +604,38 @@ spec:
- type
type: object
type: array
decisionGroups:
description: List of decision groups determined by the placement and
placement strategy.
items:
description: Present decision groups status based on the DecisionStrategy
definition.
properties:
clusterCount:
default: 0
description: Total number of clusters in the decision group.
Clusters count is equal or less than the max number of clusters
per decision group defined in the decision strategy.
format: int32
type: integer
decisionGroupIndex:
description: Present the decision group index. If there is no
decision strategy defined all placement decisions will be
in group index 0
format: int32
type: integer
decisionGroupName:
description: Decision group name that is defined in the DecisionStrategy's
DecisionGroup.
type: string
placementDecisions:
description: List of placement decisions names associated with
the decision group
items:
type: string
type: array
type: object
type: array
numberOfSelectedClusters:
description: NumberOfSelectedClusters represents the number of selected
ManagedClusters
Expand Down
59 changes: 59 additions & 0 deletions cluster/v1beta1/types_placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
v1 "open-cluster-management.io/api/cluster/v1"
)

Expand Down Expand Up @@ -94,6 +95,40 @@ type PlacementSpec struct {
// certain taints to be selected by placements with matching tolerations.
// +optional
Tolerations []Toleration `json:"tolerations,omitempty"`

// Decision Strategy divide the created placement decision to groups and define number of clusters per decision group.
// +optional
DecisionStrategy DecisionStrategy `json:"decisionStrategy,omitempty"`
}

// Subset of the created placementDecision with label.
type DecisionGroup struct {
// name to be added to the created placement Decisions labels with label key cluster.open-cluster-management.io/decisiongroupname
// +kubebuilder:validation:Required
// +required
Name string `json:"name,omitempty"`

// LabelSelector to select clusters subset by label.
// +kubebuilder:validation:Required
// +required
ClusterSelector ClusterSelector `json:"groupClusterSelector,omitempty"`
}

// Group the created placementDecision into decision groups based on the number of clusters per decision group.
type DecisionStrategy struct {
// Define subsets of the created placement decisions and add labels to the placementDecision.
// +optional
DecisionGroups []DecisionGroup `json:"decisionGroups,omitempty"`

// ClustersPerDecisionGroup is a specific number or percentage of the total selected clusters.
// The specific number will divide the placementDecisions to decisionGroups each group has max number of clusters equal to that specific number.
// The percentage will divide the placementDecisions to decisionGroups each group has max number of clusters based on the total num of selected clusters and percentage.
// ex; for a total 100 clusters selected, ClustersPerDecisionGroup equal to 20% will divide the placement decision to 5 groups each group should have 20 clusters.
// Default is having all clusters in a single group.
// +kubebuilder:validation:Enum="5%";"10%";"15%";"20%";"25%";"30%";"40%";"50%";"75%";"100%"
// +kubebuilder:default:="100%"
// +optional
ClustersPerDecisionGroup intstr.IntOrString `json:"clustersPerDecisionGroup,omitempty"`
}

// ClusterPredicate represents a predicate to select ManagedClusters.
Expand Down Expand Up @@ -329,11 +364,35 @@ const (
TolerationOpEqual TolerationOperator = "Equal"
)

// Present decision groups status based on the DecisionStrategy definition.
type DecisionGroupStatus struct {
// Present the decision group index. If there is no decision strategy defined all placement decisions will be in group index 0
// +optional
DecisionGroupIndex int32 `json:"decisionGroupIndex"`

// Decision group name that is defined in the DecisionStrategy's DecisionGroup.
// +optional
DecisionGroupName string `json:"decisionGroupName"`

// List of placement decisions names associated with the decision group
// +optional
PlacementDecisions []string `json:"placementDecisions"`

// Total number of clusters in the decision group. Clusters count is equal or less than the max number of clusters per decision group defined in the decision strategy.
// +kubebuilder:default:=0
// +optional
ClustersCount int32 `json:"clusterCount"`
}

type PlacementStatus struct {
// NumberOfSelectedClusters represents the number of selected ManagedClusters
// +optional
NumberOfSelectedClusters int32 `json:"numberOfSelectedClusters"`

// List of decision groups determined by the placement and placement strategy.
// +optional
DecisionGroups []DecisionGroupStatus `json:"decisionGroups"`

// Conditions contains the different condition status for this Placement.
// +optional
Conditions []metav1.Condition `json:"conditions"`
Expand Down
5 changes: 5 additions & 0 deletions cluster/v1beta1/types_placementdecision.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ type PlacementDecision struct {

// The placementDecsion label name holding the placement name
const (
// Placement owner name.
PlacementLabel string = "cluster.open-cluster-management.io/placement"
// decision group index.
DecisionGroupIndexLabel string = "cluster.open-cluster-management.io/decisiongroupindex"
// decision group label.
DecisionGroupName string = "cluster.open-cluster-management.io/decisiongroupname"
)

// PlacementDecisionStatus represents the current status of the PlacementDecision.
Expand Down
34 changes: 34 additions & 0 deletions cluster/v1beta1/zz_generated.swagger_doc_generated.go

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

0 comments on commit 02c9225

Please sign in to comment.