Skip to content

Commit

Permalink
Add kwokctl component api
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Nov 24, 2023
1 parent 63d0e9f commit 88e9631
Show file tree
Hide file tree
Showing 64 changed files with 3,036 additions and 2,648 deletions.
55 changes: 55 additions & 0 deletions kustomize/kwokctl/component/dashboard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: config.kwok.x-k8s.io/v1alpha1
kind: KwokctlComponent
metadata:
name: dashboard
parameters:
image: ""
binary: ""
version: "2.7.0"
bindAddress: "0.0.0.0"
port: 8000
template: |-
{{ $version :=
( or
( env "KWOK_DASHBOARD_VERSION" )
.version
)
}}
{{ $image :=
( or
.image
( env "KWOK_DASHBOARD_IMAGE" )
( join
""
( list
( or
( env "KWOK_DASHBOARD_IMAGE_PREFIX" )
"docker.io/kubernetesui"
)
"/dashboard:v"
$version
)
)
)
}}
image: {{ $image }}
binary: {{ .binary }}
links:
- kube-apiserver
ports:
- name: http
port: {{ .port }}
hostPort: {{ .port }}
protocol: TCP
args:
- --insecure-bind-address={{ .bindAddress }}
- --insecure-port={{ .port }}
- --bind-address=127.0.0.1
- --port=0
- --enable-insecure-login
- --enable-skip-login
- --disable-settings-authorizer
- --metrics-provider=none
- --system-banner=Welcome to {{ ClusterName }}
- --kubeconfig={{ Kubeconfig }}
36 changes: 36 additions & 0 deletions kustomize/kwokctl/component/embed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
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 component contains default component for kwokctl.
package component

import (
_ "embed"
)

var (
// DefaultDashboard is the default dashboard component.
//go:embed dashboard.yaml
DefaultDashboard string

// DefaultPrometheus is the default prometheus component.
//go:embed prometheus.yaml
DefaultPrometheus string

// DefaultKwokController is the default kwok controller component.
//go:embed kwok-controller.yaml
DefaultKwokController string
)
6 changes: 6 additions & 0 deletions kustomize/kwokctl/component/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- dashboard.yaml
- prometheus.yaml
- kwok-controller.yaml
225 changes: 225 additions & 0 deletions kustomize/kwokctl/component/kwok-controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@

