Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Support genereate node name
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Jan 11, 2022
1 parent e735091 commit 21e726f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd/fake-kubelet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"net/http"
"os"
"strconv"
"strings"

"github.com/spf13/pflag"
Expand All @@ -22,6 +23,8 @@ var (
cidr = getEnv("CIDR", "10.0.0.1/24")
nodeIP = net.ParseIP(getEnv("NODE_IP", "196.168.0.1"))
nodeName = getEnv("NODE_NAME", "fake")
generateNodeName = getEnv("GENERATE_NODE_NAME", "")
generateReplicas = getEnv("GENERATE_REPLICAS", "0")
kubeconfig = getEnv("KUBECONFIG", "")
healthAddress = getEnv("HEALTH_ADDRESS", "")
statusPodTemplate = getEnv("POD_STATUS_TEMPLATE", defaultPodStatusTemplate)
Expand Down Expand Up @@ -64,7 +67,17 @@ func main() {
if err != nil {
log.Fatalln(err)
}
n := fake_kubelet.NewController(cliset, strings.SplitN(nodeName, ",", -1), cidrIP, cidrIPNet, nodeIP, statusPodTemplate, nodeTemplate, nodeHeartbeatTemplate, nodeInitializationTemplate)

nodes := strings.SplitN(nodeName, ",", -1)
if generateNodeName != "" {
u, err := strconv.ParseUint(generateReplicas, 10, 64)
if err == nil {
for i := 0; i != int(u); i++ {
nodes = append(nodes, generateNodeName+strconv.Itoa(i))
}
}
}
n := fake_kubelet.NewController(cliset, nodes, cidrIP, cidrIPNet, nodeIP, statusPodTemplate, nodeTemplate, nodeHeartbeatTemplate, nodeInitializationTemplate)

err = n.LockNodeStatus(ctx)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ spec:
env:
- name: NODE_NAME
value: fake
- name: GENERATE_NODE_NAME
value: fake-
- name: GENERATE_REPLICAS
value: "5"
- name: CIDR
value: 10.0.0.1/24
- name: HEALTH_ADDRESS
Expand Down

0 comments on commit 21e726f

Please sign in to comment.