Skip to content

Commit

Permalink
Integrate metrics-server
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Jul 21, 2023
1 parent 303c34e commit 5242d36
Show file tree
Hide file tree
Showing 18 changed files with 576 additions and 5 deletions.
27 changes: 27 additions & 0 deletions pkg/apis/config/v1alpha1/kwokctl_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ type KwokctlConfigurationOptions struct {
// is the default value for env KWOK_PROMETHEUS_VERSION
PrometheusVersion string `json:"prometheusVersion,omitempty"`

// MetricsServerVersion is the version of metrics-server to use.
MetricsServerVersion string `json:"metricsServerVersion,omitempty"`

// DockerComposeVersion is the version of docker-compose to use.
// is the default value for env KWOK_DOCKER_COMPOSE_VERSION
// Deprecated: docker compose will be removed in a future release
Expand Down Expand Up @@ -142,6 +145,10 @@ type KwokctlConfigurationOptions struct {
// +default=false
DisableKubeControllerManager *bool `json:"disableKubeControllerManager,omitempty"`

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

// KubeImagePrefix is the prefix of the kubernetes image.
// is the default value for env KWOK_KUBE_IMAGE_PREFIX
//+k8s:conversion-gen=false
Expand All @@ -162,6 +169,10 @@ type KwokctlConfigurationOptions struct {
//+k8s:conversion-gen=false
PrometheusImagePrefix string `json:"prometheusImagePrefix,omitempty"`

// MetricsServerImagePrefix is the prefix of the metrics-server image.
//+k8s:conversion-gen=false
MetricsServerImagePrefix string `json:"metricsServerImagePrefix,omitempty"`

// EtcdImage is the image of etcd.
// is the default value for flag --etcd-image and env KWOK_ETCD_IMAGE
EtcdImage string `json:"etcdImage,omitempty"`
Expand All @@ -186,6 +197,9 @@ type KwokctlConfigurationOptions struct {
// is the default value for flag --prometheus-image and env KWOK_PROMETHEUS_IMAGE
PrometheusImage string `json:"prometheusImage,omitempty"`

// MetricsServerImage is the image of metrics-server.
MetricsServerImage string `json:"metricsServerImage,omitempty"`

// KindNodeImagePrefix is the prefix of the kind node image.
// is the default value for env KWOK_KIND_NODE_IMAGE_PREFIX
//+k8s:conversion-gen=false
Expand Down Expand Up @@ -255,6 +269,13 @@ type KwokctlConfigurationOptions struct {
// is the default value for env KWOK_PROMETHEUS_BINARY_TAR
PrometheusBinaryTar string `json:"prometheusBinaryTar,omitempty"`

// MetricsServerBinaryPrefix is the prefix of the metrics-server binary.
//+k8s:conversion-gen=false
MetricsServerBinaryPrefix string `json:"metricsServerBinaryPrefix,omitempty"`

// MetricsServerBinary is the binary of metrics-server.
MetricsServerBinary string `json:"metricsServerBinary,omitempty"`

// DockerComposeBinaryPrefix is the binary of docker-compose.
// is the default value for env KWOK_DOCKER_COMPOSE_BINARY_PREFIX
// Deprecated: docker compose will be removed in a future release
Expand Down Expand Up @@ -315,6 +336,9 @@ type KwokctlConfigurationOptions struct {
// is the default value for flag --controller-port and env KWOK_CONTROLLER_PORT
KwokControllerPort uint32 `json:"kwokControllerPort,omitempty"`

// MetricsServerPort is metrics-server port that is exposed to the host.
MetricsServerPort uint32 `json:"metricsServerPort,omitempty"`

// CacheDir is the directory of the cache.
CacheDir string `json:"cacheDir,omitempty"`

Expand Down Expand Up @@ -369,6 +393,9 @@ type Component struct {
// +optional
Command []string `json:"command,omitempty"`

// User is the user for the component.
User string `json:"user,omitempty"`

// Args is Arguments to the entrypoint.
// +optional
Args []string `json:"args,omitempty"`
Expand Down
5 changes: 5 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.

4 changes: 4 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.

18 changes: 18 additions & 0 deletions pkg/apis/internalversion/kwokctl_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ type KwokctlConfigurationOptions struct {
// PrometheusVersion is the version of Prometheus to use.
PrometheusVersion string

// MetricsServerVersion is the version of metrics-server to use.
MetricsServerVersion string

// DockerComposeVersion is the version of docker-compose to use.
DockerComposeVersion string

Expand All @@ -111,6 +114,9 @@ type KwokctlConfigurationOptions struct {
// DisableKubeControllerManager is the flag to disable kube-controller-manager.
DisableKubeControllerManager bool

// EnableMetricsServer is the flag to enable metrics-server.
EnableMetricsServer bool

// EtcdImage is the image of etcd.
EtcdImage string

Expand All @@ -129,6 +135,9 @@ type KwokctlConfigurationOptions struct {
// PrometheusImage is the image of Prometheus.
PrometheusImage string

// MetricsServerImage is the image of metrics-server.
MetricsServerImage string

// KindNodeImage is the image of kind node.
KindNodeImage string

Expand Down Expand Up @@ -163,6 +172,9 @@ type KwokctlConfigurationOptions struct {
// PrometheusBinaryTar is the tar of binary of Prometheus.
PrometheusBinaryTar string

// MetricsServerBinary is the binary of metrics-server.
MetricsServerBinary string

// DockerComposeBinary is the binary of Docker compose.
DockerComposeBinary string

Expand Down Expand Up @@ -202,6 +214,9 @@ type KwokctlConfigurationOptions struct {
// KwokControllerPort is kwok-controller port that is exposed to the host.
KwokControllerPort uint32

// MetricsServerPort is metrics-server port that is exposed to the host.
MetricsServerPort uint32

// CacheDir is the directory of the cache.
CacheDir string

Expand Down Expand Up @@ -246,6 +261,9 @@ type Component struct {
// Command is Entrypoint array. Not executed within a shell. Only works with Image.
Command []string

// User is the user for the component.
User string

// Args is Arguments to the entrypoint.
Args []string

Expand Down
18 changes: 18 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.

25 changes: 25 additions & 0 deletions pkg/config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ func setKwokctlConfigurationDefaults(config *configv1alpha1.KwokctlConfiguration

setKwokctlPrometheusConfig(conf)

setMetricsServerConfig(conf)

return config
}

Expand Down Expand Up @@ -447,6 +449,29 @@ func setKwokctlPrometheusConfig(conf *configv1alpha1.KwokctlConfigurationOptions
conf.PrometheusBinaryTar = envs.GetEnvWithPrefix("PROMETHEUS_BINARY_TAR", conf.PrometheusBinaryTar)
}

func setMetricsServerConfig(conf *configv1alpha1.KwokctlConfigurationOptions) {
if conf.MetricsServerVersion == "" {
conf.MetricsServerVersion = consts.MetricsServerVersion
}

if conf.MetricsServerImagePrefix == "" {
conf.MetricsServerImagePrefix = consts.MetricsServerImagePrefix
}

if conf.MetricsServerImage == "" {
conf.MetricsServerImage = joinImageURI(conf.MetricsServerImagePrefix, "metrics-server", version.AddPrefixV(conf.MetricsServerVersion))
}

// Metrics Server is not released for binary yet.
// TODO: Add binary support for Metrics Server.
//if conf.MetricsServerBinaryPrefix == "" {
// conf.MetricsServerBinaryPrefix = consts.MetricsServerBinaryPrefix + "/" + conf.MetricsServerVersion
//}
//if conf.MetricsServerBinary == "" {
// conf.MetricsServerBinary = conf.MetricsServerBinaryPrefix + "/metrics-server-" + GOOS + "-" + GOARCH + conf.BinSuffix
//}
}

// joinImageURI joins the image URI.
func joinImageURI(prefix, name, version string) string {
return prefix + "/" + name + ":" + version
Expand Down
4 changes: 4 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ var (
PrometheusBinaryPrefix = "https://github.com/prometheus/prometheus/releases/download"
PrometheusImagePrefix = "docker.io/prom"

MetricsServerVersion = "0.6.3"
MetricsServerBinaryPrefix = ""
MetricsServerImagePrefix = "registry.k8s.io/metrics-server"

KindNodeImagePrefix = "docker.io/kindest"

DefaultUnlimitedQPS = 5000.0
Expand Down
7 changes: 7 additions & 0 deletions pkg/kwok/metrics/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type Counter interface {
prometheus.Collector
// Set sets the counter to the given value.
Set(value float64)
// Get returns the current value of the counter.
Get() float64
}

// NewCounter returns a new counter.
Expand All @@ -57,3 +59,8 @@ func NewCounter(opts CounterOpts) Counter {
func (c *counter) Set(value float64) {
c.value.Store(value)
}

// Get returns the current value of the counter.
func (c *counter) Get() float64 {
return c.value.Load()
}
Loading

0 comments on commit 5242d36

Please sign in to comment.