mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Only run two service-lb if there are more than 1 nodes ready
This commit is contained in:
parent
bd269f8d3e
commit
84756df8a2
@ -229,9 +229,23 @@ func (h *handler) resolvePort(svc *core.Service, targetPort core.ServicePort) (i
|
|||||||
|
|
||||||
func (h *handler) newDeployment(svc *core.Service) (*apps.Deployment, error) {
|
func (h *handler) newDeployment(svc *core.Service) (*apps.Deployment, error) {
|
||||||
name := fmt.Sprintf("svclb-%s", svc.Name)
|
name := fmt.Sprintf("svclb-%s", svc.Name)
|
||||||
zero := intstr.FromInt(0)
|
zeroInt := intstr.FromInt(0)
|
||||||
one := intstr.FromInt(1)
|
oneInt := intstr.FromInt(1)
|
||||||
two := int32(2)
|
replicas := int32(0)
|
||||||
|
|
||||||
|
nodes, err := h.nodeCache.List("", labels.Everything())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, node := range nodes {
|
||||||
|
if Ready.IsTrue(node) {
|
||||||
|
replicas += 1
|
||||||
|
}
|
||||||
|
if replicas >= 2 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dep := &apps.Deployment{
|
dep := &apps.Deployment{
|
||||||
ObjectMeta: meta.ObjectMeta{
|
ObjectMeta: meta.ObjectMeta{
|
||||||
@ -252,7 +266,7 @@ func (h *handler) newDeployment(svc *core.Service) (*apps.Deployment, error) {
|
|||||||
APIVersion: "apps/v1",
|
APIVersion: "apps/v1",
|
||||||
},
|
},
|
||||||
Spec: apps.DeploymentSpec{
|
Spec: apps.DeploymentSpec{
|
||||||
Replicas: &two,
|
Replicas: &replicas,
|
||||||
Selector: &meta.LabelSelector{
|
Selector: &meta.LabelSelector{
|
||||||
MatchLabels: map[string]string{
|
MatchLabels: map[string]string{
|
||||||
"app": name,
|
"app": name,
|
||||||
@ -269,8 +283,8 @@ func (h *handler) newDeployment(svc *core.Service) (*apps.Deployment, error) {
|
|||||||
Strategy: apps.DeploymentStrategy{
|
Strategy: apps.DeploymentStrategy{
|
||||||
Type: apps.RollingUpdateDeploymentStrategyType,
|
Type: apps.RollingUpdateDeploymentStrategyType,
|
||||||
RollingUpdate: &apps.RollingUpdateDeployment{
|
RollingUpdate: &apps.RollingUpdateDeployment{
|
||||||
MaxSurge: &zero,
|
MaxSurge: &zeroInt,
|
||||||
MaxUnavailable: &one,
|
MaxUnavailable: &oneInt,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user