mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #109836 from tnqn/fix-apiservice-error
Fix OpenAPI loading error caused by empty APIService
This commit is contained in:
commit
e84f62e695
@ -61,11 +61,11 @@ func IsLocalAPIService(apiServiceName string) bool {
|
|||||||
return strings.HasPrefix(apiServiceName, localDelegateChainNamePrefix)
|
return strings.HasPrefix(apiServiceName, localDelegateChainNamePrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAPIServicesName returns the names of APIServices recorded in specAggregator.openAPISpecs.
|
// GetAPIServiceNames returns the names of APIServices recorded in specAggregator.openAPISpecs.
|
||||||
// We use this function to pass the names of local APIServices to the controller in this package,
|
// We use this function to pass the names of local APIServices to the controller in this package,
|
||||||
// so that the controller can periodically sync the OpenAPI spec from delegation API servers.
|
// so that the controller can periodically sync the OpenAPI spec from delegation API servers.
|
||||||
func (s *specAggregator) GetAPIServiceNames() []string {
|
func (s *specAggregator) GetAPIServiceNames() []string {
|
||||||
names := make([]string, len(s.openAPISpecs))
|
names := make([]string, 0, len(s.openAPISpecs))
|
||||||
for key := range s.openAPISpecs {
|
for key := range s.openAPISpecs {
|
||||||
names = append(names, key)
|
names = append(names, key)
|
||||||
}
|
}
|
||||||
|
@ -57,14 +57,14 @@ func IsLocalAPIService(apiServiceName string) bool {
|
|||||||
return strings.HasPrefix(apiServiceName, localDelegateChainNamePrefix)
|
return strings.HasPrefix(apiServiceName, localDelegateChainNamePrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAPIServicesName returns the names of APIServices recorded in apiServiceInfo.
|
// GetAPIServiceNames returns the names of APIServices recorded in apiServiceInfo.
|
||||||
// We use this function to pass the names of local APIServices to the controller in this package,
|
// We use this function to pass the names of local APIServices to the controller in this package,
|
||||||
// so that the controller can periodically sync the OpenAPI spec from delegation API servers.
|
// so that the controller can periodically sync the OpenAPI spec from delegation API servers.
|
||||||
func (s *specProxier) GetAPIServiceNames() []string {
|
func (s *specProxier) GetAPIServiceNames() []string {
|
||||||
s.rwMutex.RLock()
|
s.rwMutex.RLock()
|
||||||
defer s.rwMutex.RUnlock()
|
defer s.rwMutex.RUnlock()
|
||||||
|
|
||||||
names := make([]string, len(s.apiServiceInfo))
|
names := make([]string, 0, len(s.apiServiceInfo))
|
||||||
for key := range s.apiServiceInfo {
|
for key := range s.apiServiceInfo {
|
||||||
names = append(names, key)
|
names = append(names, key)
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||||
"k8s.io/apiserver/pkg/server/mux"
|
"k8s.io/apiserver/pkg/server/mux"
|
||||||
v1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
|
v1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
|
||||||
@ -117,6 +119,9 @@ func TestV2APIService(t *testing.T) {
|
|||||||
if bytes.Compare(gotSpecJSON, expectedV3Bytes) != 0 {
|
if bytes.Compare(gotSpecJSON, expectedV3Bytes) != 0 {
|
||||||
t.Errorf("Spec mismatch, expected %s, got %s", expectedV3Bytes, gotSpecJSON)
|
t.Errorf("Spec mismatch, expected %s, got %s", expectedV3Bytes, gotSpecJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apiServiceNames := specProxier.GetAPIServiceNames()
|
||||||
|
assert.ElementsMatch(t, []string{openAPIV2Converter, apiService.Name}, apiServiceNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestV3APIService(t *testing.T) {
|
func TestV3APIService(t *testing.T) {
|
||||||
@ -156,6 +161,9 @@ func TestV3APIService(t *testing.T) {
|
|||||||
if bytes.Compare(gotSpecJSON, specJSON) != 0 {
|
if bytes.Compare(gotSpecJSON, specJSON) != 0 {
|
||||||
t.Errorf("Spec mismatch, expected %s, got %s", specJSON, gotSpecJSON)
|
t.Errorf("Spec mismatch, expected %s, got %s", specJSON, gotSpecJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apiServiceNames := specProxier.GetAPIServiceNames()
|
||||||
|
assert.ElementsMatch(t, []string{openAPIV2Converter, apiService.Name}, apiServiceNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendReq(t *testing.T, handler http.Handler, path string) []byte {
|
func sendReq(t *testing.T, handler http.Handler, path string) []byte {
|
||||||
|
Loading…
Reference in New Issue
Block a user