Skip to content

Commit

Permalink
feat(platform): add ha vrid configuration on master (tkestack#1001)
Browse files Browse the repository at this point in the history
Co-authored-by: dihu <[email protected]>
  • Loading branch information
BeyondMS and dihu committed Dec 11, 2020
1 parent 4946d5e commit b1762a2
Show file tree
Hide file tree
Showing 13 changed files with 440 additions and 368 deletions.
6 changes: 6 additions & 0 deletions api/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/platform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ type HA struct {

type TKEHA struct {
VIP string
VRID *int32
}

type ThirdPartyHA struct {
Expand Down
752 changes: 391 additions & 361 deletions api/platform/v1/generated.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/platform/v1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion api/platform/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ type HA struct {
}

type TKEHA struct {
VIP string `json:"vip" protobuf:"bytes,1,name=vip"`
VIP string `json:"vip" protobuf:"bytes,1,name=vip"`
VRID *int32 `json:"vrid,omitempty" protobuf:"bytes,2,name=vrid"`
}

type ThirdPartyHA struct {
Expand Down
2 changes: 2 additions & 0 deletions api/platform/v1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion api/platform/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions api/platform/validation/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ func ValidateHA(ha *platform.HA, fldPath *field.Path) field.ErrorList {
allErrs = append(allErrs, field.Invalid(fldPath.Child("tke").Child("vip"), ha.TKEHA.VIP, msg))

}

if ha.TKEHA.VRID != nil {
if *ha.TKEHA.VRID < 1 || *ha.TKEHA.VRID > 255 {
msg := "must be a valid vrid, range [1, 255]"
allErrs = append(allErrs, field.Invalid(fldPath.Child("tke").Child("vrid"), ha.TKEHA.VRID, msg))
}
}
}
if ha.ThirdPartyHA != nil {
for _, msg := range validation.IsValidIP(ha.ThirdPartyHA.VIP) {
Expand Down
7 changes: 6 additions & 1 deletion api/platform/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion cmd/tke-installer/app/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,10 @@ func (t *TKE) setClusterDefault(cluster *platformv1.Cluster, config *types.Confi
if config.HA != nil {
if t.Para.Config.HA.TKEHA != nil {
cluster.Spec.Features.HA = &platformv1.HA{
TKEHA: &platformv1.TKEHA{VIP: t.Para.Config.HA.TKEHA.VIP},
TKEHA: &platformv1.TKEHA{
VIP: t.Para.Config.HA.TKEHA.VIP,
VRID: t.Para.Config.HA.TKEHA.VRID,
},
}
}
if t.Para.Config.HA.ThirdPartyHA != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/tke-installer/app/installer/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ func (ha *HA) VIP() string {
}

type TKEHA struct {
VIP string `json:"vip" validate:"required"`
VIP string `json:"vip" validate:"required"`
VRID *int32 `json:"vrid"`
}

type ThirdPartyHA struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/platform/provider/baremetal/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ func (p *Provider) EnsureKeepalivedInit(ctx context.Context, c *v1.Cluster) erro
option := &keepalived.Option{
IP: c.Spec.Machines[0].IP,
VIP: c.Spec.Features.HA.TKEHA.VIP,
VRID: c.Spec.Features.HA.TKEHA.VRID,
LoadBalance: false,
IPVS: false,
KubernetesSvcIP: kubernetesSvcIP,
Expand Down Expand Up @@ -1362,6 +1363,7 @@ func (p *Provider) EnsureKeepalivedWithLBOption(ctx context.Context, c *v1.Clust
option := &keepalived.Option{
IP: machine.IP,
VIP: c.Spec.Features.HA.TKEHA.VIP,
VRID: c.Spec.Features.HA.TKEHA.VRID,
LoadBalance: true,
IPVS: ipvs,
KubernetesSvcIP: kubernetesSvcIP,
Expand Down
11 changes: 9 additions & 2 deletions pkg/platform/provider/baremetal/phases/keepalived/keepalived.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
type Option struct {
IP string
VIP string
VRID *int32
LoadBalance bool
IPVS bool
KubernetesSvcIP string
Expand All @@ -44,7 +45,13 @@ var svcPortChain = "KUBE-SVC-NPX46M4PTMTKRN6Y"

// vrid gets vrid from last byte of vip and plus 1 to prevent from vip ends with zero,
// bcs vrid ranges from 1 to 255. if vip ends with 255, then throw error.
func vrid(vip string) (int, error) {
func vrid(vip string, vrid *int32) (int, error) {
if vrid != nil {
if *vrid > 0 && *vrid < 256 {
return int(*vrid), nil
}
}

var lastbyte = net.ParseIP(vip).To16()[net.IPv6len-1]
if lastbyte >= 255 {
return 1, fmt.Errorf("unusual vip :%s", vip)
Expand All @@ -59,7 +66,7 @@ func Install(s ssh.Interface, option *Option) error {
return fmt.Errorf("can't get network interface by %s", option.IP)
}

vrid, err := vrid(option.VIP)
vrid, err := vrid(option.VIP, option.VRID)
if err != nil {
return err
}
Expand Down

0 comments on commit b1762a2

Please sign in to comment.