Skip to content

Commit 2ed6360

Browse files
committed
updated docker configuration to handle manual setup of subnet to use
1 parent a20b6d9 commit 2ed6360

7 files changed

Lines changed: 539 additions & 333 deletions

File tree

cmd/main.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ func main() {
162162
log.G(context.Background()).Fatal(err)
163163
}
164164

165+
// log the interlinkconfig
166+
log.G(context.Background()).Info("\u2705 InterLinkConfig: ", interLinkConfig)
167+
165168
if interLinkConfig.VerboseLogging {
166169
logger.SetLevel(logrus.DebugLevel)
167170
} else if interLinkConfig.ErrorsOnlyLogging {
@@ -177,16 +180,35 @@ func main() {
177180
if availableDinds == "" {
178181
availableDinds = "2"
179182
}
183+
availableDindsInt, err := strconv.ParseInt(availableDinds, 10, 8)
184+
if err != nil {
185+
log.G(ctx).Fatal("Error parsing AVAILABLEDINDS: ", err)
186+
}
187+
188+
// Build the subnet pool from the config (empty slice = no pool).
189+
subnetPool, err := dindmanager.InitSubnetPool(interLinkConfig.DockerNetworkSubnet)
190+
if err != nil {
191+
log.G(ctx).Fatal("Error initialising subnet pool: ", err)
192+
}
193+
if len(subnetPool) > 0 {
194+
log.G(ctx).Info(fmt.Sprintf(
195+
"\u2705 Subnet pool initialised: %d /24 subnets available from %v",
196+
len(subnetPool), interLinkConfig.DockerNetworkSubnet,
197+
))
198+
} else {
199+
log.G(ctx).Info("\u2705 No DockerNetworkSubnet configured — Docker will assign subnets automatically")
200+
}
201+
180202
var dindHandler dindmanager.DindManagerInterface = &dindmanager.DindManager{
181203
DindList: []dindmanager.DindSpecs{},
182204
Ctx: ctx,
183205
FPGAEnabled: interLinkConfig.FPGAEnabled,
184206
XilinxToolsPath: interLinkConfig.XilinxToolsPath,
207+
SubnetPool: subnetPool,
185208
}
186-
availableDindsInt, err := strconv.ParseInt(availableDinds, 10, 8)
187-
if err != nil {
188-
log.G(ctx).Info("\u2705 Error parsing availableDinds")
189-
}
209+
210+
dindHandler.(*dindmanager.DindManager).InitialPoolSz = len(subnetPool)
211+
190212
dindHandler.CleanDindContainers()
191213
dindHandler.BuildDindContainers(int8(availableDindsInt))
192214

pkg/common/types.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,32 @@ type RetrievedContainer struct {
5454

5555
// InterLinkConfig holds the whole configuration
5656
type InterLinkConfig struct {
57-
VKConfigPath string `yaml:"VKConfigPath"`
58-
VKTokenFile string `yaml:"VKTokenFile"`
59-
Interlinkurl string `yaml:"InterlinkURL"`
60-
Sidecarurl string `yaml:"SidecarURL"`
61-
Sbatchpath string `yaml:"SbatchPath"`
62-
Scancelpath string `yaml:"ScancelPath"`
63-
Squeuepath string `yaml:"SqueuePath"`
64-
Interlinkport string `yaml:"InterlinkPort"`
65-
Socket string `yaml:"Socket"`
66-
Sidecarport string `yaml:"SidecarPort"`
67-
Commandprefix string `yaml:"CommandPrefix"`
68-
ExportPodData bool `yaml:"ExportPodData"`
69-
DataRootFolder string `yaml:"DataRootFolder"`
70-
ServiceAccount string `yaml:"ServiceAccount"`
71-
Namespace string `yaml:"Namespace"`
72-
Tsocks bool `yaml:"Tsocks"`
73-
Tsockspath string `yaml:"TsocksPath"`
74-
Tsocksconfig string `yaml:"TsocksConfig"`
75-
Tsockslogin string `yaml:"TsocksLoginNode"`
76-
BashPath string `yaml:"BashPath"`
77-
VerboseLogging bool `yaml:"VerboseLogging"`
78-
ErrorsOnlyLogging bool `yaml:"ErrorsOnlyLogging"`
79-
PodIP string `yaml:"PodIP"`
80-
SingularityPrefix string `yaml:"SingularityPrefix"`
81-
set bool
57+
VKConfigPath string `yaml:"VKConfigPath"`
58+
VKTokenFile string `yaml:"VKTokenFile"`
59+
Interlinkurl string `yaml:"InterlinkURL"`
60+
Sidecarurl string `yaml:"SidecarURL"`
61+
Sbatchpath string `yaml:"SbatchPath"`
62+
Scancelpath string `yaml:"ScancelPath"`
63+
Squeuepath string `yaml:"SqueuePath"`
64+
Interlinkport string `yaml:"InterlinkPort"`
65+
Socket string `yaml:"Socket"`
66+
Sidecarport string `yaml:"SidecarPort"`
67+
Commandprefix string `yaml:"CommandPrefix"`
68+
ExportPodData bool `yaml:"ExportPodData"`
69+
DataRootFolder string `yaml:"DataRootFolder"`
70+
ServiceAccount string `yaml:"ServiceAccount"`
71+
Namespace string `yaml:"Namespace"`
72+
Tsocks bool `yaml:"Tsocks"`
73+
Tsockspath string `yaml:"TsocksPath"`
74+
Tsocksconfig string `yaml:"TsocksConfig"`
75+
Tsockslogin string `yaml:"TsocksLoginNode"`
76+
BashPath string `yaml:"BashPath"`
77+
VerboseLogging bool `yaml:"VerboseLogging"`
78+
ErrorsOnlyLogging bool `yaml:"ErrorsOnlyLogging"`
79+
PodIP string `yaml:"PodIP"`
80+
SingularityPrefix string `yaml:"SingularityPrefix"`
81+
DockerNetworkSubnet []string `yaml:"DockerNetworkSubnet"`
82+
set bool
8283
}
8384

8485
// ContainerLogOpts is a struct in which it is possible to specify options to retrieve logs from the sidecar

pkg/docker/Create.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -554,40 +554,40 @@ cd $TMPDIR
554554
}
555555

556556
// Create DNS configuration script for DIND
557-
dnsConfigScript := `#!/bin/sh
558-
set -e
559-
560-
# Backup original resolv.conf
561-
cp /etc/resolv.conf /etc/resolv.conf.backup 2>/dev/null || true
562-
563-
# Create new resolv.conf with cluster DNS
564-
cat > /etc/resolv.conf << EOF
565-
nameserver 8.8.8.8
566-
search ` + dnsSearch + `
567-
EOF
568-
569-
echo "DNS configured for cluster connectivity"
570-
`
571-
572-
// Write DNS config script to pod directory
573-
dnsScriptPath := filepath.Join(podDirectoryPath, "configure-dns.sh")
574-
err = os.WriteFile(dnsScriptPath, []byte(dnsConfigScript), 0755)
575-
if err != nil {
576-
log.G(h.Ctx).Warning("⚠️ Failed to create DNS config script: " + err.Error())
577-
} else {
578-
// Execute DNS configuration on DIND container
579-
dnsExecCmd := exec.ExecTask{
580-
Command: "docker",
581-
Args: []string{"exec", string(data.Pod.UID) + "_dind", "sh", dnsScriptPath},
582-
Shell: true,
583-
}
584-
_, err = dnsExecCmd.Execute()
585-
if err != nil {
586-
log.G(h.Ctx).Warning("⚠️ Failed to configure DNS on DIND container: " + err.Error())
587-
} else {
588-
log.G(h.Ctx).Info("✅ [POD FLOW] DNS configured on DIND container successfully with NS: " + dnsNameserver + ", Search: " + dnsSearch)
589-
}
590-
}
557+
/* dnsConfigScript := `#!/bin/sh
558+
set -e
559+
560+
# Backup original resolv.conf
561+
cp /etc/resolv.conf /etc/resolv.conf.backup 2>/dev/null || true
562+
563+
# Create new resolv.conf with cluster DNS
564+
cat > /etc/resolv.conf << EOF
565+
nameserver 8.8.8.8
566+
search ` + dnsSearch + `
567+
EOF
568+
569+
echo "DNS configured for cluster connectivity"
570+
`
571+
572+
// Write DNS config script to pod directory
573+
dnsScriptPath := filepath.Join(podDirectoryPath, "configure-dns.sh")
574+
err = os.WriteFile(dnsScriptPath, []byte(dnsConfigScript), 0755)
575+
if err != nil {
576+
log.G(h.Ctx).Warning("⚠️ Failed to create DNS config script: " + err.Error())
577+
} else {
578+
// Execute DNS configuration on DIND container
579+
dnsExecCmd := exec.ExecTask{
580+
Command: "docker",
581+
Args: []string{"exec", string(data.Pod.UID) + "_dind", "sh", dnsScriptPath},
582+
Shell: true,
583+
}
584+
_, err = dnsExecCmd.Execute()
585+
if err != nil {
586+
log.G(h.Ctx).Warning("⚠️ Failed to configure DNS on DIND container: " + err.Error())
587+
} else {
588+
log.G(h.Ctx).Info("✅ [POD FLOW] DNS configured on DIND container successfully with NS: " + dnsNameserver + ", Search: " + dnsSearch)
589+
}
590+
} */
591591
}
592592
}
593593

