Skip to content

Commit

Permalink
supporting exposing master loopback client
Browse files Browse the repository at this point in the history
  • Loading branch information
yue9944882 committed Sep 6, 2021
1 parent 16bafbc commit 4ae0036
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/builder/builder_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package builder

import (
"k8s.io/apimachinery/pkg/runtime"
genericapiserver "k8s.io/apiserver/pkg/server"
openapicommon "k8s.io/kube-openapi/pkg/common"
"sigs.k8s.io/apiserver-runtime/internal/sample-apiserver/pkg/cmd/server"
"sigs.k8s.io/apiserver-runtime/pkg/util/loopback"
Expand Down Expand Up @@ -56,6 +57,15 @@ func (a *Server) ExposeLoopbackAuthorizer() *Server {
})
}

// ExposeLoopbackMasterClientConfig exposes loopback client config for accessing the
// configured master cluster's kube-apiserver as an external singleton.
func (a *Server) ExposeLoopbackMasterClientConfig() *Server {
return a.WithConfigFns(func(config *genericapiserver.RecommendedConfig) *genericapiserver.RecommendedConfig {
loopback.SetLoopbackMasterClientConfig(config.ClientConfig)
return config
})
}

// WithoutEtcd removes etcd related settings from apiserver.
func (a *Server) WithoutEtcd() *Server {
return a.WithOptionsFns(func(o *ServerOptions) *ServerOptions {
Expand Down
39 changes: 39 additions & 0 deletions pkg/util/loopback/master.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package loopback

import (
"sync"

"k8s.io/client-go/rest"
)

var setLoopbackMasterClientOnce sync.Once
var loopbackMasterClientConfig *rest.Config

// SetLoopbackMasterClientConfig provides loopback client config for one time
func SetLoopbackMasterClientConfig(c *rest.Config) {
setLoopbackMasterClientOnce.Do(func() {
loopbackMasterClientConfig = c
})
}

// GetLoopbackMasterClientConfig gets loopback client config for the
// master kube-apiserver.
func GetLoopbackMasterClientConfig() *rest.Config {
return loopbackMasterClientConfig
}

0 comments on commit 4ae0036

Please sign in to comment.