Skip to content

Commit 749d333

Browse files
authored
Merge pull request #77 from sttts/sttts-namespace-deletion-klog-fatal
UPSTREAM: <carry>: do not klog.Fatal in namespace deletion
2 parents 64132a2 + 9f75712 commit 749d333

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ require (
5353
github.com/heketi/heketi v10.3.0+incompatible
5454
github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6 // indirect
5555
github.com/ishidawataru/sctp v0.0.0-20190723014705-7c296d48a2b5
56-
github.com/kcp-dev/logicalcluster v1.0.0
56+
github.com/kcp-dev/logicalcluster v1.1.0
5757
github.com/libopenstorage/openstorage v1.0.0
5858
github.com/lithammer/dedent v1.1.0
5959
github.com/lpabon/godbc v0.1.1 // indirect

pkg/controller/namespace/deletion/namespaced_resources_deleter.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (d *namespacedResourcesDeleter) Delete(clusterName logicalcluster.Name, nsN
154154
return nil
155155
}
156156

157-
func (d *namespacedResourcesDeleter) initOpCache(clusterName logicalcluster.Name) {
157+
func (d *namespacedResourcesDeleter) initOpCache(clusterName logicalcluster.Name) error {
158158
// pre-fill opCache with the discovery info
159159
//
160160
// TODO(sttts): get rid of opCache and http 405 logic around it and trust discovery info
@@ -163,7 +163,7 @@ func (d *namespacedResourcesDeleter) initOpCache(clusterName logicalcluster.Name
163163
utilruntime.HandleError(fmt.Errorf("unable to get all supported resources from server: %v", err))
164164
}
165165
if len(resources) == 0 {
166-
klog.Fatalf("Unable to get any supported resources from server: %v", err)
166+
return fmt.Errorf("unable to get any supported resources from server: %v", err)
167167
}
168168

169169
for _, rl := range resources {
@@ -188,6 +188,7 @@ func (d *namespacedResourcesDeleter) initOpCache(clusterName logicalcluster.Name
188188
}
189189
}
190190
}
191+
return nil
191192
}
192193

193194
// ResourcesRemainingError is used to inform the caller that all resources are not yet fully removed from the namespace.
@@ -236,14 +237,14 @@ func (o *operationNotSupportedCache) setNotSupported(key operationKey) {
236237
}
237238

238239
// isSupported returns true if the operation is supported
239-
func (d *namespacedResourcesDeleter) isSupported(clusterName logicalcluster.Name, key operationKey) bool {
240+
func (d *namespacedResourcesDeleter) isSupported(clusterName logicalcluster.Name, key operationKey) (bool, error) {
240241
// Quick read-only check to see if the cache already exists
241242
d.opCachesMutex.RLock()
242243
cache, exists := d.opCaches[clusterName]
243244
d.opCachesMutex.RUnlock()
244245

245246
if exists {
246-
return cache.isSupported(key)
247+
return cache.isSupported(key), nil
247248
}
248249

249250
// Doesn't exist - may need to create
@@ -254,7 +255,7 @@ func (d *namespacedResourcesDeleter) isSupported(clusterName logicalcluster.Name
254255
// when we checked with the read lock held, and now.
255256
cache, exists = d.opCaches[clusterName]
256257
if exists {
257-
return cache.isSupported(key)
258+
return cache.isSupported(key), nil
258259
}
259260

260261
// Definitely doesn't exist - need to create it.
@@ -263,9 +264,11 @@ func (d *namespacedResourcesDeleter) isSupported(clusterName logicalcluster.Name
263264
}
264265
d.opCaches[clusterName] = cache
265266

266-
d.initOpCache(clusterName)
267+
if err := d.initOpCache(clusterName); err != nil {
268+
return false, err
269+
}
267270

268-
return cache.isSupported(key)
271+
return cache.isSupported(key), nil
269272
}
270273

271274
// updateNamespaceFunc is a function that makes an update to a namespace
@@ -342,7 +345,9 @@ func (d *namespacedResourcesDeleter) deleteCollection(clusterName logicalcluster
342345
klog.V(5).Infof("namespace controller - deleteCollection - namespace: %s, gvr: %v", namespace, gvr)
343346

344347
key := operationKey{operation: operationDeleteCollection, gvr: gvr}
345-
if !d.isSupported(clusterName, key) {
348+
if supported, err := d.isSupported(clusterName, key); err != nil {
349+
return false, err
350+
} else if !supported {
346351
klog.V(5).Infof("namespace controller - deleteCollection ignored since not supported - namespace: %s, gvr: %v", namespace, gvr)
347352
return false, nil
348353
}
@@ -381,7 +386,9 @@ func (d *namespacedResourcesDeleter) listCollection(clusterName logicalcluster.N
381386
klog.V(5).Infof("namespace controller - listCollection - namespace: %s, gvr: %v", namespace, gvr)
382387

383388
key := operationKey{operation: operationList, gvr: gvr}
384-
if !d.isSupported(clusterName, key) {
389+
if supported, err := d.isSupported(clusterName, key); err != nil {
390+
return nil, false, err
391+
} else if !supported {
385392
klog.V(5).Infof("namespace controller - listCollection ignored since not supported - namespace: %s, gvr: %v", namespace, gvr)
386393
return nil, false, nil
387394
}

pkg/genericcontrolplane/clientutils/multiclusterconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ func (mcrt *multiClusterClientConfigRoundTripper) RoundTrip(req *http.Request) (
155155
if headerCluster.Empty() {
156156
return nil, fmt.Errorf("Cluster should not be empty for request '%s' on resource '%s' (%s)", requestInfo.Verb, requestInfo.Resource, requestInfo.Path)
157157
}
158-
req.Header.Add("X-Kubernetes-Cluster", headerCluster.String())
158+
req.Header.Add(logicalcluster.ClusterHeader, headerCluster.String())
159159
} else {
160160
if contextCluster != nil && !contextCluster.Name.Empty() {
161-
req.Header.Add("X-Kubernetes-Cluster", contextCluster.Name.String())
161+
req.Header.Add(logicalcluster.ClusterHeader, contextCluster.Name.String())
162162
}
163163
}
164164
if mcrt.disableSharding {

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/kcp_rest_options_getter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (t apiBindingAwareCRDRESTOptionsGetter) GetRESTOptions(resource schema.Grou
5151
// Bound CRDs must have the associated identity annotation
5252
apiIdentity := t.crd.Annotations["apis.kcp.dev/identity"]
5353
if apiIdentity == "" {
54-
return generic.RESTOptions{}, fmt.Errorf("missing 'apis.kcp.dev/identity' annotation")
54+
return generic.RESTOptions{}, fmt.Errorf("missing 'apis.kcp.dev/identity' annotation on CRD %s|%s for %s.%s", logicalcluster.From(t.crd), t.crd.Name, t.crd.Spec.Names.Plural, t.crd.Spec.Group)
5555
}
5656

5757
// Modify the ResourcePrefix so it results in e.g. /registry/mygroup.io/widgets/identity4567/...

0 commit comments

Comments
 (0)