johnandersen777.bsky.social/socialweb-computer-console
console.socialweb.computer: kcp, kubectl and ssh compiled to wasm in a browser tab with a terminal; a kcp fork
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 (
"context"
"fmt"
"net"
"net/url"
"os"
"path/filepath"
"strings"
"time"
"github.com/spf13/pflag"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
genericapiserveroptions "k8s.io/apiserver/pkg/server/options"
cliflag "k8s.io/component-base/cli/flag"
controlplaneapiserver "k8s.io/kubernetes/pkg/controlplane/apiserver/options"
etcdoptions "github.com/kcp-dev/embeddedetcd/options"
corev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1"
kcpadmission "github.com/kcp-dev/kcp/pkg/admission"
kcpfeatures "github.com/kcp-dev/kcp/pkg/features"
"github.com/kcp-dev/kcp/pkg/server/options/batteries"
kcpserviceaccount "github.com/kcp-dev/kcp/pkg/server/serviceaccount"
)
type Options struct {
GenericControlPlane controlplaneapiserver.Options
EmbeddedEtcd etcdoptions.Options
Controllers Controllers
Authorization Authorization
AdminAuthentication AdminAuthentication
Virtual Virtual
HomeWorkspaces HomeWorkspaces
Cache Cache
Extra ExtraOptions
}
type ExtraOptions struct {
ProfilerAddress string
ShardKubeconfigFile string
RootShardKubeconfigFile string
ShardBaseURL string
ShardExternalURL string
ShardName string
ShardLabels map[string]string
ShardVirtualWorkspaceURL string
ShardClientCertFile string
ShardClientKeyFile string
ShardVirtualWorkspaceCAFile string
// MountProxyClientCertFile / MountProxyClientKeyFile point to a client certificate
// (signed by the front-proxy requestheader CA) that the local proxy presents when it
// forwards a request for a mounted workspace back to the front-proxy. This lets the
// front-proxy trust the forwarded identity headers instead of clearing them.
MountProxyClientCertFile string
MountProxyClientKeyFile string
ShardReplicaCount int
DiscoveryPollInterval time.Duration
ExperimentalBindFreePort bool
LogicalClusterTotalObjectLimit int64
LogicalClusterObjectCountScanInterval time.Duration
LogicalClusterAdminKubeconfig string
ExternalLogicalClusterAdminKubeconfig string
ConversionCELTransformationTimeout time.Duration
RootIdentitiesFile string
BatteriesIncluded []string
// SingleAPIServer declares that this server is the only apiserver
// serving its storage (an embedded or single-process kcp, e.g. one
// backed by memory:// storage). See APIExtensionsMasterCount.
SingleAPIServer bool
// DEVELOPMENT ONLY. AdditionalMappingsFile is the path to a file that contains additional mappings
// for the mini-front-proxy to use. The file should be in the format of the
// --miniproxy-mapping-file flag of the front-proxy. Do NOT expose this flag to users via main server options.
// It is overridden by the kcp start command.
AdditionalMappingsFile string
ServiceAccountCache *kcpserviceaccount.Cache
}
// APIExtensionsMasterCount returns the apiserver count kcp passes to the
// apiextensions server (its ExtraConfig.MasterCount, the upstream HA
// signal):
//
// - ShardReplicaCount > 1: the replica count. The CRD handler delays
// establishing new CRDs by 5 s and sleeps 2 s on creates within 2 s of
// a CRD becoming Established, so every replica has seen the CRD.
// - SingleAPIServer: 1, "known to be the only apiserver". The kcp
// apiextensions patch (scripts/prepare-kcp-patched-modules.sh) skips the
// 2 s create sleep only for exactly 1.
// - otherwise 0, "not declared": no establishing delay (as for 1) and the
// 2 s create sleep stays.
//
// Upstream only compares MasterCount with "> 1", so 0 and 1 behave the same
// in an unpatched build.
func (o ExtraOptions) APIExtensionsMasterCount() int {
switch {
case o.ShardReplicaCount > 1:
return o.ShardReplicaCount
case o.SingleAPIServer:
return 1
default:
return 0
}
}
type completedOptions struct {
GenericControlPlane controlplaneapiserver.CompletedOptions
EmbeddedEtcd etcdoptions.CompletedOptions
Controllers Controllers
Authorization Authorization
AdminAuthentication AdminAuthentication
Virtual Virtual
HomeWorkspaces HomeWorkspaces
Cache cacheCompleted
Extra ExtraOptions
}
type CompletedOptions struct {
*completedOptions
}
// NewOptions creates a new Options with default parameters.
func NewOptions(rootDir string) *Options {
saCache := kcpserviceaccount.NewCache()
o := &Options{
GenericControlPlane: *controlplaneapiserver.NewOptions(),
EmbeddedEtcd: *etcdoptions.NewOptions(rootDir),
Controllers: *NewControllers(),
Authorization: *NewAuthorization(),
AdminAuthentication: *NewAdminAuthentication(rootDir),
Virtual: *NewVirtual(),
HomeWorkspaces: *NewHomeWorkspaces(),
Cache: *NewCache(rootDir),
Extra: ExtraOptions{
ProfilerAddress: "",
ShardKubeconfigFile: "",
ShardBaseURL: "",
ShardExternalURL: "",
ShardName: "root",
ShardReplicaCount: 1,
DiscoveryPollInterval: 60 * time.Second,
ExperimentalBindFreePort: false,
ConversionCELTransformationTimeout: time.Second,
LogicalClusterTotalObjectLimit: 0,
LogicalClusterObjectCountScanInterval: 60 * time.Second,
BatteriesIncluded: sets.List[string](batteries.Defaults),
ServiceAccountCache: saCache,
},
}
// override all the stuff
o.GenericControlPlane.SecureServing.ServerCert.CertDirectory = rootDir
o.GenericControlPlane.Authentication.ServiceAccounts.Issuers = []string{"https://kcp.default.svc"}
o.GenericControlPlane.Authentication.ServiceAccounts.OptionalTokenGetter = saCache.TokenGetter
o.GenericControlPlane.Etcd.StorageConfig.Transport.ServerList = []string{"embedded"}
if name := os.Getenv("KCP_MEMORY_STORAGE"); name != "" {
if name == "true" || name == "1" {
name = "main"
}
// Selects the in-memory storage.Interface backend added by the
// js/wasm build overlay (<repo>/contrib/wasm/overlay/apiserver).
o.GenericControlPlane.Etcd.StorageConfig.Transport.ServerList = []string{"memory://" + name}
}
o.GenericControlPlane.Authorization = nil // we have our own
// override set of admission plugins
kcpadmission.RegisterAllKcpAdmissionPlugins(o.GenericControlPlane.Admission.GenericAdmission.Plugins)
o.GenericControlPlane.Admission.GenericAdmission.DisablePlugins = sets.List[string](kcpadmission.DefaultOffAdmissionPlugins())
o.GenericControlPlane.Admission.GenericAdmission.RecommendedPluginOrder = kcpadmission.AllOrderedPlugins
// turn on the watch cache
o.GenericControlPlane.Etcd.EnableWatchCache = true
o.GenericControlPlane.SystemNamespaces = append(o.GenericControlPlane.SystemNamespaces, metav1.NamespaceSystem)
return o
}
func (o *Options) AddFlags(fss *cliflag.NamedFlagSets) {
raw := &cliflag.NamedFlagSets{}
o.GenericControlPlane.AddFlags(raw)
for name, fs := range raw.FlagSets {
fss.FlagSet(name).AddFlagSet(filter(name, fs, allowedFlags))
}
etcdServers := fss.FlagSet("etcd").Lookup("etcd-servers")
etcdServers.Usage += " By default an embedded etcd server is started."
o.EmbeddedEtcd.AddFlags(fss.FlagSet("Embedded etcd"))
o.Controllers.AddFlags(fss.FlagSet("kcp Controllers"))
o.Authorization.AddFlags(fss.FlagSet("kcp Authorization"))
o.AdminAuthentication.AddFlags(fss.FlagSet("kcp Authentication"))
o.Virtual.AddFlags(fss.FlagSet("kcp Virtual Workspaces"))
o.HomeWorkspaces.AddFlags(fss.FlagSet("kcp Home Workspaces"))
o.Cache.AddFlags(fss.FlagSet("kcp Cache Server"))
fs := fss.FlagSet("kcp")
fs.StringVar(&o.Extra.ProfilerAddress, "profiler-address", o.Extra.ProfilerAddress, "[Address]:port to bind the profiler to")
fs.StringVar(&o.Extra.ShardKubeconfigFile, "shard-kubeconfig-file", o.Extra.ShardKubeconfigFile, "Kubeconfig holding admin(!) credentials to peer kcp shards.")
fs.StringVar(&o.Extra.RootShardKubeconfigFile, "root-shard-kubeconfig-file", o.Extra.RootShardKubeconfigFile, "Kubeconfig holding admin(!) credentials to the root kcp shard.")
fs.StringVar(&o.Extra.ShardBaseURL, "shard-base-url", o.Extra.ShardBaseURL, "Base URL to this kcp shard. Defaults to external address.")
fs.StringVar(&o.Extra.ShardExternalURL, "shard-external-url", o.Extra.ShardExternalURL, "URL used by outside clients to talk to this kcp shard. Defaults to external address.")
fs.StringVar(&o.Extra.ShardName, "shard-name", o.Extra.ShardName, "A name of this kcp shard. Defaults to the \"root\" name.")
// https://github.com/kubernetes/kubernetes/blob/f28b4c9efbca5c5c0af716d9f2d5702667ee8a45/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go#L491-L495
// The --shard-replica-count is passed along and lands as
// masterCount in upstream which then causes a 5s delay on startup.
fs.IntVar(&o.Extra.ShardReplicaCount, "shard-replica-count", o.Extra.ShardReplicaCount, "Number of kcp server replicas serving this shard. Values greater than 1 delay CRD establishment by 5 seconds so all replicas can warm their caches before the CRD is served.")
fs.BoolVar(&o.Extra.SingleAPIServer, "single-apiserver", o.Extra.SingleAPIServer, "Declare that this kcp server is the only apiserver serving its storage (no other replica shares it). Builds with the kcp apiextensions patch (scripts/prepare-kcp-patched-modules.sh) then skip the 2 second HA wait on creates right after a CRD becomes Established. Cannot be combined with --shard-replica-count greater than 1.")
fs.StringToStringVar(&o.Extra.ShardLabels, "shard-labels", o.Extra.ShardLabels, "Additional labels to set on this shard's Shard object, e.g. region=us-east-1. The Shard object is owned by the shard; labels are part of its configuration.")
fs.StringVar(&o.Extra.ShardVirtualWorkspaceCAFile, "shard-virtual-workspace-ca-file", o.Extra.ShardVirtualWorkspaceCAFile, "Path to a CA certificate file that is valid for the virtual workspace server.")
fs.StringVar(&o.Extra.ShardVirtualWorkspaceURL, "shard-virtual-workspace-url", o.Extra.ShardVirtualWorkspaceURL, "An external URL address of a virtual workspace server associated with this shard. Defaults to shard's base address.")
fs.StringVar(&o.Extra.ShardClientCertFile, "shard-client-cert-file", o.Extra.ShardClientCertFile, "Path to a client certificate file the shard uses to communicate with other system components.")
fs.StringVar(&o.Extra.ShardClientKeyFile, "shard-client-key-file", o.Extra.ShardClientKeyFile, "Path to a client certificate key file the shard uses to communicate with other system components.")
fs.StringVar(&o.Extra.MountProxyClientCertFile, "mount-proxy-client-cert-file", o.Extra.MountProxyClientCertFile, "Path to a client certificate file (signed by the front-proxy requestheader CA) the local proxy presents when forwarding a request for a mounted workspace back to the front-proxy.")
fs.StringVar(&o.Extra.MountProxyClientKeyFile, "mount-proxy-client-key-file", o.Extra.MountProxyClientKeyFile, "Path to the key file for --mount-proxy-client-cert-file.")
fs.StringVar(&o.Extra.LogicalClusterAdminKubeconfig, "logical-cluster-admin-kubeconfig", o.Extra.LogicalClusterAdminKubeconfig, "Kubeconfig holding system:kcp:logical-cluster-admin credentials for connecting to other shards. Defaults to the loopback client")
fs.StringVar(&o.Extra.ExternalLogicalClusterAdminKubeconfig, "external-logical-cluster-admin-kubeconfig", o.Extra.ExternalLogicalClusterAdminKubeconfig, "Kubeconfig holding system:kcp:external-logical-cluster-admin credentials for connecting to the external address (e.g. the front-proxy). Defaults to the loopback client")
fs.StringVar(&o.Extra.RootIdentitiesFile, "root-identities-file", "", "Path to a YAML file used to bootstrap APIExport identities inside the root workspace. The YAML file must be structured as {\"identities\": [ {\"export\": \"<APIExport name>\", \"identity\": \"<APIExport identity>\"}, ... ]}. If a secret with matching APIExport name already exists inside kcp-system namespace, it will be left unchanged. Defaults to empty, i.e. no identities are bootstrapped.")
fs.BoolVar(&o.Extra.ExperimentalBindFreePort, "experimental-bind-free-port", o.Extra.ExperimentalBindFreePort, "Bind to a free port. --secure-port must be 0. Use the admin.kubeconfig to extract the chosen port.")
fs.MarkHidden("experimental-bind-free-port") //nolint:errcheck
fs.String("external-hostname", "", "DEPRECATED: This flag is deprecated and will be removed in a future release.")
fs.MarkHidden("external-hostname") //nolint:errcheck
fs.DurationVar(&o.Extra.ConversionCELTransformationTimeout, "conversion-cel-transformation-timeout", o.Extra.ConversionCELTransformationTimeout, "Maximum amount of time that CEL transformations may take per object conversion.")
fs.Int64Var(&o.Extra.LogicalClusterTotalObjectLimit, "logical-cluster-total-object-limit", o.Extra.LogicalClusterTotalObjectLimit, "Maximum total number of objects allowed in a logical cluster on this shard. 0 disables the default limit. The "+corev1alpha1.LogicalClusterMaxTotalObjectsAnnotationKey+" annotation on a LogicalCluster overrides this value for that logical cluster.")
fs.DurationVar(&o.Extra.LogicalClusterObjectCountScanInterval, "logical-cluster-object-count-scan-interval", o.Extra.LogicalClusterObjectCountScanInterval, "Interval at which etcd is scanned to count objects per logical cluster for total object count limit enforcement.")
fs.StringSliceVar(&o.Extra.BatteriesIncluded, "batteries-included", o.Extra.BatteriesIncluded, fmt.Sprintf(
`A list of batteries included (= default objects that might be unwanted in production, but are very helpful in trying out kcp or for development). These are the possible values: %s.
- workspace-types: creates "organization" and "team" WorkspaceTypes in the root workspace.
- admin: creates an admin.kubeconfig in the path passed to --kubeconfig-path.
- user: creates an additional non-admin user and context named "user" in the admin.kubeconfig. Requires "admin" battery to be enabled.
- metrics-viewer: creates a service account named "metrics" and a corresponding ClusterRoleBinding (also binds a "metrics-viewer" user) in the root namespace that can view metrics.
Prefixing with - or + means to remove from the default set or add to the default set.`,
strings.Join(sets.List[string](batteries.All), ","),
))
// add flags that are filtered out from upstream, but overridden here with our own version
fs.Var(kcpfeatures.NewFlagValue(), "feature-gates", ""+
"A set of key=value pairs that describe feature gates for alpha/experimental features. "+
"Options are:\n"+strings.Join(kcpfeatures.KnownFeatures(), "\n")) // hide kube-only gates
}
func (o *CompletedOptions) Validate() []error {
var errs []error
if o.Extra.ExperimentalBindFreePort {
if o.GenericControlPlane.SecureServing.BindPort != 0 {
errs = append(errs, fmt.Errorf("--secure-port=0 required if --experimental-bind-free-port is set"))
}
}
errs = append(errs, o.GenericControlPlane.Validate()...)
errs = append(errs, o.Controllers.Validate()...)
errs = append(errs, o.EmbeddedEtcd.Validate()...)
errs = append(errs, o.Authorization.Validate()...)
errs = append(errs, o.AdminAuthentication.Validate()...)
errs = append(errs, o.Virtual.Validate()...)
errs = append(errs, o.HomeWorkspaces.Validate()...)
errs = append(errs, o.Cache.Validate()...)
if o.Extra.ShardName != corev1alpha1.RootShard && len(o.Cache.Client.KubeconfigFile) == 0 {
errs = append(errs, fmt.Errorf("--cache-kubeconfig is required for non-root shards"))
}
if o.Extra.ShardReplicaCount < 1 {
errs = append(errs, fmt.Errorf("--shard-replica-count must be at least 1"))
}
if o.Extra.SingleAPIServer && o.Extra.ShardReplicaCount > 1 {
errs = append(errs, fmt.Errorf("--single-apiserver cannot be combined with --shard-replica-count=%d", o.Extra.ShardReplicaCount))
}
differential := false
for i, b := range o.Extra.BatteriesIncluded {
if strings.HasPrefix(b, "+") || strings.HasPrefix(b, "-") {
if !differential && i > 0 {
errs = append(errs, fmt.Errorf("--batteries-included must all be prefixed with + or - or none"))
break
}
differential = true
b = b[1:]
} else if differential {
errs = append(errs, fmt.Errorf("--batteries-included must all be prefixed with + or - or none"))
break
}
if !batteries.All.Has(b) {
errs = append(errs, fmt.Errorf("unknown battery: %s", b))
}
}
batterySet := sets.New[string](o.Extra.BatteriesIncluded...)
if batterySet.Has(batteries.User) && !batterySet.Has(batteries.Admin) {
errs = append(errs, fmt.Errorf("battery %s enabled which requires %s as well", batteries.User, batteries.Admin))
}
if o.Extra.LogicalClusterAdminKubeconfig != "" && o.Extra.ShardExternalURL == "" {
errs = append(errs, fmt.Errorf("--shard-external-url is required if --logical-cluster-admin-kubeconfig is set"))
}
return errs
}
func (o *Options) Complete(ctx context.Context, rootDir string) (*CompletedOptions, error) {
if servers := o.GenericControlPlane.Etcd.StorageConfig.Transport.ServerList; len(servers) == 1 && servers[0] == "embedded" {
o.EmbeddedEtcd.Enabled = true
}
if err := o.Authorization.Complete(); err != nil {
return nil, err
}
var err error
if !filepath.IsAbs(o.EmbeddedEtcd.Directory) {
o.EmbeddedEtcd.Directory, err = filepath.Abs(o.EmbeddedEtcd.Directory)
if err != nil {
return nil, err
}
}
if !filepath.IsAbs(o.GenericControlPlane.SecureServing.ServerCert.CertDirectory) {
o.GenericControlPlane.SecureServing.ServerCert.CertDirectory, err = filepath.Abs(o.GenericControlPlane.SecureServing.ServerCert.CertDirectory)
if err != nil {
return nil, err
}
}
if !filepath.IsAbs(o.AdminAuthentication.ShardAdminTokenHashFilePath) {
o.AdminAuthentication.ShardAdminTokenHashFilePath, err = filepath.Abs(o.AdminAuthentication.ShardAdminTokenHashFilePath)
if err != nil {
return nil, err
}
}
if !filepath.IsAbs(o.AdminAuthentication.KubeConfigPath) {
o.AdminAuthentication.KubeConfigPath, err = filepath.Abs(o.AdminAuthentication.KubeConfigPath)
if err != nil {
return nil, err
}
}
if len(o.Extra.LogicalClusterAdminKubeconfig) > 0 && !filepath.IsAbs(o.Extra.LogicalClusterAdminKubeconfig) {
o.Extra.LogicalClusterAdminKubeconfig, err = filepath.Abs(o.Extra.LogicalClusterAdminKubeconfig)
if err != nil {
return nil, err
}
}
if len(o.Extra.ExternalLogicalClusterAdminKubeconfig) > 0 && !filepath.IsAbs(o.Extra.ExternalLogicalClusterAdminKubeconfig) {
o.Extra.ExternalLogicalClusterAdminKubeconfig, err = filepath.Abs(o.Extra.ExternalLogicalClusterAdminKubeconfig)
if err != nil {
return nil, err
}
}
// ExternalAddress is the address used e.g. when generating
// kubeconfigs. This is the address clients should use to talk to
// this server, i.e. the shard url.
switch {
case o.Extra.ShardBaseURL != "":
// If the shard base URL is set, use it as the external host.
parsedShardBaseURL, err := url.Parse(o.Extra.ShardBaseURL)
if err != nil {
return nil, fmt.Errorf("invalid --shard-base-url: %w", err)
}
o.GenericControlPlane.GenericServerRunOptions.ExternalHost = parsedShardBaseURL.Host
case !o.GenericControlPlane.SecureServing.BindAddress.IsUnspecified():
// If the shard base URL is not set but the bind-address was
// specified it is defaulted to the bind address. This is needed
// for the case where the server binds on a specific IP, e.g.
// when running kcp locally.
o.GenericControlPlane.GenericServerRunOptions.ExternalHost = o.GenericControlPlane.SecureServing.BindAddress.String()
}
if o.Extra.ExperimentalBindFreePort {
listener, _, err := genericapiserveroptions.CreateListener("tcp", fmt.Sprintf("%s:0", o.GenericControlPlane.SecureServing.BindAddress), net.ListenConfig{})
if err != nil {
return nil, err
}
o.GenericControlPlane.SecureServing.Listener = listener
}
if err := o.Controllers.Complete(rootDir); err != nil {
return nil, err
}
if o.Controllers.SAController.ServiceAccountKeyFile != "" && !filepath.IsAbs(o.Controllers.SAController.ServiceAccountKeyFile) {
o.Controllers.SAController.ServiceAccountKeyFile, err = filepath.Abs(o.Controllers.SAController.ServiceAccountKeyFile)
if err != nil {
return nil, err
}
}
if len(o.GenericControlPlane.Authentication.ServiceAccounts.KeyFiles) == 0 {
o.GenericControlPlane.Authentication.ServiceAccounts.KeyFiles = []string{o.Controllers.SAController.ServiceAccountKeyFile}
}
if o.GenericControlPlane.ServiceAccountSigningKeyFile == "" {
o.GenericControlPlane.ServiceAccountSigningKeyFile = o.Controllers.SAController.ServiceAccountKeyFile
}
// o.GenericControlPlane.Complete creates self-signed certificates
// with the advertise address by default. This can cause spurious
// errors if the server binds on multiple interfaces.
possibleIPs := []net.IP{
o.GenericControlPlane.GenericServerRunOptions.AdvertiseAddress,
o.GenericControlPlane.SecureServing.BindAddress,
o.GenericControlPlane.SecureServing.ExternalAddress,
}
if o.GenericControlPlane.SecureServing.Listener != nil {
host, _, err := net.SplitHostPort(o.GenericControlPlane.SecureServing.Listener.Addr().String())
if err != nil {
return nil, err
}
possibleIPs = append(possibleIPs, net.ParseIP(host))
}
alternateIPs := []net.IP{}
alternateDNS := []string{}
for _, ip := range possibleIPs {
if ip == nil || ip.IsUnspecified() {
continue
}
alternateIPs = append(alternateIPs, ip)
alternateDNS = append(alternateDNS, ip.String())
}
completedGenericOptions, err := o.GenericControlPlane.Complete(ctx, alternateDNS, alternateIPs)
if err != nil {
return nil, err
}
if o.Extra.ExperimentalBindFreePort {
// Override Required here. It influences o.GenericControlPlane.Validate to pass without a set port,
// but other than that only has cosmetic effects e.g. on the flag description. Hence, we do it here
// in Complete and not in NewOptions.
o.GenericControlPlane.SecureServing.Required = false
}
differential := false
for _, b := range o.Extra.BatteriesIncluded {
if strings.HasPrefix(b, "+") || strings.HasPrefix(b, "-") {
differential = true
break
}
}
if differential {
bats := sets.New[string](sets.List[string](batteries.Defaults)...)
for _, b := range o.Extra.BatteriesIncluded {
if strings.HasPrefix(b, "+") {
bats.Insert(b[1:])
} else if strings.HasPrefix(b, "-") {
bats.Delete(b[1:])
}
}
o.Extra.BatteriesIncluded = sets.List[string](bats)
}
completedEmbeddedEtcd := o.EmbeddedEtcd.Complete(o.GenericControlPlane.Etcd)
cacheServerEtcdOptions := *o.GenericControlPlane.Etcd
o.Cache.Server.Etcd = &cacheServerEtcdOptions
// TODO: enable the watch cache, it was disabled because
// - we need to pass a shard name so that the watch cache can calculate the key
// we already do that for cluster names (stored in the obj)
// - we need to modify wildcardClusterNameRegex and crdWildcardPartialMetadataClusterNameRegex
o.Cache.Server.Etcd.EnableWatchCache = false
o.Cache.Server.SecureServing = completedGenericOptions.SecureServing
// Pass the client ca configured on the shard to the embedded cache server.
// The cache server will still only allow access to identities with the system:master group.
o.Cache.Server.Authentication.ClientCAFile = o.GenericControlPlane.Authentication.ClientCert.ClientCA
cacheCompletedOptions, err := o.Cache.Complete()
if err != nil {
return nil, err
}
return &CompletedOptions{
completedOptions: &completedOptions{
GenericControlPlane: completedGenericOptions,
EmbeddedEtcd: completedEmbeddedEtcd,
Controllers: o.Controllers,
Authorization: o.Authorization,
AdminAuthentication: o.AdminAuthentication,
Virtual: o.Virtual,
HomeWorkspaces: o.HomeWorkspaces,
Cache: cacheCompletedOptions,
Extra: o.Extra,
},
}, nil
}
func filter(name string, fs *pflag.FlagSet, allowed sets.Set[string]) *pflag.FlagSet {
filtered := pflag.NewFlagSet(name, pflag.ContinueOnError)
fs.VisitAll(func(f *pflag.Flag) {
if allowed.Has(f.Name) {
filtered.AddFlag(f)
}
})
return filtered
}