Skip to content

Commit 1c581eb

Browse files
committed
feat: add supported features to gateway class
Signed-off-by: Kobi Levi <[email protected]>
1 parent 914b48c commit 1c581eb

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

internal/cmd/egctl/translate.go

+2
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,13 @@ func translateGatewayAPIToGatewayAPI(resources *gatewayapi.Resources) (gatewayap
274274
epInvalid = true
275275
msg := fmt.Sprintf("%s: %v", status.MsgGatewayClassInvalidParams, err)
276276
status.SetGatewayClassAccepted(resources.GatewayClass, false, string(gwapiv1.GatewayClassReasonInvalidParameters), msg)
277+
status.SetGatewayClassSupportedFeatures(resources.GatewayClass)
277278
}
278279
gRes.EnvoyProxy = resources.EnvoyProxy
279280
}
280281
if !epInvalid {
281282
status.SetGatewayClassAccepted(resources.GatewayClass, true, string(gwapiv1.GatewayClassReasonAccepted), status.MsgValidGatewayClass)
283+
status.SetGatewayClassSupportedFeatures(resources.GatewayClass)
282284
}
283285

284286
gRes.GatewayClass = resources.GatewayClass

internal/provider/kubernetes/controller.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,14 @@ func (r *gatewayAPIReconciler) gatewayClassUpdater(ctx context.Context, gc *gwap
501501
panic(fmt.Sprintf("unsupported object type %T", obj))
502502
}
503503

504-
return status.SetGatewayClassAccepted(gc.DeepCopy(), accepted, reason, msg)
504+
gc = status.SetGatewayClassAccepted(gc.DeepCopy(), accepted, reason, msg)
505+
return status.SetGatewayClassSupportedFeatures(gc.DeepCopy())
505506
}),
506507
})
507508
} else {
508509
// this branch makes testing easier by not going through the status.Updater.
509510
duplicate := status.SetGatewayClassAccepted(gc.DeepCopy(), accepted, reason, msg)
511+
duplicate = status.SetGatewayClassSupportedFeatures(duplicate.DeepCopy())
510512

511513
if err := r.client.Status().Update(ctx, duplicate); err != nil && !kerrors.IsNotFound(err) {
512514
return fmt.Errorf("error updating status of gatewayclass %s: %w", duplicate.Name, err)

internal/provider/kubernetes/controller_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/envoyproxy/gateway/internal/envoygateway/config"
2222
"github.com/envoyproxy/gateway/internal/gatewayapi"
2323
"github.com/envoyproxy/gateway/internal/logging"
24+
"github.com/envoyproxy/gateway/internal/status"
2425
)
2526

2627
func TestAddGatewayClassFinalizer(t *testing.T) {
@@ -189,6 +190,7 @@ func TestHasManagedClass(t *testing.T) {
189190
Status: metav1.ConditionTrue,
190191
},
191192
},
193+
SupportedFeatures: status.GetSupportedFeatures(),
192194
},
193195
},
194196
},
@@ -223,6 +225,7 @@ func TestHasManagedClass(t *testing.T) {
223225
Status: metav1.ConditionTrue,
224226
},
225227
},
228+
SupportedFeatures: status.GetSupportedFeatures(),
226229
},
227230
},
228231
},
@@ -275,6 +278,7 @@ func TestHasManagedClass(t *testing.T) {
275278
Status: metav1.ConditionTrue,
276279
},
277280
},
281+
SupportedFeatures: status.GetSupportedFeatures(),
278282
},
279283
},
280284
{
@@ -297,6 +301,7 @@ func TestHasManagedClass(t *testing.T) {
297301
Status: metav1.ConditionFalse,
298302
},
299303
},
304+
SupportedFeatures: status.GetSupportedFeatures(),
300305
},
301306
},
302307
},

internal/status/gatewayclass.go

+24
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
package status
1515

1616
import (
17+
"k8s.io/apimachinery/pkg/util/sets"
1718
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
19+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
1820
)
1921

2022
// SetGatewayClassAccepted inserts or updates the Accepted condition
@@ -23,3 +25,25 @@ func SetGatewayClassAccepted(gc *gwapiv1.GatewayClass, accepted bool, reason, ms
2325
gc.Status.Conditions = MergeConditions(gc.Status.Conditions, computeGatewayClassAcceptedCondition(gc, accepted, reason, msg))
2426
return gc
2527
}
28+
29+
// GetSupportedFeatures returns a list of supported Gateway-API features,
30+
// based on the running conformance tests suite.
31+
func GetSupportedFeatures() []gwapiv1.SupportedFeature {
32+
33+
// TODO(levikobi): This must be in sync with the cSuite supported features.
34+
supportedFeatures := suite.AllFeatures
35+
supportedFeatures.Delete(suite.MeshCoreFeatures.UnsortedList()...)
36+
37+
ret := sets.New[gwapiv1.SupportedFeature]()
38+
for _, feature := range supportedFeatures.UnsortedList() {
39+
ret.Insert(gwapiv1.SupportedFeature(feature))
40+
}
41+
return sets.List(ret)
42+
}
43+
44+
// SetGatewayClassSupportedFeatures insert or updates the SupportedFeatures field
45+
// for the provided GatewayClass.
46+
func SetGatewayClassSupportedFeatures(gc *gwapiv1.GatewayClass) *gwapiv1.GatewayClass {
47+
gc.Status.SupportedFeatures = GetSupportedFeatures()
48+
return gc
49+
}

0 commit comments

Comments
 (0)