@@ -22,6 +22,7 @@ import (
2222 "net"
2323 "strings"
2424
25+ topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2526 "github.com/openstack-k8s-operators/lib-common/modules/common/service"
2627 "github.com/openstack-k8s-operators/lib-common/modules/common/util"
2728 apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -33,7 +34,6 @@ import (
3334 logf "sigs.k8s.io/controller-runtime/pkg/log"
3435 "sigs.k8s.io/controller-runtime/pkg/webhook"
3536 "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
36- topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
3737)
3838
3939// log is for logging in this package.
@@ -656,3 +656,55 @@ func (spec *IronicSpec) ValidateIronicTopology(basePath *field.Path, namespace s
656656 }
657657 return allErrs
658658}
659+
660+ // SetDefaultRouteAnnotations sets HAProxy timeout values of the route
661+ func (spec * IronicAPISpec ) SetDefaultRouteAnnotations (annotations map [string ]string ) {
662+ const haProxyAnno = "haproxy.router.openshift.io/timeout"
663+ // Use a custom annotation to flag when the operator has set the default HAProxy timeout
664+ // The annotation func determines when to overwrite existing HAProxy timeout with the APITimeout
665+ const ironicAnno = "api.ironic.openstack.org/timeout"
666+
667+ valIronic , okIronic := annotations [ironicAnno ]
668+ valHAProxy , okHAProxy := annotations [haProxyAnno ]
669+
670+ // Human operator sets the HAProxy timeout manually
671+ if ! okIronic && okHAProxy {
672+ return
673+ }
674+
675+ // Human operator modified the HAProxy timeout manually without removing the Ironic flag
676+ if okIronic && okHAProxy && valIronic != valHAProxy {
677+ delete (annotations , ironicAnno )
678+ return
679+ }
680+
681+ timeout := fmt .Sprintf ("%ds" , spec .APITimeout )
682+ annotations [ironicAnno ] = timeout
683+ annotations [haProxyAnno ] = timeout
684+ }
685+
686+ // SetDefaultRouteAnnotations sets HAProxy timeout values of the route
687+ func (spec * IronicInspectorSpec ) SetDefaultRouteAnnotations (annotations map [string ]string ) {
688+ const haProxyAnno = "haproxy.router.openshift.io/timeout"
689+ // Use a custom annotation to flag when the operator has set the default HAProxy timeout
690+ // The annotation func determines when to overwrite existing HAProxy timeout with the APITimeout
691+ const ironicInspectorAnno = "inspector.ironic.openstack.org/timeout"
692+
693+ valIronic , okIronic := annotations [ironicInspectorAnno ]
694+ valHAProxy , okHAProxy := annotations [haProxyAnno ]
695+
696+ // Human operator sets the HAProxy timeout manually
697+ if ! okIronic && okHAProxy {
698+ return
699+ }
700+
701+ // Human operator modified the HAProxy timeout manually without removing the Ironic flag
702+ if okIronic && okHAProxy && valIronic != valHAProxy {
703+ delete (annotations , ironicInspectorAnno )
704+ return
705+ }
706+
707+ timeout := fmt .Sprintf ("%ds" , spec .APITimeout )
708+ annotations [ironicInspectorAnno ] = timeout
709+ annotations [haProxyAnno ] = timeout
710+ }
0 commit comments