-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathstructures_admissionregistration.go
More file actions
142 lines (104 loc) · 2.94 KB
/
structures_admissionregistration.go
File metadata and controls
142 lines (104 loc) · 2.94 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright IBM Corp. 2017, 2025
// SPDX-License-Identifier: MPL-2.0
package kubernetes
import (
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/utils/ptr"
)
func flattenServiceReference(in admissionregistrationv1.ServiceReference) []interface{} {
att := map[string]interface{}{}
att["name"] = in.Name
att["namespace"] = in.Namespace
if in.Path != nil {
att["path"] = in.Path
}
if in.Port != nil {
att["port"] = *in.Port
}
return []interface{}{att}
}
func expandServiceReference(l []interface{}) *admissionregistrationv1.ServiceReference {
obj := &admissionregistrationv1.ServiceReference{}
if len(l) == 0 || l[0] == nil {
return obj
}
in := l[0].(map[string]interface{})
if v, ok := in["name"].(string); ok {
obj.Name = v
}
if v, ok := in["namespace"].(string); ok {
obj.Namespace = v
}
if v, ok := in["path"].(string); ok && v != "" {
obj.Path = ptr.To(v)
}
if v, ok := in["port"].(int); ok {
obj.Port = ptr.To(int32(v))
}
return obj
}
func flattenWebhookClientConfig(in admissionregistrationv1.WebhookClientConfig) []interface{} {
att := map[string]interface{}{}
if len(in.CABundle) > 0 {
att["ca_bundle"] = string(in.CABundle)
}
if in.Service != nil {
att["service"] = flattenServiceReference(*in.Service)
}
if in.URL != nil {
att["url"] = *in.URL
}
return []interface{}{att}
}
func expandWebhookClientConfig(l []interface{}) admissionregistrationv1.WebhookClientConfig {
obj := admissionregistrationv1.WebhookClientConfig{}
if len(l) == 0 || l[0] == nil {
return obj
}
in := l[0].(map[string]interface{})
if v, ok := in["ca_bundle"].(string); ok {
obj.CABundle = []byte(v)
}
if v, ok := in["service"].([]interface{}); ok && len(v) > 0 {
obj.Service = expandServiceReference(v)
}
if v, ok := in["url"].(string); ok && v != "" {
obj.URL = ptr.To(v)
}
return obj
}
func flattenRuleWithOperations(in admissionregistrationv1.RuleWithOperations) map[string]interface{} {
att := map[string]interface{}{}
att["api_groups"] = in.APIGroups
att["api_versions"] = in.APIVersions
att["operations"] = in.Operations
att["resources"] = in.Resources
if in.Scope != nil {
att["scope"] = *in.Scope
}
return att
}
func expandRuleWithOperations(in map[string]interface{}) admissionregistrationv1.RuleWithOperations {
obj := admissionregistrationv1.RuleWithOperations{}
if v, ok := in["api_groups"].([]interface{}); ok {
obj.APIGroups = expandStringSlice(v)
}
if v, ok := in["api_versions"].([]interface{}); ok {
obj.APIVersions = expandStringSlice(v)
}
if v, ok := in["operations"].([]interface{}); ok {
for _, op := range v {
if op != nil {
obj.Operations = append(obj.Operations, admissionregistrationv1.OperationType(op.(string)))
}
}
}
if v, ok := in["resources"].([]interface{}); ok {
obj.Resources = expandStringSlice(v)
}
if v, ok := in["scope"].(string); ok {
scope := admissionregistrationv1.ScopeType(v)
obj.Scope = &scope
}
return obj
}