pkg/docker/Status.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,34 @@ func (h *SidecarHandler) StatusHandler(w http.ResponseWriter, r *http.Request) {
8787

8888
resp = append(resp, commonIL.PodStatus{PodName: pod.Name, PodUID: podUID, PodNamespace: podNamespace, JobID: dindUUID})
8989

90+
disabledInitContainers := make(map[string]bool)
91+
if ann, ok := pod.Annotations["interlink.eu/disable-offload-init-containers"]; ok {
92+
for _, name := range strings.Split(ann, ",") {
93+
name = strings.TrimSpace(name)
94+
if name != "" {
95+
disabledInitContainers[name] = true
96+
}
97+
}
98+
}
99+
90100
// check if the pod has initContainers and get their status
91101
for _, container := range pod.Spec.InitContainers {
102+
103+
if disabledInitContainers[container.Name] {
104+
log.G(h.Ctx).Infof("✅ [STATUS CALL] init container %s is marked as non-offloaded, reporting as Completed", container.Name)
105+
resp[i].InitContainers = append(resp[i].InitContainers, v1.ContainerStatus{
106+
Name: container.Name,
107+
Ready: false,
108+
State: v1.ContainerState{
109+
Terminated: &v1.ContainerStateTerminated{
110+
ExitCode: 0,
111+
Reason: "Completed",
112+
},
113+
},
114+
})
115+
continue
116+
}
117+
92118
containerName := podNamespace + "-" + podUID + "-" + container.Name
93119
cmd := []string{"exec " + podUID + "_dind" + " docker ps -af name=^" + containerName + "$ --format \"{{.Status}}\""}
94120
shell := exec.ExecTask{
@@ -130,8 +156,30 @@ func (h *SidecarHandler) StatusHandler(w http.ResponseWriter, r *http.Request) {
130156
}
131157
}
132158

159+
disabledContainers := make(map[string]bool)
160+
if ann, ok := pod.Annotations["interlink.eu/disable-offload-containers"]; ok {
161+
for _, name := range strings.Split(ann, ",") {
162+
name = strings.TrimSpace(name)
163+
if name != "" {
164+
disabledContainers[name] = true
165+
}
166+
}
167+
}
168+
133169
for _, container := range pod.Spec.Containers {
134170

171+
if disabledContainers[container.Name] {
172+
log.G(h.Ctx).Infof("✅ [STATUS CALL] container %s is marked as non-offloaded, reporting as Running", container.Name)
173+
resp[i].Containers = append(resp[i].Containers, v1.ContainerStatus{
174+
Name: container.Name,
175+
Ready: true,
176+
State: v1.ContainerState{
177+
Running: &v1.ContainerStateRunning{},
178+
},
179+
})
180+
continue
181+
}
182+
135183
containerName := podNamespace + "-" + podUID + "-" + container.Name
136184
cmd := []string{"exec " + podUID + "_dind" + " docker ps -af name=^" + containerName + "$ --format \"{{.Status}}\""}
137185

0 commit comments

Comments
 (0)