-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathstructure_pod_disruption_budget.go
More file actions
47 lines (40 loc) · 1.23 KB
/
structure_pod_disruption_budget.go
File metadata and controls
47 lines (40 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright IBM Corp. 2017, 2025
// SPDX-License-Identifier: MPL-2.0
package kubernetes
import (
"fmt"
api "k8s.io/api/policy/v1beta1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func expandPodDisruptionBudgetSpec(in []interface{}) (*api.PodDisruptionBudgetSpec, error) {
spec := &api.PodDisruptionBudgetSpec{}
if len(in) == 0 || in[0] == nil {
return nil, fmt.Errorf("failed to expand PodDisruptionBudget.Spec: null or empty input")
}
m := in[0].(map[string]interface{})
if v, ok := m["max_unavailable"].(string); ok && len(v) > 0 {
val := intstr.Parse(v)
spec.MaxUnavailable = &val
}
if v, ok := m["min_available"].(string); ok && len(v) > 0 {
val := intstr.Parse(v)
spec.MinAvailable = &val
}
if v, ok := m["selector"].([]interface{}); ok && len(v) > 0 {
spec.Selector = expandLabelSelector(v)
}
return spec, nil
}
func flattenPodDisruptionBudgetSpec(spec api.PodDisruptionBudgetSpec) []interface{} {
m := make(map[string]interface{}, 0)
if spec.MaxUnavailable != nil {
m["max_unavailable"] = spec.MaxUnavailable.String()
}
if spec.MinAvailable != nil {
m["min_available"] = spec.MinAvailable.String()
}
if spec.Selector != nil {
m["selector"] = flattenLabelSelector(spec.Selector)
}
return []interface{}{m}
}