# // BuildKwokControllerComponent builds a kwok controller component.
# func BuildKwokControllerComponent(conf BuildKwokControllerComponentConfig) (component internalversion.Component) {
# kwokControllerArgs := []string{}
# if conf.ManageNodesWithAnnotationSelector == "" {
# kwokControllerArgs = append(kwokControllerArgs,
# "--manage-all-nodes=true",
# )
# } else {
# kwokControllerArgs = append(kwokControllerArgs,
# "--manage-all-nodes=false",
# "--manage-nodes-with-annotation-selector="+conf.ManageNodesWithAnnotationSelector,
# )
# }
#
# kwokControllerArgs = append(kwokControllerArgs, extraArgsToStrings(conf.ExtraArgs)...)
#
# var volumes []internalversion.Volume
# volumes = append(volumes, conf.ExtraVolumes...)
# var ports []internalversion.Port
#
# if getRuntimeKind(conf.Runtime) != runtimeKindRaw {
# 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,
# },
# internalversion.Volume{
# HostPath: conf.ConfigPath,
# MountPath: "/root/.kwok/kwok.yaml",
# ReadOnly: true,
# },
# )
#
# if conf.Port != 0 {
# ports = append(ports,
# internalversion.Port{
# HostPort: conf.Port,
# Port: 10247,
# },
# )
# }
# kwokControllerArgs = append(kwokControllerArgs,
# "--kubeconfig=/root/.kube/config",
# "--config=/root/.kwok/kwok.yaml",
# "--tls-cert-file=/etc/kubernetes/pki/admin.crt",
# "--tls-private-key-file=/etc/kubernetes/pki/admin.key",
# "--node-ip="+conf.NodeIP,
# "--node-name="+conf.NodeName,
# "--node-port=10247",
# "--server-address="+conf.BindAddress+":10247",
# "--node-lease-duration-seconds="+format.String(conf.NodeLeaseDurationSeconds),
# )
# } else {
# kwokControllerArgs = append(kwokControllerArgs,
# "--kubeconfig="+conf.KubeconfigPath,
# "--config="+conf.ConfigPath,
# "--tls-cert-file="+conf.AdminCertPath,
# "--tls-private-key-file="+conf.AdminKeyPath,
# "--node-ip="+conf.NodeIP,
# "--node-name="+conf.NodeName,
# "--node-port="+format.String(conf.Port),
# "--server-address="+conf.BindAddress+":"+format.String(conf.Port),
# "--node-lease-duration-seconds="+format.String(conf.NodeLeaseDurationSeconds),
# )
# }
#
# var metricsHost string
# switch getRuntimeKind(conf.Runtime) {
# case runtimeKindRaw:
# metricsHost = net.LocalAddress + ":" + format.String(conf.Port)
# case runtimeKindContainer:
# metricsHost = conf.ProjectName + "-" + consts.ComponentKwokController + ":10247"
# case runtimeKindCluster:
# metricsHost = net.LocalAddress + ":10247"
# }
#
# var metric *internalversion.ComponentMetric
# var metricsDiscoveries []internalversion.ComponentMetric
#
# if metricsHost != "" {
# metric = &internalversion.ComponentMetric{
# Scheme: "http",
# Host: metricsHost,
# Path: "/metrics",
# }
# metricsDiscoveries = append(metricsDiscoveries, internalversion.ComponentMetric{
# Name: "kwok-service-discovery",
# Scheme: "http",
# Host: metricsHost,
# Path: "/discovery/CONTROLLER",
# })
# }
#
# if conf.Verbosity != log.LevelInfo {
# kwokControllerArgs = append(kwokControllerArgs, "--v="+format.String(conf.Verbosity))
# }
#
# if len(conf.EnableCRDs) != 0 {
# kwokControllerArgs = append(kwokControllerArgs, "--enable-crds="+strings.Join(conf.EnableCRDs, ","))
# }
#
# envs := []internalversion.Env{}
# envs = append(envs, conf.ExtraEnvs...)
#
# return internalversion.Component{
# Name: consts.ComponentKwokController,
# Version: conf.Version.String(),
# Links: []string{
# consts.ComponentKubeApiserver,
# },
# Ports: ports,
# Command: []string{"kwok"},
# Volumes: volumes,
# Args: kwokControllerArgs,
# Binary: conf.Binary,
# Image: conf.Image,
# Metric: metric,
# MetricsDiscoveries: metricsDiscoveries,
# WorkDir: conf.Workdir,
# Envs: envs,
# }
# }

apiVersion: config.kwok.x-k8s.io/v1alpha1
kind: KwokctlComponent
metadata:
name: dashboard
parameters:
image: ""
binary: ""
version: "0.4.0"
bindAddress: "0.0.0.0"
port: 10247
expose: false
template: |-
{{ $version :=
( or
( env "KWOK_CONTROLLER_VERSION" )
.version
)
}}
{{ $image :=
( or
.image
( env "KWOK_CONTROLLER_IMAGE" )
( printf
"%s/kwok:v%s"
( or
( env "KWOK_CONTROLLER_IMAGE_PREFIX" )
"registry.k8s.io/kwok"
)
$version
)
)
}}
{{ $binary :=
( or
.binary
( env "KWOK_CONTROLLER_BINARY" )
( printf
"%s/kwok-%s-%s"
( or
( env "KWOK_CONTROLLER_BINARY_PREFIX" )
( printf
"https://github.com/kubernetes-sigs/kwok/releases/download/v%s/"
$version
)
)
( goos )
( goarch )
)
)
}}
image: {{ $image }}
binary: {{ $binary }}
links:
- kube-apiserver
workdir: {{ Workdir }}
{{ if .expose }}
ports:
- name: http
port: {{ .port }}
hostPort: {{ .port }}
protocol: TCP
{{ end }}
args:
{{ if eq Mode "cluster" }}
- --manage-all-nodes=false
- --manage-nodes-with-annotation-selector=kwok.x-k8s.io/node=fake
{{ else }}
- --manage-all-nodes=true
{{ end }}
- --kubeconfig={{ Kubeconfig }}
- --config=~/.kwok/kwok.yaml
{{ if eq ( Mode ) "cluster" }}
- --node-ip=$(POD_IP)
- --node-name=kwok-controller.kube-system.svc
{{ else }}
- --node-name={{ Address }}
{{ end }}
- --node-port={{ .port }}
- --server-address=0.0.0.0:{{ .port }}
- --node-lease-duration-seconds={{ Config.Options.NodeLeaseDurationSeconds }}
metric:
scheme: http
host: {{ Address }}:{{ .port }}
path: /metrics
Loading

0 comments on commit 88e9631

Please sign in to comment.