Skip to content

Commit

Permalink
[kwokctl] Generically enable/disable a component
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Sep 24, 2024
1 parent 0e9df27 commit 491ed77
Show file tree
Hide file tree
Showing 20 changed files with 918 additions and 681 deletions.
13 changes: 13 additions & 0 deletions pkg/apis/config/v1alpha1/kwokctl_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,31 @@ type KwokctlConfigurationOptions struct {
// is the default value for flag --kube-scheduler-config and env KWOK_KUBE_SCHEDULER_CONFIG
KubeSchedulerConfig string `json:"kubeSchedulerConfig,omitempty"`

// Components is the configuration for components.
// +default=["etcd", "kube-apiserver", "kube-controller-manager", "kube-scheduler", "kwok-controller"]
Components []string `json:"components,omitempty"`

// Disable is the configuration for disables components.
Disable []string `json:"disable,omitempty"`

// Enable is the configuration for enables components.
Enable []string `json:"enable,omitempty"`

// DisableKubeScheduler is the flag to disable kube-scheduler.
// is the default value for flag --disable-kube-scheduler and env KWOK_DISABLE_KUBE_SCHEDULER
// +default=false
// Deprecated: Use Disable instead
DisableKubeScheduler *bool `json:"disableKubeScheduler,omitempty"`

// DisableKubeControllerManager is the flag to disable kube-controller-manager.
// is the default value for flag --disable-kube-controller-manager and env KWOK_DISABLE_KUBE_CONTROLLER_MANAGER
// +default=false
// Deprecated: Use Disable instead
DisableKubeControllerManager *bool `json:"disableKubeControllerManager,omitempty"`

// EnableMetricsServer is the flag to enable metrics-server.
// +default=false
// Deprecated: Use Enable instead
EnableMetricsServer *bool `json:"enableMetricsServer,omitempty"`

// KubeImagePrefix is the prefix of the kubernetes image.
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/config/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/apis/config/v1alpha1/zz_generated.defaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pkg/apis/internalversion/kwokctl_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,25 @@ type KwokctlConfigurationOptions struct {
// KubeSchedulerConfig is the configuration path for kube-scheduler.
KubeSchedulerConfig string

// Components is the configuration for components.
Components []string

// Disable is the configuration for disables components.
Disable []string

// Enable is the configuration for enables components.
Enable []string

// DisableKubeScheduler is the flag to disable kube-scheduler.
// Deprecated: Use Disable instead
DisableKubeScheduler bool

// DisableKubeControllerManager is the flag to disable kube-controller-manager.
// Deprecated: Use Disable instead
DisableKubeControllerManager bool

// EnableMetricsServer is the flag to enable metrics-server.
// Deprecated: Use Enable instead
EnableMetricsServer bool

// EtcdImage is the image of etcd.
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/internalversion/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pkg/apis/internalversion/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/kwokctl/cmd/create/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ func NewCommand(ctx context.Context) *cobra.Command {
cmd.Flags().BoolVar(&flags.Options.SecurePort, "secure-port", flags.Options.SecurePort, `The apiserver port on which to serve HTTPS with authentication and authorization, is not available before Kubernetes 1.13.0`)
cmd.Flags().BoolVar(&flags.Options.QuietPull, "quiet-pull", flags.Options.QuietPull, `Pull without printing progress information`)
cmd.Flags().StringVar(&flags.Options.KubeSchedulerConfig, "kube-scheduler-config", flags.Options.KubeSchedulerConfig, `Path to a kube-scheduler configuration file`)
cmd.Flags().StringSliceVar(&flags.Options.Components, "components", flags.Options.Components, `Default of components`)
cmd.Flags().StringSliceVar(&flags.Options.Disable, "disable", flags.Options.Disable, `Disable list of components`)
cmd.Flags().StringSliceVar(&flags.Options.Enable, "enable", flags.Options.Enable, `Enable list of components`)
cmd.Flags().BoolVar(&flags.Options.DisableKubeScheduler, "disable-kube-scheduler", flags.Options.DisableKubeScheduler, `Disable the kube-scheduler`)
_ = cmd.Flags().MarkDeprecated("disable-kube-scheduler", "--disable-kube-scheduler will be removed in a future release, please use --disable kube-scheduler instead")
cmd.Flags().BoolVar(&flags.Options.DisableKubeControllerManager, "disable-kube-controller-manager", flags.Options.DisableKubeControllerManager, `Disable the kube-controller-manager`)
_ = cmd.Flags().MarkDeprecated("disable-kube-controller-manager", "--disable-kube-controller-manager will be removed in a future release, please use --disable kube-controller-manager instead")
cmd.Flags().BoolVar(&flags.Options.EnableMetricsServer, "enable-metrics-server", flags.Options.EnableMetricsServer, `Enable the metrics-server`)
_ = cmd.Flags().MarkDeprecated("enable-metrics-server", "--enable-metrics-server will be removed in a future release, please use --enable metrics-server instead")
cmd.Flags().StringVar(&flags.Options.EtcdImage, "etcd-image", flags.Options.EtcdImage, `Image of etcd, only for docker/podman/nerdctl runtime
'${KWOK_KUBE_IMAGE_PREFIX}/etcd:${KWOK_ETCD_VERSION}'
`)
Expand Down
31 changes: 11 additions & 20 deletions pkg/kwokctl/components/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ import (

// BuildPrometheusComponentConfig is the configuration for building a prometheus component.
type BuildPrometheusComponentConfig struct {
Runtime string
Binary string
Image string
Version version.Version
Workdir string
BindAddress string
Port uint32
ConfigPath string
AdminCertPath string
AdminKeyPath string
Verbosity log.Level
DisableKubeControllerManager bool
DisableKubeScheduler bool
Runtime string
Binary string
Image string
Version version.Version
Workdir string
BindAddress string
Port uint32
ConfigPath string
AdminCertPath string
AdminKeyPath string
Verbosity log.Level
}

// BuildPrometheusComponent builds a prometheus component.
Expand Down Expand Up @@ -112,13 +110,6 @@ func BuildPrometheusComponent(conf BuildPrometheusComponentConfig) (component in
links := []string{
consts.ComponentEtcd,
consts.ComponentKubeApiserver,
consts.ComponentKwokController,
}
if !conf.DisableKubeControllerManager {
links = append(links, consts.ComponentKubeControllerManager)
}
if !conf.DisableKubeScheduler {
links = append(links, consts.ComponentKubeScheduler)
}

return internalversion.Component{
Expand Down
Loading

0 comments on commit 491ed77

Please sign in to comment.