Class: Kubevirt::K8sIoApiCoreV1TopologySpreadConstraint

Inherits:
ApiModelBase
  • Object
show all
Defined in:
lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb

Overview

TopologySpreadConstraint specifies how to spread matching pods among the given topology.

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiModelBase

_deserialize, #_to_hash, #to_body, #to_s

Constructor Details

#initialize(attributes = {}) ⇒ K8sIoApiCoreV1TopologySpreadConstraint

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 110

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `Kubevirt::K8sIoApiCoreV1TopologySpreadConstraint` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  acceptable_attribute_map = self.class.acceptable_attribute_map
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!acceptable_attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `Kubevirt::K8sIoApiCoreV1TopologySpreadConstraint`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'label_selector')
    self.label_selector = attributes[:'label_selector']
  end

  if attributes.key?(:'match_label_keys')
    if (value = attributes[:'match_label_keys']).is_a?(Array)
      self.match_label_keys = value
    end
  end

  if attributes.key?(:'max_skew')
    self.max_skew = attributes[:'max_skew']
  else
    self.max_skew = 0
  end

  if attributes.key?(:'min_domains')
    self.min_domains = attributes[:'min_domains']
  end

  if attributes.key?(:'node_affinity_policy')
    self.node_affinity_policy = attributes[:'node_affinity_policy']
  end

  if attributes.key?(:'node_taints_policy')
    self.node_taints_policy = attributes[:'node_taints_policy']
  end

  if attributes.key?(:'topology_key')
    self.topology_key = attributes[:'topology_key']
  else
    self.topology_key = ''
  end

  if attributes.key?(:'when_unsatisfiable')
    self.when_unsatisfiable = attributes[:'when_unsatisfiable']
  else
    self.when_unsatisfiable = ''
  end
end

Instance Attribute Details

#label_selectorObject

Returns the value of attribute label_selector.



19
20
21
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 19

def label_selector
  @label_selector
end

#match_label_keysObject

MatchLabelKeys is a set of pod label keys to select the pods over which spreading will be calculated. The keys are used to lookup values from the incoming pod labels, those key-value labels are ANDed with labelSelector to select the group of existing pods over which spreading will be calculated for the incoming pod. The same key is forbidden to exist in both MatchLabelKeys and LabelSelector. MatchLabelKeys cannot be set when LabelSelector isn’t set. Keys that don’t exist in the incoming pod labels will be ignored. A null or empty list means only match against labelSelector. This is a beta field and requires the MatchLabelKeysInPodTopologySpread feature gate to be enabled (enabled by default).



22
23
24
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 22

def match_label_keys
  @match_label_keys
end

#max_skewObject

MaxSkew describes the degree to which pods may be unevenly distributed. When ‘whenUnsatisfiable=DoNotSchedule`, it is the maximum permitted difference between the number of matching pods in the target topology and the global minimum. The global minimum is the minimum number of matching pods in an eligible domain or zero if the number of eligible domains is less than MinDomains. For example, in a 3-zone cluster, MaxSkew is set to 1, and pods with the same labelSelector spread as 2/2/1: In this case, the global minimum is 1. | zone1 | zone2 | zone3 | | P P | P P | P | - if MaxSkew is 1, incoming pod can only be scheduled to zone3 to become 2/2/2; scheduling it onto zone1(zone2) would make the ActualSkew(3-1) on zone1(zone2) violate MaxSkew(1). - if MaxSkew is 2, incoming pod can be scheduled onto any zone. When `whenUnsatisfiable=ScheduleAnyway`, it is used to give higher precedence to topologies that satisfy it. It’s a required field. Default value is 1 and 0 is not allowed.



25
26
27
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 25

def max_skew
  @max_skew
end

#min_domainsObject

MinDomains indicates a minimum number of eligible domains. When the number of eligible domains with matching topology keys is less than minDomains, Pod Topology Spread treats "global minimum" as 0, and then the calculation of Skew is performed. And when the number of eligible domains with matching topology keys equals or greater than minDomains, this value has no effect on scheduling. As a result, when the number of eligible domains is less than minDomains, scheduler won’t schedule more than maxSkew Pods to those domains. If value is nil, the constraint behaves as if MinDomains is equal to 1. Valid values are integers greater than 0. When value is not nil, WhenUnsatisfiable must be DoNotSchedule. For example, in a 3-zone cluster, MaxSkew is set to 2, MinDomains is set to 5 and pods with the same labelSelector spread as 2/2/2: | zone1 | zone2 | zone3 | | P P | P P | P P | The number of domains is less than 5(MinDomains), so "global minimum" is treated as 0. In this situation, new pod with the same labelSelector cannot be scheduled, because computed skew will be 3(3 - 0) if new Pod is scheduled to any of the three zones, it will violate MaxSkew.



28
29
30
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 28

def min_domains
  @min_domains
end

#node_affinity_policyObject

NodeAffinityPolicy indicates how we will treat Pod’s nodeAffinity/nodeSelector when calculating pod topology spread skew. Options are: - Honor: only nodes matching nodeAffinity/nodeSelector are included in the calculations. - Ignore: nodeAffinity/nodeSelector are ignored. All nodes are included in the calculations. If this value is nil, the behavior is equivalent to the Honor policy. Possible enum values: - ‘"Honor"` means use this scheduling directive when calculating pod topology spread skew. - `"Ignore"` means ignore this scheduling directive when calculating pod topology spread skew.



31
32
33
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 31

def node_affinity_policy
  @node_affinity_policy
end

