Allow tolerationSeconds to be empty on Zone tolerations Requests (#238)

Since toleration seconds can be empty, we were forcing it to be an integer defaulting to 0 which
was creating a toleration with value 0 when value should have been nil.
This commit is contained in:
Cesar N
2020-08-07 20:00:16 -07:00
committed by GitHub
parent 3b123c6182
commit 47274817fa
6 changed files with 168 additions and 27 deletions

View File

@@ -214,13 +214,6 @@ func getTenant(ctx context.Context, operatorClient OperatorClient, namespace, te
}
func getTenantInfo(tenant *operator.Tenant) *models.Tenant {
var instanceCount int64
var volumeCount int64
for _, zone := range tenant.Spec.Zones {
instanceCount = instanceCount + int64(zone.Servers)
volumeCount = volumeCount + int64(zone.Servers*zone.VolumesPerServer)
}
var zones []*models.Zone
var totalSize int64
@@ -1233,12 +1226,18 @@ func parseTenantZoneRequest(zoneParams *models.Zone, annotations map[string]stri
// parse tolerations
tolerations := []corev1.Toleration{}
for _, elem := range zoneParams.Tolerations {
var tolerationSeconds *int64
if elem.TolerationSeconds != nil {
// elem.TolerationSeconds.Seconds is allowed to be nil
tolerationSeconds = elem.TolerationSeconds.Seconds
}
toleration := corev1.Toleration{
Key: elem.Key,
Operator: corev1.TolerationOperator(elem.Operator),
Value: elem.Value,
Effect: corev1.TaintEffect(elem.Effect),
TolerationSeconds: &elem.TolerationSeconds,
TolerationSeconds: tolerationSeconds,
}
tolerations = append(tolerations, toleration)
}
@@ -1434,12 +1433,18 @@ func parseTenantZone(zone *operator.Zone) *models.Zone {
// parse tolerations
var tolerations models.ZoneTolerations
for _, elem := range zone.Tolerations {
var tolerationSecs *models.ZoneTolerationSeconds
if elem.TolerationSeconds != nil {
tolerationSecs = &models.ZoneTolerationSeconds{
Seconds: elem.TolerationSeconds,
}
}
toleration := &models.ZoneTolerationsItems0{
Key: elem.Key,
Operator: string(elem.Operator),
Value: elem.Value,
Effect: string(elem.Effect),
TolerationSeconds: *elem.TolerationSeconds,
TolerationSeconds: tolerationSecs,
}
tolerations = append(tolerations, toleration)
}

View File

@@ -3378,6 +3378,19 @@ func init() {
}
}
},
"zoneTolerationSeconds": {
"description": "TolerationSeconds represents the period of time the toleration (which must be of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, it is not set, which means tolerate the taint forever (do not evict). Zero and negative values will be treated as 0 (evict immediately) by the system.",
"type": "object",
"required": [
"seconds"
],
"properties": {
"seconds": {
"type": "integer",
"format": "int64"
}
}
},
"zoneTolerations": {
"description": "Tolerations allows users to set entries like effect, key, operator, value.",
"type": "array",
@@ -3398,9 +3411,7 @@ func init() {
"type": "string"
},
"tolerationSeconds": {
"description": "TolerationSeconds represents the period of time the toleration (which must be of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, it is not set, which means tolerate the taint forever (do not evict). Zero and negative values will be treated as 0 (evict immediately) by the system.",
"type": "integer",
"format": "int64"
"$ref": "#/definitions/zoneTolerationSeconds"
},
"value": {
"description": "Value is the taint value the toleration matches to. If the operator is Exists, the value should be empty, otherwise just a regular string.",
@@ -5675,9 +5686,7 @@ func init() {
"type": "string"
},
"tolerationSeconds": {
"description": "TolerationSeconds represents the period of time the toleration (which must be of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, it is not set, which means tolerate the taint forever (do not evict). Zero and negative values will be treated as 0 (evict immediately) by the system.",
"type": "integer",
"format": "int64"
"$ref": "#/definitions/zoneTolerationSeconds"
},
"value": {
"description": "Value is the taint value the toleration matches to. If the operator is Exists, the value should be empty, otherwise just a regular string.",
@@ -7184,6 +7193,19 @@ func init() {
}
}
},
"zoneTolerationSeconds": {
"description": "TolerationSeconds represents the period of time the toleration (which must be of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, it is not set, which means tolerate the taint forever (do not evict). Zero and negative values will be treated as 0 (evict immediately) by the system.",
"type": "object",
"required": [
"seconds"
],
"properties": {
"seconds": {
"type": "integer",
"format": "int64"
}
}
},
"zoneTolerations": {
"description": "Tolerations allows users to set entries like effect, key, operator, value.",
"type": "array",