Skip to content

Commit 1c6d384

Browse files
authored
Merge pull request #411 from vincepri/generate-marker-help
🏃 Make webhook marker MatchPolicy optional
2 parents 65bd5c2 + 932c305 commit 1c6d384

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

pkg/webhook/parser.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type Config struct {
6060
// MatchPolicy defines how the "rules" list is used to match incoming requests.
6161
// Allowed values are "Exact" (match only if it exactly matches the specified rule)
6262
// or "Equivalent" (match a request if it modifies a resource listed in rules, even via another API group or version).
63-
MatchPolicy string
63+
MatchPolicy string `marker:",optional"`
6464

6565
// Groups specifies the API groups that this webhook receives requests for.
6666
Groups []string
@@ -111,11 +111,16 @@ func (c Config) ToMutatingWebhook() (admissionreg.MutatingWebhook, error) {
111111
return admissionreg.MutatingWebhook{}, fmt.Errorf("%s is a validating webhook", c.Name)
112112
}
113113

114+
matchPolicy, err := c.matchPolicy()
115+
if err != nil {
116+
return admissionreg.MutatingWebhook{}, err
117+
}
118+
114119
return admissionreg.MutatingWebhook{
115120
Name: c.Name,
116121
Rules: c.rules(),
117122
FailurePolicy: c.failurePolicy(),
118-
MatchPolicy: c.matchPolicy(),
123+
MatchPolicy: matchPolicy,
119124
ClientConfig: c.clientConfig(),
120125
}, nil
121126
}
@@ -126,11 +131,16 @@ func (c Config) ToValidatingWebhook() (admissionreg.ValidatingWebhook, error) {
126131
return admissionreg.ValidatingWebhook{}, fmt.Errorf("%s is a mutating webhook", c.Name)
127132
}
128133

134+
matchPolicy, err := c.matchPolicy()
135+
if err != nil {
136+
return admissionreg.ValidatingWebhook{}, err
137+
}
138+
129139
return admissionreg.ValidatingWebhook{
130140
Name: c.Name,
131141
Rules: c.rules(),
132142
FailurePolicy: c.failurePolicy(),
133-
MatchPolicy: c.matchPolicy(),
143+
MatchPolicy: matchPolicy,
134144
ClientConfig: c.clientConfig(),
135145
}, nil
136146
}
@@ -177,18 +187,17 @@ func (c Config) failurePolicy() *admissionreg.FailurePolicyType {
177187
}
178188

179189
// matchPolicy converts the string value to the proper value for the API.
180-
// Unrecognized values are passed through.
181-
func (c Config) matchPolicy() *admissionreg.MatchPolicyType {
190+
func (c Config) matchPolicy() (*admissionreg.MatchPolicyType, error) {
182191
var matchPolicy admissionreg.MatchPolicyType
183192
switch strings.ToLower(c.MatchPolicy) {
184193
case strings.ToLower(string(admissionreg.Exact)):
185194
matchPolicy = admissionreg.Exact
186195
case strings.ToLower(string(admissionreg.Equivalent)):
187196
matchPolicy = admissionreg.Equivalent
188197
default:
189-
matchPolicy = admissionreg.MatchPolicyType(c.MatchPolicy)
198+
return nil, fmt.Errorf("unknown value %q for matchPolicy", c.MatchPolicy)
190199
}
191-
return &matchPolicy
200+
return &matchPolicy, nil
192201
}
193202

194203
// clientConfig returns the client config for a webhook.

pkg/webhook/zz_generated.markerhelp.go

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)