Skip to content

Commit 144cb72

Browse files
Merge pull request #1879 from bertinatto/fix-manifestclient-namespaces-discovery
manifestclient: fix discovery of namespaces
2 parents ec00d85 + 283adfa commit 144cb72

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pkg/manifestclient/group_resource_discovery.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"errors"
55
"fmt"
66
"io/fs"
7-
"k8s.io/apimachinery/pkg/util/json"
87
"path/filepath"
9-
"sigs.k8s.io/yaml"
108
"strings"
119

10+
"k8s.io/apimachinery/pkg/util/json"
11+
"sigs.k8s.io/yaml"
12+
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
apirequest "k8s.io/apiserver/pkg/endpoints/request"
1415
)
@@ -114,6 +115,20 @@ func (mrt *manifestRoundTripper) getLegacyGroupResourceDiscovery(requestInfo *ap
114115
for resourceName, apiResource := range apiResourcesForNamespace {
115116
apiResources[resourceName] = apiResource
116117
}
118+
119+
// Namespaces are special: each namespace is stored in its own file within the namespace directory
120+
namespacePath := filepath.Join("namespaces", namespaceDirEntry.Name(), namespaceDirEntry.Name()+".yaml")
121+
if namespaceObj, err := readIndividualFile(mrt.sourceFS, namespacePath); err == nil {
122+
// It's currently not guaranteed that the file is always present
123+
apiResources["namespaces"] = metav1.APIResource{
124+
Name: "namespaces",
125+
Kind: namespaceObj.GetKind(),
126+
Group: namespaceObj.GroupVersionKind().Group,
127+
Version: namespaceObj.GroupVersionKind().Version,
128+
Namespaced: false,
129+
Verbs: []string{"get", "list", "watch"},
130+
}
131+
}
117132
}
118133

119134
for _, apiResource := range apiResources {

0 commit comments

Comments
 (0)