Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Supporting exposing master loopback client #50

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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