Skip to content

Commit 49c0c66

Browse files
LBwacher minor fixes (#39)
* fix: lb-watcher: use only pods with same seletors and in the same namespace with service * fix: lb-watcher: patch IP in CR after creating or updating the l4lb in automatic mode * deploy: remove default 'resources' in manifest * Preparation for new release Co-authored-by: Artashes Balabekyan <[email protected]>
1 parent 920acbc commit 49c0c66

File tree

6 files changed

+17
-48
lines changed

6 files changed

+17
-48
lines changed

config/manager/manager.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,4 @@ spec:
3030
image: controller:latest
3131
imagePullPolicy: "Always"
3232
name: manager
33-
resources:
34-
limits:
35-
cpu: 100m
36-
memory: 30Mi
37-
requests:
38-
cpu: 100m
39-
memory: 20Mi
4033
terminationGracePeriodSeconds: 10

controllers/l4lbmeta_controller.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,12 @@ func (u *uniReconciler) updateL4LBIfNeccesarry(l4lbCR *v1alpha1.L4LB, l4lbMeta v
255255
l4lbCR.Spec.Frontend.IP = l4lbMeta.Spec.IP
256256
shouldUpdateCR = true
257257
}
258-
if l4lbCR.Spec.OwnerTenant == "" || l4lbCR.Spec.Site == "" {
258+
if l4lbCR.Spec.OwnerTenant == "" || l4lbCR.Spec.Site == "" || l4lbCR.Spec.Frontend.IP == "" {
259+
_ = u.NStorage.L4LBStorage.Download()
259260
if updatedL4LB, ok := u.NStorage.L4LBStorage.FindByID(l4lbMeta.Spec.ID); ok {
260261
l4lbCR.Spec.OwnerTenant = updatedL4LB.TenantName
261262
l4lbCR.Spec.Site = updatedL4LB.SiteName
262-
if l4lbCR.Spec.Frontend.IP == "" {
263-
l4lbCR.Spec.Frontend.IP = updatedL4LB.IP
264-
}
263+
l4lbCR.Spec.Frontend.IP = updatedL4LB.IP
265264
shouldUpdateCR = true
266265
}
267266
}

deploy/charts/netris-operator/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.3.7
18+
version: 0.3.8
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
23-
appVersion: v0.4.5
23+
appVersion: v0.4.6
2424
home: https://github.com/netrisai/netris-operator
2525
icon: https://www.netris.ai/wp-content/uploads/2020/05/logo-600.png # [todo] Change url to permalink
2626
keywords:

lbwatcher/lb_watcher.go

+7-16
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
k8sv1alpha1 "github.com/netrisai/netris-operator/api/v1alpha1"
3030
"github.com/netrisai/netris-operator/netrisstorage"
3131
"go.uber.org/zap/zapcore"
32-
v1 "k8s.io/api/core/v1"
3332
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3433
"k8s.io/client-go/kubernetes"
3534
"k8s.io/client-go/tools/record"
@@ -417,12 +416,6 @@ func (w *Watcher) generateLoadBalancers(clientset *kubernetes.Clientset, lbTimeo
417416
return lbList, fmt.Errorf("{generateLoadBalancers} %s", err)
418417
}
419418

420-
debugLogger.Info("Getting k8s pods...")
421-
podList, err := getPods(clientset, "")
422-
if err != nil {
423-
return lbList, fmt.Errorf("{generateLoadBalancers} %s", err)
424-
}
425-
426419
timeout, err := strconv.Atoi(lbTimeout)
427420
if err != nil {
428421
return lbList, fmt.Errorf("{generateLoadBalancers} %s", err)
@@ -435,21 +428,19 @@ func (w *Watcher) generateLoadBalancers(clientset *kubernetes.Clientset, lbTimeo
435428

436429
for _, svc := range serviceList.Items {
437430
if svc.Spec.Type == "LoadBalancer" {
438-
selectors := []selector{}
431+
selectors := []string{}
439432
hostIPs := map[string]int{}
440433
for key, value := range svc.Spec.Selector {
441-
selectors = append(selectors, selector{
442-
Key: key,
443-
Value: value,
444-
})
434+
selectors = append(selectors, fmt.Sprintf("%s=%s", key, value))
445435
}
446436

447-
pods := []v1.Pod{}
448-
for _, sel := range selectors {
449-
pods = append(pods, filterPodsBySelector(podList, sel.Key, sel.Value)...)
437+
debugLogger.Info("Getting k8s pods...", "service", svc.Name, "namespace", svc.Namespace)
438+
podList, err := getPodsByLabelSeector(clientset, svc.Namespace, strings.Join(selectors, ","))
439+
if err != nil {
440+
return lbList, fmt.Errorf("{generateLoadBalancers} %s", err)
450441
}
451442

452-
for _, pod := range pods {
443+
for _, pod := range podList.Items {
453444
hostIPs[pod.Status.HostIP] = 1
454445
}
455446

lbwatcher/pods.go

+5-14
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,15 @@ import (
2525
"k8s.io/client-go/kubernetes"
2626
)
2727

28-
func getPods(clientset *kubernetes.Clientset, namespace string) (*v1.PodList, error) {
28+
func getPodsByLabelSeector(clientset *kubernetes.Clientset, namespace, selectors string) (*v1.PodList, error) {
2929
ctx, cancel := context.WithTimeout(cntxt, contextTimeout)
3030
defer cancel()
31-
pods, err := clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{})
31+
listOptions := metav1.ListOptions{
32+
LabelSelector: selectors,
33+
}
34+
pods, err := clientset.CoreV1().Pods(namespace).List(ctx, listOptions)
3235
if err != nil {
3336
return pods, fmt.Errorf("{getPods} %s", err)
3437
}
3538
return pods, nil
3639
}
37-
38-
func filterPodsBySelector(pods *v1.PodList, selectorKey, selectorValue string) []v1.Pod {
39-
filteredPods := []v1.Pod{}
40-
for _, pod := range pods.Items {
41-
for labelKey, labelValue := range pod.Labels {
42-
if labelKey == selectorKey && labelValue == selectorValue {
43-
filteredPods = append(filteredPods, pod)
44-
}
45-
}
46-
}
47-
return filteredPods
48-
}

lbwatcher/types.go

-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ type Watcher struct {
2727
MGR manager.Manager
2828
}
2929

30-
type selector struct {
31-
Key string
32-
Value string
33-
}
34-
3530
type lbIP struct {
3631
Name string
3732
IP string

0 commit comments

Comments
 (0)