Skip to content

Commit

Permalink
高可用部署主备选取应将kube-apiserver是否工作考虑进去
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhang Dongliang committed Jul 15, 2020
1 parent 41045fb commit d8f027f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
DefaultPromtailVersion = DefaultLokiVersion
Grafana = "grafana"
DefaultGrafanaVersion = "6.5.2"
DefaultKeepalivedVersionTag = "v2.0.23"
DefaultKeepalivedVersionTag = "v2.0.24"
// mirror of kiwigrid/k8s-sidecar:0.1.20
K8sSidecar = "k8s-sidecar"
DefaultK8sSidecarVersion = "0.1.20"
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@ func (d *initData) OperatorVersion() string {
return d.operatorVersion
}

// GetNodeIP returns current node ip for init mode
func (d *initData) GetNodeIP() string {
return d.nodeIP
}

func printJoinCommand(out io.Writer, adminKubeConfigPath, token string, i *initData) error {
joinControlPlaneCommand, err := occmdutil.GetJoinControlPlaneCommand(adminKubeConfigPath, token, i.certificateKey, i.skipTokenPrint, i.skipCertificateKeyPrint)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ func (j *joinData) OutputWriter() io.Writer {
return j.outputWriter
}

// GetNodeIP returns current node ip for join mode
func (j *joinData) GetNodeIP() string {
return j.nodeIP
}

// fetchInitConfigurationFromJoinConfiguration retrieves the init configuration from a join configuration, performing the discovery
func fetchInitConfigurationFromJoinConfiguration(cfg *apiv1.JoinConfiguration, tlsBootstrapCfg *clientcmdapi.Config) (*apiv1.InitConfiguration, error) {
// Retrieves the kubeadm configuration
Expand Down
17 changes: 12 additions & 5 deletions pkg/phases/addons/keepalived/keepalived.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func runKeepalivedPhaseLocal() func(c workflow.RunData) error {
role := "MASTER"
idata, ok := c.(ocadm_init.InitData)
keepalivedVersionTag := ""
nodeIP := ""
if !ok {
jdata, ok := c.(ocadm_join.JoinData)
if !ok {
Expand All @@ -86,9 +87,11 @@ func runKeepalivedPhaseLocal() func(c workflow.RunData) error {
role = "BACKUP"
vip = jdata.GetHighAvailabilityVIP()
keepalivedVersionTag = jdata.GetKeepalivedVersionTag()
nodeIP = jdata.GetNodeIP()
} else {
vip = idata.GetHighAvailabilityVIP()
keepalivedVersionTag = idata.GetKeepalivedVersionTag()
nodeIP = idata.GetNodeIP()
}
if len(vip) == 0 {
fmt.Println("vip is empty. no need to install keepalived.")
Expand All @@ -101,22 +104,22 @@ func runKeepalivedPhaseLocal() func(c workflow.RunData) error {
fmt.Println("got Keepalived version tag from commandline: ", keepalivedVersionTag)
}

fmt.Printf("[PASS] Installing Keepalived:%s as %s", keepalivedVersionTag, role)
fmt.Printf("[PASS] Installing Keepalived:%s as %s, nodeIP[%s]", keepalivedVersionTag, role, nodeIP)
dataPath := "/var/lib/keepalived"
if err := os.MkdirAll(dataPath, 0700); err != nil {
return errors.Wrapf(err, "failed to create Keepalived directory %q", dataPath)
} else {
fmt.Println("[PASS] keepalived path created.")
}
if err := CreateLocalKeepalivedStaticPodManifestFile(vip, keepalivedVersionTag, role); err != nil {
if err := CreateLocalKeepalivedStaticPodManifestFile(vip, keepalivedVersionTag, role, nodeIP); err != nil {
return errors.Wrap(err, "error creating local keepalived static pod manifest file")
}
return nil
}
}

func CreateLocalKeepalivedStaticPodManifestFile(ip, keepalivedVersionTag, role string) error {
spec := GetKeepalivedPodSpec(ip, keepalivedVersionTag, role)
func CreateLocalKeepalivedStaticPodManifestFile(vip, keepalivedVersionTag, role, nodeIP string) error {
spec := GetKeepalivedPodSpec(vip, keepalivedVersionTag, role, nodeIP)
if err := staticpodutil.WriteStaticPodToDisk("keepalived", "/etc/kubernetes/manifests", spec); err != nil {
return err
}
Expand All @@ -130,7 +133,7 @@ func md5ize(str string) string {
return md5str
}

func GetKeepalivedPodSpec(vip, keepalivedVersionTag, role string) v1.Pod {
func GetKeepalivedPodSpec(vip, keepalivedVersionTag, role, nodeIP string) v1.Pod {
privileged := true
priority := "100"
vipPswd := md5ize(b64.StdEncoding.EncodeToString([]byte(vip)))
Expand Down Expand Up @@ -189,6 +192,10 @@ func GetKeepalivedPodSpec(vip, keepalivedVersionTag, role string) v1.Pod {
Name: "KEEPALIVED_ROUTER_ID",
Value: svid,
},
{
Name: "KEEPALIVED_NODE_IP",
Value: nodeIP,
},
},
}, nil)
}
1 change: 1 addition & 0 deletions pkg/phases/init/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ type InitData interface {
AddonCalicoIpAutodetectionMethod() string
GetHighAvailabilityVIP() string
GetKeepalivedVersionTag() string
GetNodeIP() string
}
1 change: 1 addition & 0 deletions pkg/phases/join/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ type JoinData interface {
OnecloudJoinCfg() *apiv1.JoinConfiguration
GetHighAvailabilityVIP() string
GetKeepalivedVersionTag() string
GetNodeIP() string
}

0 comments on commit d8f027f

Please sign in to comment.