1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package clusterstack
import (
"errors"
"fmt"
"path/filepath"
)
const (
KubeSchedulerConfigFileName = "kube-scheduler.yaml"
SchedulerKubeconfigName = "scheduler.kubeconfig"
MarketSchedulerPodInitialBackoffSeconds = 1
MarketSchedulerPodMaxBackoffSeconds = 1
)
var ErrNoSchedulerBackoffForAPlainCluster = errors.New(
"clusterstack: a kube-scheduler config is rendered for a market cluster only. A market " +
"cluster is the one that starts from zero nodes, and a pod that was unschedulable while " +
"it had none is held for kube-scheduler's backoff (1 s doubling to 10 s) after the first " +
"node arrives. A stack that dials no market has no zero-node window to shorten, and its " +
"argv names no config file, so a file rendered for it would be read by nobody")
var ErrNoSchedulerDataDir = errors.New(
"clusterstack: Spec.DataDir must be absolute before a kube-scheduler config can be rendered " +
"from it. The config names the scheduler's kubeconfig by a path derived from DataDir, and " +
"k3s reads that path as it stands: a relative one resolves against whichever directory " +
"the server happened to start in, so the running scheduler would be handed another " +
"cluster's apiserver")
func SchedulerKubeconfig(dataDir string) string {
return filepath.Join(CredDir(dataDir), SchedulerKubeconfigName)
}
func KubeSchedulerConfigPath(dataDir string) string {
return filepath.Join(dataDir, KubeSchedulerConfigFileName)
}
func (s Spec) KubeSchedulerConfig() ([]byte, error) {
if !s.MarketDialled {
return nil, ErrNoSchedulerBackoffForAPlainCluster
}
if !filepath.IsAbs(s.DataDir) {
return nil, fmt.Errorf("%w (%q)", ErrNoSchedulerDataDir, s.DataDir)
}
return fmt.Appendf(nil, `apiVersion: kubescheduler.config.k8s.io/v1
kind: KubeSchedulerConfiguration
clientConnection:
kubeconfig: %s
leaderElection:
leaderElect: true
leaseDuration: 4s
renewDeadline: 3s
retryPeriod: 1s
podInitialBackoffSeconds: %d
podMaxBackoffSeconds: %d
`, SchedulerKubeconfig(s.serverDir()), MarketSchedulerPodInitialBackoffSeconds,
MarketSchedulerPodMaxBackoffSeconds), nil
}
func (s Spec) schedulerArgv() []string {
if !s.MarketDialled {
return nil
}
return []string{"--kube-scheduler-arg=config=" + s.KubeSchedulerConfigFile()}
}
func (s Spec) KubeSchedulerConfigFile() string { return KubeSchedulerConfigPath(s.serverDir()) }