Skip to content

Commit

Permalink
Merge pull request #755 from wzshiming/feat/dashborad
Browse files Browse the repository at this point in the history
[kwokctl] Integrate dashboard
  • Loading branch information
wzshiming authored Aug 11, 2023
2 parents 2daecd5 + c9f031e commit df94e74
Show file tree
Hide file tree
Showing 24 changed files with 664 additions and 46 deletions.
21 changes: 21 additions & 0 deletions pkg/apis/config/v1alpha1/kwokctl_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ type KwokctlConfigurationOptions struct {
// is the default value for env KWOK_ETCD_VERSION
EtcdVersion string `json:"etcdVersion,omitempty"`

// DashboardVersion is the version of Kubernetes dashboard to use.
DashboardVersion string `json:"dashboardVersion,omitempty"`

// PrometheusVersion is the version of Prometheus to use.
// is the default value for env KWOK_PROMETHEUS_VERSION
PrometheusVersion string `json:"prometheusVersion,omitempty"`
Expand Down Expand Up @@ -168,6 +171,10 @@ type KwokctlConfigurationOptions struct {
//+k8s:conversion-gen=false
KwokImagePrefix string `json:"kwokImagePrefix,omitempty"`

// DashboardImagePrefix is the prefix of the dashboard image.
//+k8s:conversion-gen=false
DashboardImagePrefix string `json:"dashboardImagePrefix,omitempty"`

// PrometheusImagePrefix is the prefix of the Prometheus image.
// is the default value for env KWOK_PROMETHEUS_IMAGE_PREFIX
//+k8s:conversion-gen=false
Expand Down Expand Up @@ -198,6 +205,9 @@ type KwokctlConfigurationOptions struct {
// is the default value for flag --controller-image and env KWOK_CONTROLLER_IMAGE
KwokControllerImage string `json:"kwokControllerImage,omitempty"`

// DashboardImage is the image of dashboard.
DashboardImage string `json:"dashboardImage,omitempty"`

// PrometheusImage is the image of Prometheus.
// is the default value for flag --prometheus-image and env KWOK_PROMETHEUS_IMAGE
PrometheusImage string `json:"prometheusImage,omitempty"`
Expand Down Expand Up @@ -262,6 +272,14 @@ type KwokctlConfigurationOptions struct {
// is the default value for flag --controller-binary and env KWOK_CONTROLLER_BINARY
KwokControllerBinary string `json:"kwokControllerBinary,omitempty"`

// TODO: Add dashboard binary
// // DashboardBinaryPrefix is the prefix of the dashboard binary.
// //+k8s:conversion-gen=false
// DashboardBinaryPrefix string `json:"dashboardBinaryPrefix,omitempty"`
//
// // DashboardBinary is the binary of dashboard.
// DashboardBinary string `json:"dashboardBinary,omitempty"`

// PrometheusBinaryPrefix is the prefix of the Prometheus binary.
// is the default value for env KWOK_PROMETHEUS_PREFIX
//+k8s:conversion-gen=false
Expand Down Expand Up @@ -344,6 +362,9 @@ type KwokctlConfigurationOptions struct {
// KubeSchedulerPort is kube-scheduler port in the binary runtime
KubeSchedulerPort uint32 `json:"kubeSchedulerPort,omitempty"`

// DashboardPort is dashboard port in the binary runtime
DashboardPort uint32 `json:"dashboardPort,omitempty"`

// KwokControllerPort is kwok-controller port that is exposed to the host.
// is the default value for flag --controller-port and env KWOK_CONTROLLER_PORT
KwokControllerPort uint32 `json:"kwokControllerPort,omitempty"`
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/internalversion/kwokctl_configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ type KwokctlConfigurationOptions struct {
// EtcdVersion is the version of Etcd to use.
EtcdVersion string

// DashboardVersion is the version of Kubernetes dashboard to use.
DashboardVersion string

// PrometheusVersion is the version of Prometheus to use.
PrometheusVersion string

Expand Down Expand Up @@ -135,6 +138,9 @@ type KwokctlConfigurationOptions struct {
// KwokControllerImage is the image of Kwok.
KwokControllerImage string

// DashboardImage is the image of dashboard.
DashboardImage string

// PrometheusImage is the image of Prometheus.
PrometheusImage string

Expand Down Expand Up @@ -169,6 +175,10 @@ type KwokctlConfigurationOptions struct {
// KwokControllerBinary is the binary of kwok.
KwokControllerBinary string

// TODO: Add dashboard binary
// // DashboardBinary is the binary of dashboard.
// DashboardBinary string

// PrometheusBinary is the binary of Prometheus.
PrometheusBinary string

Expand Down Expand Up @@ -217,6 +227,9 @@ type KwokctlConfigurationOptions struct {
// KubeSchedulerPort is kube-scheduler port in the binary runtime
KubeSchedulerPort uint32

// DashboardPort is dashboard port that is exposed to the host.
DashboardPort uint32

// KwokControllerPort is kwok-controller port that is exposed to the host.
KwokControllerPort uint32

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

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

setKwokctlDockerConfig(conf)

setKwokctlDashboardConfig(conf)

setKwokctlPrometheusConfig(conf)

setKwokctlJaegerConfig(conf)
Expand Down Expand Up @@ -425,6 +427,34 @@ func setKwokctlDockerConfig(conf *configv1alpha1.KwokctlConfigurationOptions) {
conf.DockerComposeBinary = envs.GetEnvWithPrefix("DOCKER_COMPOSE_BINARY", conf.DockerComposeBinary)
}

func setKwokctlDashboardConfig(conf *configv1alpha1.KwokctlConfigurationOptions) {
if conf.DashboardVersion == "" {
conf.DashboardVersion = consts.DashboardVersion
}
conf.DashboardVersion = version.AddPrefixV(envs.GetEnvWithPrefix("DASHBOARD_VERSION", conf.DashboardVersion))

if conf.DashboardImagePrefix == "" {
conf.DashboardImagePrefix = consts.DashboardImagePrefix
}
conf.DashboardImagePrefix = envs.GetEnvWithPrefix("DASHBOARD_IMAGE_PREFIX", conf.DashboardImagePrefix)

if conf.DashboardImage == "" {
conf.DashboardImage = joinImageURI(conf.DashboardImagePrefix, "dashboard", conf.DashboardVersion)
}
conf.DashboardImage = envs.GetEnvWithPrefix("DASHBOARD_IMAGE", conf.DashboardImage)

// TODO: Add dashboard binary
// if conf.DashboardBinaryPrefix == "" {
// conf.DashboardBinaryPrefix = consts.DashboardBinaryPrefix + "/" + conf.DashboardVersion
// }
// conf.DashboardBinaryPrefix = envs.GetEnvWithPrefix("DASHBOARD_BINARY_PREFIX", conf.DashboardBinaryPrefix)\
//
// if conf.DashboardBinary == "" {
// conf.DashboardBinary = conf.DashboardBinaryPrefix + "/dashboard-" + GOOS + "-" + GOARCH + conf.BinSuffix
// }
// conf.DashboardBinary = envs.GetEnvWithPrefix("DASHBOARD_BINARY", conf.DashboardBinary)
}

func setKwokctlPrometheusConfig(conf *configv1alpha1.KwokctlConfigurationOptions) {
conf.PrometheusPort = envs.GetEnvWithPrefix("PROMETHEUS_PORT", conf.PrometheusPort)

Expand Down
4 changes: 4 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ var (
KindVersion = "0.19.0"
KindBinaryPrefix = "https://github.com/kubernetes-sigs/kind/releases/download"

DashboardVersion = "2.7.0"
DashboardBinaryPrefix = ""
DashboardImagePrefix = "docker.io/kubernetesui"

PrometheusVersion = "2.44.0"
PrometheusBinaryPrefix = "https://github.com/prometheus/prometheus/releases/download"
PrometheusImagePrefix = "docker.io/prom"
Expand Down
4 changes: 4 additions & 0 deletions pkg/kwokctl/cmd/create/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func NewCommand(ctx context.Context) *cobra.Command {
cmd.Flags().Uint32Var(&flags.Options.KwokControllerPort, "controller-port", flags.Options.KwokControllerPort, `Port of kwok-controller given to the host`)
cmd.Flags().StringVar(&flags.Options.KindNodeImage, "kind-node-image", flags.Options.KindNodeImage, `Image of kind node, only for kind/kind-podman runtime
'${KWOK_KIND_NODE_IMAGE_PREFIX}/node:${KWOK_KUBE_VERSION}'
`)
cmd.Flags().Uint32Var(&flags.Options.DashboardPort, "dashboard-port", flags.Options.DashboardPort, `Port of dashboard given to the host`)
cmd.Flags().StringVar(&flags.Options.DashboardImage, "dashboard-image", flags.Options.DashboardImage, `Image of dashboard, only for docker/podman/nerdctl/kind/kind-podman runtime
'${KWOK_DASHBOARD_IMAGE_PREFIX}/dashboard:${KWOK_DASHBOARD_VERSION}'
`)
cmd.Flags().StringVar(&flags.Options.KubeApiserverBinary, "kube-apiserver-binary", flags.Options.KubeApiserverBinary, `Binary of kube-apiserver, only for binary runtime
`)
Expand Down
116 changes: 116 additions & 0 deletions pkg/kwokctl/components/dashboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
Copyright 2023 The Kubernetes 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 components

import (
"sigs.k8s.io/kwok/pkg/apis/internalversion"
"sigs.k8s.io/kwok/pkg/utils/format"
"sigs.k8s.io/kwok/pkg/utils/version"
)

// BuildDashboardComponentConfig is the configuration for building the dashboard component.
type BuildDashboardComponentConfig struct {
Binary string
Image string
Version version.Version
Workdir string
BindAddress string
Port uint32

Banner string

CaCertPath string
AdminCertPath string
AdminKeyPath string
KubeconfigPath string
}

// BuildDashboardComponent builds the dashboard component.
func BuildDashboardComponent(conf BuildDashboardComponentConfig) (component internalversion.Component, err error) {
dashboardArgs := []string{
"--insecure-bind-address=" + conf.BindAddress,
"--bind-address=127.0.0.1",
"--port=0",
"--enable-insecure-login",
"--enable-skip-login",
"--disable-settings-authorizer",
"--metrics-provider=none",
}
if conf.Banner != "" {
dashboardArgs = append(dashboardArgs, "--system-banner="+conf.Banner)
}

inContainer := conf.Image != ""
user := ""
var volumes []internalversion.Volume
var ports []internalversion.Port
if inContainer {
dashboardArgs = append(dashboardArgs,
"--kubeconfig=/root/.kube/config",
"--insecure-port=8000",
)
volumes = append(volumes,
internalversion.Volume{
HostPath: conf.KubeconfigPath,
MountPath: "/root/.kube/config",
ReadOnly: true,
},
internalversion.Volume{
HostPath: conf.CaCertPath,
MountPath: "/etc/kubernetes/pki/ca.crt",
ReadOnly: true,
},
internalversion.Volume{
HostPath: conf.AdminCertPath,
MountPath: "/etc/kubernetes/pki/admin.crt",
ReadOnly: true,
},
internalversion.Volume{
HostPath: conf.AdminKeyPath,
MountPath: "/etc/kubernetes/pki/admin.key",
ReadOnly: true,
},
)
ports = append(ports,
internalversion.Port{
Name: "http",
Port: 8000,
HostPort: conf.Port,
Protocol: internalversion.ProtocolTCP,
},
)
} else {
dashboardArgs = append(dashboardArgs,
"--kubeconfig="+conf.KubeconfigPath,
"--insecure-port="+format.String(conf.Port),
)
}

component = internalversion.Component{
Name: "dashboard",
Image: conf.Image,
Links: []string{
"kube-apiserver",
},
WorkDir: conf.Workdir,
Ports: ports,
Volumes: volumes,
Args: dashboardArgs,
User: user,
}
return component, nil
}
9 changes: 9 additions & 0 deletions pkg/kwokctl/runtime/binary/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ func (c *Cluster) download(ctx context.Context) error {
}
}

// TODO: Add dashboard binary
// if conf.DashboardPort != 0 {
// kubeDashboardPath := c.GetBinPath("dashboard" + conf.BinSuffix)
// err = c.DownloadWithCache(ctx, conf.CacheDir, conf.DashboardBinary, kubeDashboardPath, 0750, conf.QuietPull)
// if err != nil {
// return err
// }
// }

kwokControllerPath := c.GetBinPath("kwok-controller" + conf.BinSuffix)
err = c.DownloadWithCache(ctx, conf.CacheDir, conf.KwokControllerBinary, kwokControllerPath, 0750, conf.QuietPull)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/kwokctl/runtime/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
Prometheus = "prometheus.yaml"
KindName = "kind.yaml"
KwokPod = "kwok-controller-pod.yaml"
DashboardDeploy = "dashboard-deployment.yaml"
PrometheusDeploy = "prometheus-deployment.yaml"
JaegerDeploy = "jaeger-deployment.yaml"
AuditPolicyName = "audit.yaml"
Expand Down
Loading

0 comments on commit df94e74

Please sign in to comment.