Skip to content

Commit ae70162

Browse files
authored
Merge pull request kubernetes-retired#205 from erikgb/fix/validation-todos
Remove obsolete validation TODOs
2 parents fdf83ab + ecbb645 commit ae70162

File tree

4 files changed

+0
-16
lines changed

4 files changed

+0
-16
lines changed

internal/anchor/validator.go

-3
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,11 @@ func (v *Validator) handle(req *anchorRequest) admission.Response {
9797
// Can't create subnamespaces in unmanaged namespaces
9898
if why := config.WhyUnmanaged(pnm); why != "" {
9999
err := fmt.Errorf("cannot create a subnamespace in the unmanaged namespace %q (%s)", pnm, why)
100-
// TODO(erikgb): Add to list of Invalid field errors?
101100
return webhooks.DenyForbidden(api.SubnamespaceAnchorGR, pnm, err)
102101
}
103102
// Can't create subnamespaces using unmanaged namespace names
104103
if why := config.WhyUnmanaged(cnm); why != "" {
105104
err := fmt.Errorf("cannot create a subnamespace using the unmanaged namespace name %q (%s)", cnm, why)
106-
// TODO(erikgb): Add to list of Invalid field errors?
107105
return webhooks.DenyForbidden(api.SubnamespaceAnchorGR, cnm, err)
108106
}
109107

@@ -113,7 +111,6 @@ func (v *Validator) handle(req *anchorRequest) admission.Response {
113111
childIsMissingAnchor := (cns.Parent().Name() == pnm && cns.IsSub)
114112
if !childIsMissingAnchor {
115113
err := errors.New("cannot create a subnamespace using an existing namespace")
116-
// TODO(erikgb): Add to list of Invalid field errors?
117114
return webhooks.DenyConflict(api.SubnamespaceAnchorGR, cnm, err)
118115
}
119116
}

internal/hierarchyconfig/validator.go

-7
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,10 @@ func (v *Validator) handle(ctx context.Context, log logr.Logger, req *request) a
123123

124124
if why := config.WhyUnmanaged(req.hc.Namespace); why != "" {
125125
err := fmt.Errorf("namespace %q is not managed by HNC (%s) and cannot be set as a child of another namespace", req.hc.Namespace, why)
126-
// TODO(erikgb): Invalid field error better?
127126
return webhooks.DenyForbidden(api.HierarchyConfigurationGR, api.Singleton, err)
128127
}
129128
if why := config.WhyUnmanaged(req.hc.Spec.Parent); why != "" {
130129
err := fmt.Errorf("namespace %q is not managed by HNC (%s) and cannot be set as the parent of another namespace", req.hc.Spec.Parent, why)
131-
// TODO(erikgb): Invalid field error better?
132130
return webhooks.DenyForbidden(api.HierarchyConfigurationGR, api.Singleton, err)
133131
}
134132

@@ -190,7 +188,6 @@ func (v *Validator) checkNS(ns *forest.Namespace) admission.Response {
190188
haltedRoot := ns.GetHaltedRoot()
191189
if haltedRoot != "" && haltedRoot != ns.Name() {
192190
err := fmt.Errorf("ancestor %q of namespace %q has a critical condition, which must be resolved before any changes can be made to the hierarchy configuration", haltedRoot, ns.Name())
193-
// TODO(erikgb): InternalError better?
194191
return webhooks.DenyForbidden(api.HierarchyConfigurationGR, api.Singleton, err)
195192
}
196193

@@ -201,7 +198,6 @@ func (v *Validator) checkNS(ns *forest.Namespace) admission.Response {
201198
func (v *Validator) checkParent(ns, curParent, newParent *forest.Namespace) admission.Response {
202199
if ns.IsExternal() && newParent != nil {
203200
err := fmt.Errorf("namespace %q is managed by %q, not HNC, so it cannot have a parent in HNC", ns.Name(), ns.Manager)
204-
// TODO(erikgb): Invalid field error better?
205201
return webhooks.DenyForbidden(api.HierarchyConfigurationGR, api.Singleton, err)
206202
}
207203

@@ -212,14 +208,12 @@ func (v *Validator) checkParent(ns, curParent, newParent *forest.Namespace) admi
212208
// Prevent changing parent of a subnamespace
213209
if ns.IsSub {
214210
err := fmt.Errorf("illegal parent: Cannot set the parent of %q to %q because it's a subnamespace of %q", ns.Name(), newParent.Name(), curParent.Name())
215-
// TODO(erikgb): Invalid field error better?
216211
return webhooks.DenyConflict(api.HierarchyConfigurationGR, api.Singleton, err)
217212
}
218213

219214
// non existence of parent namespace -> not allowed
220215
if newParent != nil && !newParent.Exists() {
221216
err := fmt.Errorf("requested parent %q does not exist", newParent.Name())
222-
// TODO(erikgb): Invalid field error better?
223217
return webhooks.DenyForbidden(api.HierarchyConfigurationGR, api.Singleton, err)
224218
}
225219

@@ -230,7 +224,6 @@ func (v *Validator) checkParent(ns, curParent, newParent *forest.Namespace) admi
230224
// parent conflicts with something in the _existing_ hierarchy.
231225
if reason := ns.CanSetParent(newParent); reason != "" {
232226
err := fmt.Errorf("illegal parent: %s", reason)
233-
// TODO(erikgb): Invalid field error better?
234227
return webhooks.DenyConflict(api.HierarchyConfigurationGR, api.Singleton, err)
235228
}
236229

internal/hncconfig/validator.go

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func (v *Validator) Handle(ctx context.Context, req admission.Request) admission
4949
if req.Operation == k8sadm.Delete {
5050
if req.Name == api.HNCConfigSingleton {
5151
err := errors.New("deleting the 'config' object is forbidden")
52-
// TODO(erikgb): MethodNotSupported error better?
5352
return webhooks.DenyForbidden(api.HNCConfigurationGR, api.HNCConfigSingleton, err)
5453
} else {
5554
// We allow deleting other objects. We should never enter this case with the CRD validation. We introduced

internal/namespace/validator.go

-5
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ func (v *Validator) illegalTreeLabel(req *nsRequest) admission.Response {
136136
// Check if new HNC label tree key isn't being added
137137
if oldLabels[key] != val {
138138
err := fmt.Errorf("cannot set or modify tree label %q in namespace %q; these can only be managed by HNC", key, req.ns.Name)
139-
// TODO(erikgb): Invalid field error list better?
140139
return webhooks.DenyForbidden(namespaceGR, req.ns.Name, err)
141140
}
142141
}
@@ -146,7 +145,6 @@ func (v *Validator) illegalTreeLabel(req *nsRequest) admission.Response {
146145
if strings.Contains(key, api.LabelTreeDepthSuffix) {
147146
if _, ok := req.ns.Labels[key]; !ok {
148147
err := fmt.Errorf("cannot remove tree label %q in namespace %q; these can only be managed by HNC", key, req.ns.Name)
149-
// TODO(erikgb): Invalid field error list better?
150148
return webhooks.DenyForbidden(namespaceGR, req.ns.Name, err)
151149
}
152150
}
@@ -175,7 +173,6 @@ func (v *Validator) illegalIncludedNamespaceLabel(req *nsRequest) admission.Resp
175173
err := fmt.Errorf("you cannot enforce webhook rules on this unmanaged namespace using the %q label. "+
176174
"See https://github.com/kubernetes-sigs/hierarchical-namespaces/blob/master/docs/user-guide/concepts.md#included-namespace-label "+
177175
"for detail", api.LabelIncludedNamespace)
178-
// TODO(erikgb): Invalid field error better?
179176
return webhooks.DenyForbidden(namespaceGR, req.ns.Name, err)
180177
}
181178

@@ -187,7 +184,6 @@ func (v *Validator) illegalIncludedNamespaceLabel(req *nsRequest) admission.Resp
187184
err := fmt.Errorf("you cannot change the value of the %q label. It has to be set as true on all managed namespaces. "+
188185
"See https://github.com/kubernetes-sigs/hierarchical-namespaces/blob/master/docs/user-guide/concepts.md#included-namespace-label "+
189186
"for detail", api.LabelIncludedNamespace)
190-
// TODO(erikgb): Invalid field error better?
191187
return webhooks.DenyForbidden(namespaceGR, req.ns.Name, err)
192188
}
193189

@@ -220,7 +216,6 @@ func (v *Validator) conflictBetweenParentAndExternalManager(req *nsRequest, ns *
220216
if mgr != "" && mgr != api.MetaGroup && ns.Parent() != nil {
221217
err := fmt.Errorf("is a child of %q. Namespaces with parents defined by HNC cannot also be managed externally. "+
222218
"To manage this namespace with %q, first make it a root in HNC", ns.Parent().Name(), mgr)
223-
// TODO(erikgb): Conflict error better?
224219
return webhooks.DenyForbidden(namespaceGR, req.ns.Name, err)
225220
}
226221
return webhooks.Allow("")

0 commit comments

Comments
 (0)