Skip to content

Commit

Permalink
Merge pull request #50 from yue9944882/feat/suppot-exposing-master-lo…
Browse files Browse the repository at this point in the history
…opback-config

Feat: Supporting exposing master loopback client
  • Loading branch information
k8s-ci-robot committed Sep 6, 2021
2 parents 16bafbc + bff8496 commit 8433bb8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ func NewREST(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) (*reg
if err := store.CompleteWithOptions(options); err != nil {
return nil, err
}
return &registry.REST{store}, nil
return &registry.REST{Store: store}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ func NewREST(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) (*reg
if err := store.CompleteWithOptions(options); err != nil {
return nil, err
}
return &registry.REST{store}, nil
return &registry.REST{Store: store}, nil
}
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
}
2 changes: 1 addition & 1 deletion tools/apiserver-runtime-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func main() {
var defaultModule string
cwd, _ := os.Getwd()
if modRoot := findModuleRoot(cwd); modRoot != "" {
if b, err := ioutil.ReadFile(path.Join(modRoot, "go.mod")); err == nil {
if b, err := ioutil.ReadFile(filepath.Clean(path.Join(modRoot, "go.mod"))); err == nil {
defaultModule = modfile.ModulePath(b)
}
}
Expand Down

0 comments on commit 8433bb8

Please sign in to comment.