7
7
"github.com/spf13/pflag"
8
8
"k8s.io/apimachinery/pkg/runtime/schema"
9
9
"k8s.io/apimachinery/pkg/util/sets"
10
+ utilfeature "k8s.io/apiserver/pkg/util/feature"
10
11
11
12
proxyrest "github.com/clusterpedia-io/clusterpedia/pkg/kubeapiserver/resourcerest/proxy"
12
13
)
@@ -18,6 +19,9 @@ type Options struct {
18
19
19
20
AllowedProxySubresources []string
20
21
ExtraProxyRequestHeaderPrefixes []string
22
+
23
+ EnableProxyPathForForwardRequest bool
24
+ AllowForwardUnsyncResourceRequest bool
21
25
}
22
26
23
27
func NewOptions () * Options {
@@ -40,12 +44,20 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
40
44
// If you have a better solution, please submit an issue!
41
45
fs .StringSliceVar (& o .AllowedProxySubresources , "allowed-proxy-subresources" , o .AllowedProxySubresources , "" +
42
46
"List of subresources that support proxying requests to the specified cluster, formatted as '[resource/subresource],[subresource],...'. " +
43
- fmt .Sprintf ("Supported proxy subresources include %q" , strings .Join (resources , "," )),
47
+ fmt .Sprintf ("Supported proxy subresources include %q. " , strings .Join (resources , "," )),
44
48
)
45
49
46
50
fs .BoolVar (& o .AllowPediaClusterConfigForProxyRequest , "allow-pediacluster-config-for-proxy-request" , o .AllowPediaClusterConfigForProxyRequest , "" +
47
51
"Allow proxy requests to use the cluster configuration from PediaCluster when authentication information cannot be got from the header." ,
48
52
)
53
+
54
+ fs .BoolVar (& o .EnableProxyPathForForwardRequest , "enable-proxy-path-for-forward-request" , o .EnableProxyPathForForwardRequest , "" +
55
+ "Add a '/proxy' path in the API to proxy any request." ,
56
+ )
57
+ fs .BoolVar (& o .AllowForwardUnsyncResourceRequest , "allow-forward-unsync-resource-request" , o .AllowForwardUnsyncResourceRequest , "" +
58
+ "Allow forwarding requests for unsynchronized resource types." +
59
+ "By default, only requests for resource types configured in PediaCluster can be forwarded." ,
60
+ )
49
61
}
50
62
51
63
var supportedProxyCoreSubresources = map [string ][]string {
@@ -55,6 +67,11 @@ var supportedProxyCoreSubresources = map[string][]string{
55
67
}
56
68
57
69
func (o * Options ) Config () (* ExtraConfig , error ) {
70
+ if ! utilfeature .DefaultFeatureGate .Enabled (AllowProxyRequestToClusters ) && (len (o .AllowedProxySubresources ) != 0 ||
71
+ o .EnableProxyPathForForwardRequest || o .AllowForwardUnsyncResourceRequest ) {
72
+ return nil , fmt .Errorf ("please enable feature gate %s to allow apiserver to handle the proxy and forward requests" , AllowProxyRequestToClusters )
73
+ }
74
+
58
75
subresources := make (map [schema.GroupResource ]sets.Set [string ])
59
76
60
77
for _ , subresource := range o .AllowedProxySubresources {
@@ -89,7 +106,9 @@ func (o *Options) Config() (*ExtraConfig, error) {
89
106
}
90
107
}
91
108
return & ExtraConfig {
92
- AllowPediaClusterConfigReuse : o .AllowPediaClusterConfigForProxyRequest ,
93
- AllowedProxySubresources : subresources ,
109
+ AllowPediaClusterConfigReuse : o .AllowPediaClusterConfigForProxyRequest ,
110
+ AllowedProxySubresources : subresources ,
111
+ EnableProxyPathForForwardRequest : o .EnableProxyPathForForwardRequest ,
112
+ AllowForwardUnsyncResourceRequest : o .AllowForwardUnsyncResourceRequest ,
94
113
}, nil
95
114
}
0 commit comments