Skip to content

Commit

Permalink
Add new structured data type origin for clusteroverridepolicy and ove…
Browse files Browse the repository at this point in the history
…rridepolicy
  • Loading branch information
ryansxy committed Dec 11, 2023
1 parent 8371cf7 commit 2a9a3bc
Show file tree
Hide file tree
Showing 22 changed files with 3,733 additions and 19 deletions.
3 changes: 2 additions & 1 deletion apis/policy/v1alpha1/clustervalidatepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ type ValidateCondition struct {

// ValueProcess defines operation to handle value to compare.
// E.g. operation: '*'
// operationWith: 50% # or 0.5
//
// operationWith: 50% # or 0.5
type ValueProcess struct {
// Operation defines the type of operate value, and it should work with operationWith.
// For example, operation is `*` and operationWith is 0.5 then in cue the value will be multiplied by 0.5.
Expand Down
4 changes: 2 additions & 2 deletions apis/policy/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the policy v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=policy.kcloudlabs.io
// +kubebuilder:object:generate=true
// +groupName=policy.kcloudlabs.io
package v1alpha1

import (
Expand Down
111 changes: 111 additions & 0 deletions apis/policy/v1alpha1/overridepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type ResourceSelector struct {
// - RenderCue
// - Cue
// - Plaintext
// - Origin
type Overriders struct {
// Plaintext represents override rules defined with plaintext overriders.
// +optional
Expand All @@ -106,6 +107,10 @@ type Overriders struct {
// Don't modify the value of this field, modify Rules instead of.
// +optional
RenderedCue string `json:"renderedCue,omitempty"`

// Origin represents override rule defined by K8s origin field.
// +optional
Origin []OverrideRuleOrigin `json:"origin,omitempty"`
}

// OverrideRuleType is definition for type of single override rule template
Expand Down Expand Up @@ -157,6 +162,112 @@ const (
FromHTTP ValueRefFrom = "http"
)

// OverrideRuleOriginType is the definition type of most fields from k8s
// +kubebuilder:validation:Enum=annotations;labels;nodeSelector;hostNetwork;schedulerName;resourceRequirements;resourceOversell;affinity;tolerations;topologySpreadConstraints
type OverrideRuleOriginType string

const (
// OverrideRuleOriginTypeAnnotations - `annotations`
OverrideRuleOriginTypeAnnotations OverrideRuleOriginType = "annotations"
// OverrideRuleOriginLabels - `labels`
OverrideRuleOriginLabels OverrideRuleOriginType = "labels"
// OverrideRuleOriginNodeSelector - `nodeSelector`
OverrideRuleOriginNodeSelector OverrideRuleOriginType = "nodeSelector"
// OverrideRuleOriginHostNetwork - `hostNetwork`
OverrideRuleOriginHostNetwork OverrideRuleOriginType = "hostNetwork"
// OverrideRuleOriginSchedulerName - `schedulerName`
OverrideRuleOriginSchedulerName OverrideRuleOriginType = "schedulerName"
// OverrideRuleOriginResourceRequirements - `resourceRequirements`
OverrideRuleOriginResourceRequirements OverrideRuleOriginType = "resourceRequirements"
// OverrideRuleOriginResourceOversell - `resourceOversell`
OverrideRuleOriginResourceOversell OverrideRuleOriginType = "resourceOversell"
// OverrideRuleOriginAffinity - `affinity`
OverrideRuleOriginAffinity OverrideRuleOriginType = "affinity"
// OverrideRuleOriginTolerations - `tolerations`
OverrideRuleOriginTolerations OverrideRuleOriginType = "tolerations"
// OverrideRuleOriginTopologySpreadConstraints - `topologySpreadConstraints`
OverrideRuleOriginTopologySpreadConstraints OverrideRuleOriginType = "topologySpreadConstraints"
)

type ResourceType string

const (
RequestResourceType ResourceType = "requests"
LimitResourceType ResourceType = "limits"
)

// OverrideRuleOrigin represents a set of rule definition
type OverrideRuleOrigin struct {
// Type represents current rule operate field type.
// +kubebuilder:validation:Enum=annotations;labels;nodeSelector;hostNetwork;schedulerName;resourceRequirements;resourceOversell;affinity;tolerations;topologySpreadConstraints
// +required
Type OverrideRuleOriginType `json:"type,omitempty"`
// Operation represents current operation type.
// +kubebuilder:validation:Enum=add;replace;remove
// +required
Operation OverriderOperator `json:"operation,omitempty"`
// Replace represents whether full replacement is required
// +optional
Replace bool `json:"replace,omitempty"`
// ResourceOversellRule represents the oversold ratio of a resource
// +optional
ResourceOversell map[ResourceType]map[string]Float64 `json:"resourcesOversell,omitempty"`
// ContainerCount represents which container it is, the first container is 0.
// Only affects ResourceRequirements and ResourceOversell
// Note: For the same 'OverrideRuleOrigin', only one of 'ResourceRequirements' and 'ResourceOversell' can be present.
// +optional
ContainerCount int `json:"containerCount,omitempty"`
// ResourceRequirements represents the oversold ratio of a resource
// +optional
ResourceRequirements v1.ResourceRequirements `json:"resourceRequirements,omitempty"`
// If specified, the pod's tolerations.
// +optional
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
// If specified, the pod's scheduling constraints
// +optional
Affinity *v1.Affinity `json:"affinity,omitempty"`
// TopologySpreadConstraints describes how a group of pods ought to spread across topology
// domains. Scheduler will schedule pods in a way which abides by the constraints.
// This field is alpha-level and is only honored by clusters that enables the EvenPodsSpread
// feature.
// All topologySpreadConstraints are ANDed.
// +optional
// +patchMergeKey=topologyKey
// +patchStrategy=merge
// +listType=map
// +listMapKey=topologyKey
// +listMapKey=whenUnsatisfiable
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
// If specified, the pod will be dispatched by specified scheduler.
// If not specified, the pod will be dispatched by default scheduler.
// +optional
SchedulerName string `json:"schedulerName,omitempty"`
// Host networking requested for this pod. Use the host's network namespace.
// If this option is set, the ports that will be used must be specified.
// Default to false.
// +k8s:conversion-gen=false
// +optional
HostNetwork bool `json:"hostNetwork,omitempty"`
// NodeSelector is a selector which must be true for the pod to fit on a node.
// Selector which must match a node's labels for the pod to be scheduled on that node.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +optional
// +mapType=atomic
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Annotations is an unstructured key value map stored with a resource that may be
// set by external tools to store and retrieve arbitrary metadata. They are not
// queryable and should be preserved when modifying objects.
// More info: http://kubernetes.io/docs/user-guide/annotations
// +optional
Annotations map[string]string `json:"annotations,omitempty"`
// Map of string keys and values that can be used to organize and categorize
// (scope and select) objects. May match selectors of replication controllers
// and services.
// More info: http://kubernetes.io/docs/user-guide/labels
// +optional
Labels map[string]string `json:"labels,omitempty"`
}

// OverrideRuleTemplate represents a single template of rule definition
type OverrideRuleTemplate struct {
// Type represents current rule operate field type.
Expand Down
80 changes: 80 additions & 0 deletions apis/policy/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 2a9a3bc

Please sign in to comment.