Skip to content

Commit 19c665e

Browse files
committed
use podIP if service name is empty
1 parent 1c4ecba commit 19c665e

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

pkg/config/types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ type Config struct {
2222
StartupDelay time.Duration `json:"startupDelay"`
2323
Metrics Metrics `json:"metrics"`
2424
// LatestMetricsLabel if true, each result metric is also created with executionID=latest
25-
LatestMetricsLabel bool `json:"latestMetricsLabel"`
26-
Custom map[string]interface{} `json:"custom"`
27-
CallbackServiceName string `json:"callbackServiceName"`
28-
CallbackServicePort int `json:"callbackServicePort"`
29-
UsePodIPForCallback bool `json:"usePodIPForCallback"`
25+
LatestMetricsLabel bool `json:"latestMetricsLabel"`
26+
Custom map[string]interface{} `json:"custom"`
27+
// CallbackServiceName if left blank, the pod IP is used for callback
28+
CallbackServiceName string `json:"callbackServiceName"`
29+
CallbackServicePort int `json:"callbackServicePort"`
3030
// LeaderElectionResourceLock resource lock type. if empty default (resourcelock.ConfigMapsLeasesResourceLock) is used
3131
LeaderElectionResourceLock string `json:"leaderElectionResourceLock,omitempty"`
3232

pkg/cron/cron.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cron
33
import (
44
"context"
55
"os"
6+
"strings"
67
"time"
78

89
"github.com/bakito/batch-job-controller/pkg/config"
@@ -122,7 +123,7 @@ func (j *cronJob) startPods() {
122123
}
123124

124125
var callbackAddress string
125-
if j.cfg.UsePodIPForCallback {
126+
if len(strings.TrimSpace(j.cfg.CallbackServiceName)) == 0 {
126127
// get my pod
127128
p := &corev1.Pod{}
128129
name := os.Getenv("HOSTNAME")

pkg/cron/cron_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ var _ = Describe("Cron", func() {
7272
mockController.EXPECT().AllAdded(gm.Any())
7373
mockController.EXPECT().AddPod(gm.Any())
7474
mockClient.EXPECT().DeleteAllOf(gm.Any(), gm.Any(), gm.Any(), gm.Any(), gm.Any())
75-
mockClient.EXPECT().Get(gm.Any(), gm.Any(), gm.AssignableToTypeOf(&corev1.Service{}))
7675
mockClient.EXPECT().List(gm.Any(), gm.AssignableToTypeOf(&corev1.NodeList{}), client.MatchingLabels(nodeSelector)).
7776
Do(func(ctx context.Context, list *corev1.NodeList, opts ...client.ListOption) error {
7877
list.Items = []corev1.Node{
@@ -93,7 +92,16 @@ var _ = Describe("Cron", func() {
9392
return nil
9493
})
9594
})
96-
It("should start all pods", func() {
95+
It("should start all pods with service IP for callback", func() {
96+
cj.cfg.CallbackServiceName = "any-service-name"
97+
mockClient.EXPECT().Get(gm.Any(), gm.Any(), gm.AssignableToTypeOf(&corev1.Service{}))
98+
mockLog.EXPECT().WithValues("id", id).Return(mockLog)
99+
mockLog.EXPECT().Info("executing job")
100+
cj.startPods()
101+
})
102+
It("should start all pods with pod IP for callback", func() {
103+
cj.cfg.CallbackServiceName = " "
104+
mockClient.EXPECT().Get(gm.Any(), gm.Any(), gm.AssignableToTypeOf(&corev1.Pod{}))
97105
mockLog.EXPECT().WithValues("id", id).Return(mockLog)
98106
mockLog.EXPECT().Info("executing job")
99107
cj.startPods()

0 commit comments

Comments
 (0)