Skip to content

Commit 35c0143

Browse files
committed
desiredIstio: Enable GIE if InferencePool found
Configure the Istio control-plane to enable Gateway API Inference Extension (GIE) if the InferencePool CRD from GIE exists on the cluster. Conditionally set one new environment variable in the Istio CR: ENABLE_GATEWAY_API_INFERENCE_EXTENSION This commit resolves NE-2104. https://issues.redhat.com/browse/NE-2104 * pkg/operator/controller/gatewayclass/controller.go (inferencepoolCrdName, inferencepoolExperimentalCrdName): New consts. (NewUnmanaged): Watch customresourcedefinitions, with a predicate on the InferencePool CRD, in order to reconcile the Istio CR when the InferencePool CRD is created or deleted. * pkg/operator/controller/gatewayclass/istio.go (ensureIstio): Use the new inferencepoolCrdExists helper to check whether the InferencePool CRD exists, and pass a flag to desiredIstio when the CRD is present. (inferencepoolCrdExists): New helper. Using the new crdExists helper, check whether the InferencePool CRD exists in the inference.networking.k8s.io or inference.networking.x-k8s.io API groups. (crdExists): New helper. (desiredIstio): Add a Boolean parameter, and set the environment variable when the argument is true.
1 parent 4f1ed7f commit 35c0143

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

pkg/operator/controller/gatewayclass/controller.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
1717

18+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920
"k8s.io/apimachinery/pkg/types"
2021
utilerrors "k8s.io/apimachinery/pkg/util/errors"
@@ -31,6 +32,13 @@ import (
3132

3233
const (
3334
controllerName = "gatewayclass_controller"
35+
36+
// inferencepoolCrdName is the name of the InferencePool CRD from
37+
// Gateway API Inference Extension.
38+
inferencepoolCrdName = "inferencepools.inference.networking.k8s.io"
39+
// inferencepoolExperimentalCrdName is the name of the experimental
40+
// (alpha version) InferencePool CRD.
41+
inferencepoolExperimentalCrdName = "inferencepools.inference.networking.x-k8s.io"
3442
)
3543

3644
var log = logf.Logger.WithName(controllerName)
@@ -92,6 +100,20 @@ func NewUnmanaged(mgr manager.Manager, config Config) (controller.Controller, er
92100
return nil, err
93101
}
94102

103+
// Watch for the InferencePool CRD to determine whether to enable
104+
// Gateway API Inference Extension (GIE) on the Istio control-plane.
105+
isInferencepoolCrd := predicate.NewPredicateFuncs(func(o client.Object) bool {
106+
switch o.GetName() {
107+
case inferencepoolCrdName, inferencepoolExperimentalCrdName:
108+
return true
109+
default:
110+
return false
111+
}
112+
})
113+
if err := c.Watch(source.Kind[client.Object](operatorCache, &apiextensionsv1.CustomResourceDefinition{}, reconciler.enqueueRequestForSomeGatewayClass(), isInferencepoolCrd)); err != nil {
114+
return nil, err
115+
}
116+
95117
gatewayClassController = c
96118
return c, nil
97119
}

pkg/operator/controller/gatewayclass/istio.go

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/openshift/cluster-ingress-operator/pkg/operator/controller"
1414

15+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1516
"k8s.io/apimachinery/pkg/api/errors"
1617
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1718
"k8s.io/apimachinery/pkg/types"
@@ -38,7 +39,13 @@ func (r *reconciler) ensureIstio(ctx context.Context, gatewayclass *gatewayapiv1
3839
Name: gatewayclass.Name,
3940
UID: gatewayclass.UID,
4041
}
41-
desired := desiredIstio(name, ownerRef)
42+
43+
enableInferenceExtension, err := r.inferencepoolCrdExists(ctx)
44+
if err != nil {
45+
return have, current, err
46+
}
47+
48+
desired := desiredIstio(name, ownerRef, enableInferenceExtension)
4249

4350
switch {
4451
case !have:
@@ -56,8 +63,40 @@ func (r *reconciler) ensureIstio(ctx context.Context, gatewayclass *gatewayapiv1
5663
return true, current, nil
5764
}
5865

66+
// inferencepoolCrdExists returns a Boolean value indicating whether the
67+
// InferencePool CRD exists under the inference.networking.k8s.io or
68+
// inference.networking.x-k8s.io API group.
69+
func (r *reconciler) inferencepoolCrdExists(ctx context.Context) (bool, error) {
70+
if v, err := r.crdExists(ctx, inferencepoolCrdName); err != nil {
71+
return false, err
72+
} else if v {
73+
return true, nil
74+
}
75+
76+
if v, err := r.crdExists(ctx, inferencepoolExperimentalCrdName); err != nil {
77+
return false, err
78+
} else if v {
79+
return true, nil
80+
}
81+
82+
return false, nil
83+
}
84+
85+
// crdExists returns a Boolean value indicating whether the named CRD exists.
86+
func (r *reconciler) crdExists(ctx context.Context, crdName string) (bool, error) {
87+
namespacedName := types.NamespacedName{Name: crdName}
88+
var crd apiextensionsv1.CustomResourceDefinition
89+
if err := r.cache.Get(ctx, namespacedName, &crd); err != nil {
90+
if errors.IsNotFound(err) {
91+
return false, nil
92+
}
93+
return false, fmt.Errorf("failed to get CRD %s: %w", crdName, err)
94+
}
95+
return true, nil
96+
}
97+
5998
// desiredIstio returns the desired Istio CR.
60-
func desiredIstio(name types.NamespacedName, ownerRef metav1.OwnerReference) *sailv1.Istio {
99+
func desiredIstio(name types.NamespacedName, ownerRef metav1.OwnerReference, enableInferenceExtension bool) *sailv1.Istio {
61100
pilotContainerEnv := map[string]string{
62101
// Enable Gateway API.
63102
"PILOT_ENABLE_GATEWAY_API": "true",
@@ -106,6 +145,9 @@ func desiredIstio(name types.NamespacedName, ownerRef metav1.OwnerReference) *sa
106145
// service annotations.
107146
"PILOT_ENABLE_GATEWAY_API_COPY_LABELS_ANNOTATIONS": "false",
108147
}
148+
if enableInferenceExtension {
149+
pilotContainerEnv["ENABLE_GATEWAY_API_INFERENCE_EXTENSION"] = "true"
150+
}
109151
return &sailv1.Istio{
110152
ObjectMeta: metav1.ObjectMeta{
111153
Namespace: name.Namespace,

0 commit comments

Comments
 (0)