#node_taints_policyObject

NodeTaintsPolicy indicates how we will treat node taints when calculating pod topology spread skew. Options are: - Honor: nodes without taints, along with tainted nodes for which the incoming pod has a toleration, are included. - Ignore: node taints are ignored. All nodes are included. If this value is nil, the behavior is equivalent to the Ignore policy. Possible enum values: - ‘"Honor"` means use this scheduling directive when calculating pod topology spread skew. - `"Ignore"` means ignore this scheduling directive when calculating pod topology spread skew.



34
35
36
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 34

def node_taints_policy
  @node_taints_policy
end

#topology_keyObject

TopologyKey is the key of node labels. Nodes that have a label with this key and identical values are considered to be in the same topology. We consider each <key, value> as a "bucket", and try to put balanced number of pods into each bucket. We define a domain as a particular instance of a topology. Also, we define an eligible domain as a domain whose nodes meet the requirements of nodeAffinityPolicy and nodeTaintsPolicy. e.g. If TopologyKey is "kubernetes.io/hostname", each Node is a domain of that topology. And, if TopologyKey is "topology.kubernetes.io/zone", each zone is a domain of that topology. It’s a required field.



37
38
39
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 37

def topology_key
  @topology_key
end

#when_unsatisfiableObject

WhenUnsatisfiable indicates how to deal with a pod if it doesn’t satisfy the spread constraint. - DoNotSchedule (default) tells the scheduler not to schedule it. - ScheduleAnyway tells the scheduler to schedule the pod in any location, but giving higher precedence to topologies that would help reduce the skew. A constraint is considered "Unsatisfiable" for an incoming pod if and only if every possible node assignment for that pod would violate "MaxSkew" on some topology. For example, in a 3-zone cluster, MaxSkew is set to 1, and pods with the same labelSelector spread as 3/1/1: | zone1 | zone2 | zone3 | | P P P | P | P | If WhenUnsatisfiable is set to DoNotSchedule, incoming pod can only be scheduled to zone2(zone3) to become 3/2/1(3/1/2) as ActualSkew(2-1) on zone2(zone3) satisfies MaxSkew(1). In other words, the cluster can still be imbalanced, but scheduler won’t make it more imbalanced. It’s a required field. Possible enum values: - ‘"DoNotSchedule"` instructs the scheduler not to schedule the pod when constraints are not satisfied. - `"ScheduleAnyway"` instructs the scheduler to schedule the pod even if constraints are not satisfied.



40
41
42
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 40

def when_unsatisfiable
  @when_unsatisfiable
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



79
80
81
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 79

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



84
85
86
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 84

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 65

def self.attribute_map
  {
    :'label_selector' => :'labelSelector',
    :'match_label_keys' => :'matchLabelKeys',
    :'max_skew' => :'maxSkew',
    :'min_domains' => :'minDomains',
    :'node_affinity_policy' => :'nodeAffinityPolicy',
    :'node_taints_policy' => :'nodeTaintsPolicy',
    :'topology_key' => :'topologyKey',
    :'when_unsatisfiable' => :'whenUnsatisfiable'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 281

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



103
104
105
106
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 103

def self.openapi_nullable
  Set.new([
  ])
end

.openapi_typesObject

Attribute type mapping.



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 89

def self.openapi_types
  {
    :'label_selector' => :'K8sIoApimachineryPkgApisMetaV1LabelSelector',
    :'match_label_keys' => :'Array<String>',
    :'max_skew' => :'Integer',
    :'min_domains' => :'Integer',
    :'node_affinity_policy' => :'String',
    :'node_taints_policy' => :'String',
    :'topology_key' => :'String',
    :'when_unsatisfiable' => :'String'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 253

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      label_selector == o.label_selector &&
      match_label_keys == o.match_label_keys &&
      max_skew == o.max_skew &&
      min_domains == o.min_domains &&
      node_affinity_policy == o.node_affinity_policy &&
      node_taints_policy == o.node_taints_policy &&
      topology_key == o.topology_key &&
      when_unsatisfiable == o.when_unsatisfiable
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


268
269
270
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 268

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



274
275
276
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 274

def hash
  [label_selector, match_label_keys, max_skew, min_domains, node_affinity_policy, node_taints_policy, topology_key, when_unsatisfiable].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 167

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  if @max_skew.nil?
    invalid_properties.push('invalid value for "max_skew", max_skew cannot be nil.')
  end

  if @topology_key.nil?
    invalid_properties.push('invalid value for "topology_key", topology_key cannot be nil.')
  end

  if @when_unsatisfiable.nil?
    invalid_properties.push('invalid value for "when_unsatisfiable", when_unsatisfiable cannot be nil.')
  end

  invalid_properties
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 303

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/kubevirt/models/k8s_io_api_core_v1_topology_spread_constraint.rb', line 187

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  return false if @max_skew.nil?
  node_affinity_policy_validator = EnumAttributeValidator.new('String', ["Honor", "Ignore"])
  return false unless node_affinity_policy_validator.valid?(@node_affinity_policy)
  node_taints_policy_validator = EnumAttributeValidator.new('String', ["Honor", "Ignore"])
  return false unless node_taints_policy_validator.valid?(@node_taints_policy)
  return false if @topology_key.nil?
  return false if @when_unsatisfiable.nil?
  when_unsatisfiable_validator = EnumAttributeValidator.new('String', ["DoNotSchedule", "ScheduleAnyway"])
  return false unless when_unsatisfiable_validator.valid?(@when_unsatisfiable)
  true
end