Skip to content

Commit

Permalink
virtual: split named virtual workspaces from config constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sttts committed Mar 10, 2023
1 parent 6f965b9 commit cf254e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
17 changes: 9 additions & 8 deletions cmd/virtual-workspaces/command/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ func Run(ctx context.Context, o *options.Options) error {
}

// create apiserver
virtualWorkspaces, err := o.VirtualWorkspaces.NewVirtualWorkspaces(identityConfig, o.RootPathPrefix, wildcardKubeInformers, wildcardKcpInformers, cacheKcpInformers)
if err != nil {
return err
}
scheme := runtime.NewScheme()
metav1.AddToGroupVersion(scheme, schema.GroupVersion{Group: "", Version: "v1"})
codecs := serializer.NewCodecFactory(scheme)
Expand All @@ -163,20 +159,25 @@ func Run(ctx context.Context, o *options.Options) error {
if err := o.Authentication.ApplyTo(&recommendedConfig.Authentication, recommendedConfig.SecureServing, recommendedConfig.OpenAPIConfig); err != nil {
return err
}
if err := o.Authorization.ApplyTo(&recommendedConfig.Config, virtualWorkspaces); err != nil {
return err
}
if err := o.Audit.ApplyTo(&recommendedConfig.Config); err != nil {
return err
}
rootAPIServerConfig, err := virtualrootapiserver.NewConfig(recommendedConfig, []virtualrootapiserver.InformerStart{
wildcardKubeInformers.Start,
wildcardKcpInformers.Start,
cacheKcpInformers.Start,
}, virtualWorkspaces)
})
if err != nil {
return err
}
rootAPIServerConfig.Extra.VirtualWorkspaces, err = o.VirtualWorkspaces.NewVirtualWorkspaces(identityConfig, o.RootPathPrefix, wildcardKubeInformers, wildcardKcpInformers, cacheKcpInformers)
if err != nil {
return err
}

if err := o.Authorization.ApplyTo(&recommendedConfig.Config, rootAPIServerConfig.Extra.VirtualWorkspaces); err != nil {
return err
}

completedRootAPIServerConfig := rootAPIServerConfig.Complete()
rootAPIServer, err := virtualrootapiserver.NewServer(completedRootAPIServerConfig, genericapiserver.NewEmptyDelegate())
Expand Down
35 changes: 17 additions & 18 deletions pkg/server/virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ func (s *Server) installVirtualWorkspaces(
preHandlerChainMux mux,
) error {
logger := klog.FromContext(ctx)
// create virtual workspaces
virtualWorkspaces, err := s.Options.Virtual.VirtualWorkspaces.NewVirtualWorkspaces(
config,
virtualcommandoptions.DefaultRootPathPrefix,
s.KubeSharedInformerFactory,
s.KcpSharedInformerFactory,
s.CacheKcpSharedInformerFactory,
)
if err != nil {
return err
}

// create apiserver, with its own delegation chain
scheme := runtime.NewScheme()
Expand All @@ -75,18 +64,28 @@ func (s *Server) installVirtualWorkspaces(
recommendedConfig.LivezChecks = []healthz.HealthChecker{}
recommendedConfig.Authentication = auth

authorizationOptions := virtualoptions.NewAuthorization()
authorizationOptions.AlwaysAllowGroups = s.Options.Authorization.AlwaysAllowGroups
authorizationOptions.AlwaysAllowPaths = s.Options.Authorization.AlwaysAllowPaths
if err := authorizationOptions.ApplyTo(&recommendedConfig.Config, virtualWorkspaces); err != nil {
rootAPIServerConfig, err := virtualrootapiserver.NewConfig(recommendedConfig, nil)
if err != nil {
return err
}

rootAPIServerConfig, err := virtualrootapiserver.NewConfig(recommendedConfig, nil, virtualWorkspaces)
rootAPIServerConfig.Generic.ExternalAddress = externalAddress
rootAPIServerConfig.Extra.VirtualWorkspaces, err = s.Options.Virtual.VirtualWorkspaces.NewVirtualWorkspaces(
config,
virtualcommandoptions.DefaultRootPathPrefix,
s.KubeSharedInformerFactory,
s.KcpSharedInformerFactory,
s.CacheKcpSharedInformerFactory,
)
if err != nil {
return err
}
rootAPIServerConfig.Generic.ExternalAddress = externalAddress

authorizationOptions := virtualoptions.NewAuthorization()
authorizationOptions.AlwaysAllowGroups = s.Options.Authorization.AlwaysAllowGroups
authorizationOptions.AlwaysAllowPaths = s.Options.Authorization.AlwaysAllowPaths
if err := authorizationOptions.ApplyTo(&recommendedConfig.Config, rootAPIServerConfig.Extra.VirtualWorkspaces); err != nil {
return err
}

completedRootAPIServerConfig := rootAPIServerConfig.Complete()
completedRootAPIServerConfig.Generic.AuditBackend = s.MiniAggregator.GenericAPIServer.AuditBackend
Expand Down

0 comments on commit cf254e7

Please sign in to comment.