From c2b3247ecf907d3f265724d8793c3b354acf5b1d Mon Sep 17 00:00:00 2001 From: Christoph Mewes Date: Thu, 1 Jun 2023 13:00:18 +0200 Subject: [PATCH] now that tmc/ is just an empty wrapper around pkg/server, get rid of it entirely --- cmd/kcp/kcp.go | 16 ++--- cmd/kcp/options/options.go | 8 +-- test/e2e/framework/kcp.go | 6 +- tmc/pkg/server/config.go | 77 ---------------------- tmc/pkg/server/options/options.go | 75 ---------------------- tmc/pkg/server/server.go | 102 ------------------------------ 6 files changed, 15 insertions(+), 269 deletions(-) delete mode 100644 tmc/pkg/server/config.go delete mode 100644 tmc/pkg/server/options/options.go delete mode 100644 tmc/pkg/server/server.go diff --git a/cmd/kcp/kcp.go b/cmd/kcp/kcp.go index b15b652aef3..0f57063d12b 100644 --- a/cmd/kcp/kcp.go +++ b/cmd/kcp/kcp.go @@ -42,7 +42,7 @@ import ( "github.com/kcp-dev/kcp/pkg/cmd/help" "github.com/kcp-dev/kcp/pkg/embeddedetcd" kcpfeatures "github.com/kcp-dev/kcp/pkg/features" - tmcserver "github.com/kcp-dev/kcp/tmc/pkg/server" + "github.com/kcp-dev/kcp/pkg/server" ) func main() { @@ -83,7 +83,7 @@ func main() { } serverOptions := options.NewOptions(rootDir) - serverOptions.Server.Core.GenericControlPlane.Logs.Verbosity = logsapiv1.VerbosityLevel(2) + serverOptions.Server.GenericControlPlane.Logs.Verbosity = logsapiv1.VerbosityLevel(2) startCmd := &cobra.Command{ Use: "start", @@ -105,7 +105,7 @@ func main() { }, RunE: func(cmd *cobra.Command, args []string) error { // run as early as possible to avoid races later when some components (e.g. grpc) start early using klog - if err := logsapiv1.ValidateAndApply(serverOptions.Server.Core.GenericControlPlane.Logs, kcpfeatures.DefaultFeatureGate); err != nil { + if err := logsapiv1.ValidateAndApply(serverOptions.Server.GenericControlPlane.Logs, kcpfeatures.DefaultFeatureGate); err != nil { return err } @@ -119,9 +119,9 @@ func main() { } logger := klog.FromContext(cmd.Context()) - logger.Info("running with selected batteries", "batteries", strings.Join(completed.Server.Core.Extra.BatteriesIncluded, ",")) + logger.Info("running with selected batteries", "batteries", strings.Join(completed.Server.Extra.BatteriesIncluded, ",")) - config, err := tmcserver.NewConfig(completed.Server) + config, err := server.NewConfig(completed.Server) if err != nil { return err } @@ -134,13 +134,13 @@ func main() { ctx := genericapiserver.SetupSignalContext() // the etcd server must be up before NewServer because storage decorators access it right away - if completedConfig.Core.EmbeddedEtcd.Config != nil { - if err := embeddedetcd.NewServer(completedConfig.Core.EmbeddedEtcd).Run(ctx); err != nil { + if completedConfig.EmbeddedEtcd.Config != nil { + if err := embeddedetcd.NewServer(completedConfig.EmbeddedEtcd).Run(ctx); err != nil { return err } } - s, err := tmcserver.NewServer(completedConfig) + s, err := server.NewServer(completedConfig) if err != nil { return err } diff --git a/cmd/kcp/options/options.go b/cmd/kcp/options/options.go index c839b292c46..71a26e21c3c 100644 --- a/cmd/kcp/options/options.go +++ b/cmd/kcp/options/options.go @@ -22,14 +22,14 @@ import ( cliflag "k8s.io/component-base/cli/flag" kcpcoreoptions "github.com/kcp-dev/kcp/cmd/kcp-core/options" - tmcserveroptions "github.com/kcp-dev/kcp/tmc/pkg/server/options" + serveroptions "github.com/kcp-dev/kcp/pkg/server/options" ) type Options struct { Output io.Writer Generic kcpcoreoptions.GenericOptions - Server tmcserveroptions.Options + Server serveroptions.Options Extra ExtraOptions } @@ -39,7 +39,7 @@ func NewOptions(rootDir string) *Options { opts := &Options{ Output: nil, - Server: *tmcserveroptions.NewOptions(rootDir), + Server: *serveroptions.NewOptions(rootDir), Generic: *kcpcoreoptions.NewGeneric(rootDir), Extra: ExtraOptions{}, } @@ -51,7 +51,7 @@ type completedOptions struct { Output io.Writer Generic kcpcoreoptions.GenericOptions - Server tmcserveroptions.CompletedOptions + Server serveroptions.CompletedOptions Extra ExtraOptions } diff --git a/test/e2e/framework/kcp.go b/test/e2e/framework/kcp.go index f1935b6142b..564a12837b0 100644 --- a/test/e2e/framework/kcp.go +++ b/test/e2e/framework/kcp.go @@ -61,10 +61,10 @@ import ( kcpoptions "github.com/kcp-dev/kcp/cmd/kcp/options" "github.com/kcp-dev/kcp/cmd/sharded-test-server/third_party/library-go/crypto" "github.com/kcp-dev/kcp/pkg/embeddedetcd" + "github.com/kcp-dev/kcp/pkg/server" corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" kcpclientset "github.com/kcp-dev/kcp/sdk/client/clientset/versioned/cluster" kubefixtures "github.com/kcp-dev/kcp/test/e2e/fixtures/kube" - "github.com/kcp-dev/kcp/tmc/pkg/server" ) // TestServerArgs returns the set of kcp args used to start a test @@ -664,8 +664,8 @@ func (c *kcpServer) Run(opts ...RunOption) error { } // the etcd server must be up before NewServer because storage decorators access it right away - if completedConfig.Core.EmbeddedEtcd.Config != nil { - if err := embeddedetcd.NewServer(completedConfig.Core.EmbeddedEtcd).Run(ctx); err != nil { + if completedConfig.EmbeddedEtcd.Config != nil { + if err := embeddedetcd.NewServer(completedConfig.EmbeddedEtcd).Run(ctx); err != nil { return err } } diff --git a/tmc/pkg/server/config.go b/tmc/pkg/server/config.go deleted file mode 100644 index 9746dc738a6..00000000000 --- a/tmc/pkg/server/config.go +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2022 The KCP 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 server - -import ( - _ "net/http/pprof" - - coreserver "github.com/kcp-dev/kcp/pkg/server" - "github.com/kcp-dev/kcp/tmc/pkg/server/options" -) - -type Config struct { - Options options.CompletedOptions - - Core *coreserver.Config - - ExtraConfig -} - -type ExtraConfig struct { -} - -type completedConfig struct { - Options options.CompletedOptions - Core coreserver.CompletedConfig - - ExtraConfig -} - -type CompletedConfig struct { - // Embed a private pointer that cannot be instantiated outside of this package. - *completedConfig -} - -// Complete fills in any fields not set that are required to have valid data. It's mutating the receiver. -func (c *Config) Complete() (CompletedConfig, error) { - core, err := c.Core.Complete() - if err != nil { - return CompletedConfig{}, err - } - - return CompletedConfig{&completedConfig{ - Options: c.Options, - Core: core, - - ExtraConfig: c.ExtraConfig, - }}, nil -} - -func NewConfig(opts options.CompletedOptions) (*Config, error) { - core, err := coreserver.NewConfig(opts.Core) - if err != nil { - return nil, err - } - - c := &Config{ - Options: opts, - Core: core, - ExtraConfig: ExtraConfig{}, - } - - return c, nil -} diff --git a/tmc/pkg/server/options/options.go b/tmc/pkg/server/options/options.go deleted file mode 100644 index 0943efb66ff..00000000000 --- a/tmc/pkg/server/options/options.go +++ /dev/null @@ -1,75 +0,0 @@ -/* -Copyright 2022 The KCP 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 options - -import ( - cliflag "k8s.io/component-base/cli/flag" - - kcpcoreoptions "github.com/kcp-dev/kcp/pkg/server/options" -) - -type Options struct { - Core kcpcoreoptions.Options - - Extra ExtraOptions -} - -type ExtraOptions struct { -} - -type completedOptions struct { - Core kcpcoreoptions.CompletedOptions - - Extra ExtraOptions -} - -type CompletedOptions struct { - *completedOptions -} - -// NewOptions creates a new Options with default parameters. -func NewOptions(rootDir string) *Options { - o := &Options{ - Core: *kcpcoreoptions.NewOptions(rootDir), - - Extra: ExtraOptions{}, - } - - return o -} - -func (o *Options) AddFlags(fss *cliflag.NamedFlagSets) { - o.Core.AddFlags(fss) -} - -func (o *CompletedOptions) Validate() []error { - return o.Core.Validate() -} - -func (o *Options) Complete(rootDir string) (*CompletedOptions, error) { - core, err := o.Core.Complete(rootDir) - if err != nil { - return nil, err - } - - return &CompletedOptions{ - completedOptions: &completedOptions{ - Core: *core, - Extra: o.Extra, - }, - }, nil -} diff --git a/tmc/pkg/server/server.go b/tmc/pkg/server/server.go deleted file mode 100644 index 91e262d348b..00000000000 --- a/tmc/pkg/server/server.go +++ /dev/null @@ -1,102 +0,0 @@ -/* -Copyright 2021 The KCP 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 server - -import ( - "context" - _ "net/http/pprof" - - "k8s.io/apimachinery/pkg/util/sets" - genericapiserver "k8s.io/apiserver/pkg/server" - "k8s.io/klog/v2" - - configrootcompute "github.com/kcp-dev/kcp/config/rootcompute" - coreserver "github.com/kcp-dev/kcp/pkg/server" - corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" -) - -type Server struct { - CompletedConfig - - Core *coreserver.Server -} - -func NewServer(c CompletedConfig) (*Server, error) { - core, err := coreserver.NewServer(c.Core) - if err != nil { - return nil, err - } - - s := &Server{ - CompletedConfig: c, - - Core: core, - } - - return s, nil -} - -func (s *Server) Run(ctx context.Context) error { - logger := klog.FromContext(ctx).WithValues("component", "kcp") - ctx = klog.NewContext(ctx, logger) - - enabled := sets.New(s.Options.Core.Controllers.IndividuallyEnabled...) - if len(enabled) > 0 { - logger.WithValues("controllers", enabled).Info("starting controllers individually") - } - - if s.Options.Core.Controllers.EnableAll || enabled.Has("cluster") { - // bootstrap root compute workspace - computeBoostrapHookName := "rootComputeBoostrap" - if err := s.Core.AddPostStartHook(computeBoostrapHookName, func(hookContext genericapiserver.PostStartHookContext) error { - logger := logger.WithValues("postStartHook", computeBoostrapHookName) - if s.Core.Options.Extra.ShardName == corev1alpha1.RootShard { - // the root ws is only present on the root shard - logger.Info("waiting to bootstrap root compute workspace until root phase1 is complete") - s.Core.WaitForPhase1Finished() - - logger.Info("starting bootstrapping root compute workspace") - if err := configrootcompute.Bootstrap(goContext(hookContext), - s.Core.BootstrapApiExtensionsClusterClient, - s.Core.BootstrapDynamicClusterClient, - sets.New(s.Core.Options.Extra.BatteriesIncluded...), - ); err != nil { - logger.Error(err, "failed to bootstrap root compute workspace") - return nil // don't klog.Fatal. This only happens when context is cancelled. - } - logger.Info("finished bootstrapping root compute workspace") - } - return nil - }); err != nil { - return err - } - } - - return s.Core.Run(ctx) -} - -// goContext turns the PostStartHookContext into a context.Context for use in routines that may or may not -// run inside of a post-start-hook. The k8s APIServer wrote the post-start-hook context code before contexts -// were part of the Go stdlib. -func goContext(parent genericapiserver.PostStartHookContext) context.Context { - ctx, cancel := context.WithCancel(context.Background()) - go func(done <-chan struct{}) { - <-done - cancel() - }(parent.StopCh) - return ctx -}