Class: Kubernetes::V1TopologySpreadConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/kubernetes/models/v1_topology_spread_constraint.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ V1TopologySpreadConstraint

Initializes the object

Parameters:

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

    Model attributes in the form of hash



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 83

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

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `Kubernetes::V1TopologySpreadConstraint`. Please check the name to make sure it's valid. List of attributes: " + self.class.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']
  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']
  end

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

Instance Attribute Details

#label_selectorObject

Returns the value of attribute label_selector.



19
20
21
# File 'lib/kubernetes/models/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/kubernetes/models/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/kubernetes/models/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/kubernetes/models/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.



31
32
33
# File 'lib/kubernetes/models/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.



34
35
36
# File 'lib/kubernetes/models/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/kubernetes/models/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.



40
41
42
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 40

def when_unsatisfiable
  @when_unsatisfiable
end

Class Method Details

.acceptable_attributesObject

Returns all the JSON keys this model knows about



57
58
59
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 57

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

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



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 43

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



189
190
191
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 189

def self.build_from_hash(attributes)
  new.build_from_hash(attributes)
end

.openapi_nullableObject

List of attributes with nullable: true



76
77
78
79
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 76

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

.openapi_typesObject

Attribute type mapping.



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 62

def self.openapi_types
  {
    :'label_selector' => :'V1LabelSelector',
    :'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



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 161

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

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 219

def _deserialize(type, value)
  case type.to_sym
  when :Time
    Time.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    # models (e.g. Pet) or oneOf
    klass = Kubernetes.const_get(type)
    klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 290

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
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



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 196

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.openapi_types.each_pair do |key, type|
    if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
      self.send("#{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[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


176
177
178
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 176

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



182
183
184
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 182

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



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 133

def list_invalid_properties
  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_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



266
267
268
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 266

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 272

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

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



260
261
262
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 260

def to_s
  to_hash.to_s
end

#valid?Boolean

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

Returns:

  • (Boolean)

    true if the model is valid



152
153
154
155
156
157
# File 'lib/kubernetes/models/v1_topology_spread_constraint.rb', line 152

def valid?
  return false if @max_skew.nil?
  return false if @topology_key.nil?
  return false if @when_unsatisfiable.nil?
  true
end