Skip to content

Commit

Permalink
Revert "use env var from init container instead of file"
Browse files Browse the repository at this point in the history
This reverts commit 7d4e3b1.
  • Loading branch information
m-terra committed Oct 30, 2024
1 parent 7d4e3b1 commit 2f812d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions controllers/instance/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ then
sleep 5
export BIND_ADDRESS="{{.IP}}"
echo "BIND_ADDRESS=${BIND_ADDRESS}"
echo -n "BIND_ADDRESS={{.IP}}" > {{.File}}
cat {{.File}}
exit 0
fi
Expand All @@ -56,6 +56,7 @@ const (
type initScriptData struct {
Host string
IP string
File string
}

func (r *Reconciler) reconcileStatefulSet(ctx context.Context, instance *proxyv1alpha1.Instance, checksum string) error {
Expand Down Expand Up @@ -218,6 +219,8 @@ func (r *Reconciler) reconcileStatefulSet(ctx context.Context, instance *proxyv1
}

if len(instance.Spec.Network.HostIPs) > 0 {
file := "/var/lib/haproxy/run/env"

var hosts []string
for host := range instance.Spec.Network.HostIPs {
hosts = append(hosts, host)
Expand All @@ -229,6 +232,7 @@ func (r *Reconciler) reconcileStatefulSet(ctx context.Context, instance *proxyv1
data := initScriptData{
Host: host,
IP: instance.Spec.Network.HostIPs[host],
File: file,
}

tmpl, err := template.New("initScript").Parse(initContainerScript)
Expand Down Expand Up @@ -258,6 +262,11 @@ func (r *Reconciler) reconcileStatefulSet(ctx context.Context, instance *proxyv1
},
},
})

statefulset.Spec.Template.Spec.Containers[0].Env = append(statefulset.Spec.Template.Spec.Containers[0].Env, corev1.EnvVar{
Name: "ENV_FILE",
Value: file,
})
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion controllers/instance/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var _ = Describe("Reconcile", Label("controller"), func() {
"then\n i=0\n while [ $(ip a show to '10.158.182.27' | wc -l) -eq 0 ]\n do\n ((i=i+1))\n if [ \"$i\" -gt \"20\" ]\n" +
" then echo 'timeout waiting for IP 10.158.182.27, aborting'\n exit 1\n fi\n echo 'waiting for IP 10.158.182.27 to be assigned...'\n" +
" sleep 5\n done\n\n echo 'IP 10.158.182.27 assignment verified, waiting 5 seconds before continuing...'\n\n" +
" sleep 5\n\n export BIND_ADDRESS=\"10.158.182.27\"\n echo \"BIND_ADDRESS=${BIND_ADDRESS}\"\n exit 0\nfi\n\nexit 1\n"))
" sleep 5\n\n echo -n \"BIND_ADDRESS=10.158.182.27\" > /var/lib/haproxy/run/env\n cat /var/lib/haproxy/run/env\n exit 0\nfi\n\nexit 1\n"))
})
})
})

0 comments on commit 2f812d2

Please sign in to comment.