Skip to content

Commit

Permalink
Merge pull request #141 from yboaron/get_endpoints
Browse files Browse the repository at this point in the history
Bug 1886572: Calculate keepalived priority for ingress
  • Loading branch information
openshift-merge-robot committed Jun 7, 2021
2 parents e6b36b2 + 65f8866 commit c8b1456
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
36 changes: 33 additions & 3 deletions pkg/config/node.go
Expand Up @@ -22,7 +22,10 @@ import (
"github.com/openshift/installer/pkg/types"
)

const localhostKubeApiServerUrl string = "https://localhost:6443"
const (
localhostKubeApiServerUrl = "https://localhost:6443"
defaultIngressControllerName = "router-internal-default"
)

var log = logrus.New()

Expand Down Expand Up @@ -63,7 +66,8 @@ type ApiLBConfig struct {
}

type IngressConfig struct {
Peers []string
Peers []string
Priority int
}

type Node struct {
Expand Down Expand Up @@ -218,6 +222,33 @@ func IsUpgradeStillRunning(kubeconfigPath string) (error, bool) {
return nil, false
}

func GetIngressPriority(kubeconfigPath string, nonVirtualIP string) int {
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
if err != nil {
log.Errorf("Failed to retrieve config from kubeconfig: %s , set priority to lower value", err)
return 20
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Errorf("Failed to build client config: %s , set priority to lower value", err)
return 20
}
endpoint, err := clientset.CoreV1().Endpoints("openshift-ingress").Get(defaultIngressControllerName, metav1.GetOptions{})
if err != nil {
log.Errorf("Failed to read %s endpoints: %s , set priority to lower value", defaultIngressControllerName, err)
return 20
}
for _, entry := range endpoint.Subsets {
for _, address := range entry.Addresses {
if address.IP == nonVirtualIP {
return 40
}
}
}
return 20
}

func GetIngressConfig(kubeconfigPath string) (ingressConfig IngressConfig, err error) {
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
if err != nil {
Expand All @@ -228,7 +259,6 @@ func GetIngressConfig(kubeconfigPath string) (ingressConfig IngressConfig, err e
if err != nil {
return ingressConfig, err
}

nodes, err := clientset.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
return ingressConfig, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/monitor/dynkeepalived.go
Expand Up @@ -335,7 +335,6 @@ func KeepalivedWatch(kubeconfigPath, clusterConfigPath, templatePath, cfgPath st
newConfig.EnableUnicast = false
}
updateUnicastConfig(kubeconfigPath, &newConfig, appliedConfig)

log.WithFields(logrus.Fields{
"curConfig": newConfig,
}).Info("Mode Update config change")
Expand Down Expand Up @@ -381,6 +380,7 @@ func KeepalivedWatch(kubeconfigPath, clusterConfigPath, templatePath, cfgPath st
newConfig.EnableUnicast = curEnableUnicast
}
updateUnicastConfig(kubeconfigPath, &newConfig, appliedConfig)
newConfig.IngressConfig.Priority = config.GetIngressPriority(kubeconfigPath, newConfig.NonVirtualIP)
curConfig = &newConfig
if doesConfigChanged(curConfig, appliedConfig) {
if prevConfig == nil || cmp.Equal(*prevConfig, *curConfig) {
Expand Down

0 comments on commit c8b1456

Please sign in to comment.