Skip to content

Commit

Permalink
Merge pull request #21 from Ygnas/gatewayclass-supportedfeatures-metrics
Browse files Browse the repository at this point in the history
Gatewayclass supportedfeatures metrics
  • Loading branch information
david-martin authored Sep 8, 2023
2 parents 9e8fcab + 78f6059 commit adb654f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ spec:
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
- jsonPath: .status.supportedFeatures
name: SupportedFeatures
type: string
- jsonPath: .spec.description
name: Description
priority: 1
Expand Down Expand Up @@ -418,6 +421,11 @@ spec:
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
supportedFeatures:
items:
type: string
maxItems: 64
type: array
type: object
required:
- spec
Expand Down
8 changes: 8 additions & 0 deletions custom-resource-state.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ spec:
labelsFromPath:
type: ["type"]
valueFrom: ["status"]
- name: "status_supported_features"
help: "List of supported features for the GatewayClass"
each:
type: Info
info:
path: [status, supportedFeatures]
labelsFromPath:
features: []
- groupVersionKind:
group: gateway.networking.k8s.io
kind: "HTTPRoute"
Expand Down
5 changes: 5 additions & 0 deletions examples/enterprise/all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ status:
reason: Accepted
status: "True"
type: Accepted
supportedFeatures:
- HTTPRoute
- HTTPRouteHostRewrite
- HTTPRoutePortRedirect
- HTTPRouteQueryParamMatching
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
Expand Down
23 changes: 23 additions & 0 deletions tests/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@ func testGatewayClasses(t *testing.T, metrics map[string][][]string) {
expectEqual(t, gatewayClass1Status1Labels["customresource_version"], "v1beta1", "gatewayapi_gatewayclass_status__1 customresource_version")
expectEqual(t, gatewayClass1Status1Labels["name"], "testgatewayclass1", "gatewayapi_gatewayclass_status__1 name")
expectEqual(t, gatewayClass1Status1Labels["type"], "Accepted", "gatewayapi_gatewayclass_status__1 type")

//gatewayapi_gatewayclass_status_supported_features
gatewayClassStatusSupportedFeatures := metrics["gatewayapi_gatewayclass_status_supported_features"]
gatewayClass1StatusSupportedFeatures1 := gatewayClassStatusSupportedFeatures[0]
expectEqual(t, gatewayClass1StatusSupportedFeatures1[3], "1", "gatewayapi_gatewayclass_status_supported_features__1 value")
gatewayClass1StatusSupportedFeatures1Labels := parseLabels(string(gatewayClass1StatusSupportedFeatures1[2]))
expectEqual(t, gatewayClass1StatusSupportedFeatures1Labels["customresource_group"], "gateway.networking.k8s.io", "gatewayapi_gatewayclass_status_supported_features__1 customresource_group")
expectEqual(t, gatewayClass1StatusSupportedFeatures1Labels["customresource_kind"], "GatewayClass", "gatewayapi_gatewayclass_status_supported_features__1 customresource_kind")
expectEqual(t, gatewayClass1StatusSupportedFeatures1Labels["customresource_version"], "v1beta1", "gatewayapi_gatewayclass_status_supported_features__1 customresource_version")
expectEqual(t, gatewayClass1StatusSupportedFeatures1Labels["name"], "testgatewayclass1", "gatewayapi_gatewayclass_status_supported_features__1 name")

expectedFeatures := map[int]string{
0: "HTTPRoute",
1: "HTTPRouteHostRewrite",
2: "HTTPRoutePortRedirect",
3: "HTTPRouteQueryParamMatching",
}

for i, feature := range gatewayClassStatusSupportedFeatures {
featureInfo := parseLabels(string(feature[0]))
featureName := featureInfo["features"]
expectEqual(t, featureName, expectedFeatures[i], "gatewayapi_gatewayclass_status_supported_features__"+strconv.Itoa(i)+" features")
}
}

func testGateways(t *testing.T, metrics map[string][][]string) {
Expand Down
7 changes: 6 additions & 1 deletion tests/manifests/testgatewayclass1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ status:
observedGeneration: 1
reason: Accepted
status: "True"
type: Accepted
type: Accepted
supportedFeatures:
- HTTPRoute
- HTTPRouteHostRewrite
- HTTPRoutePortRedirect
- HTTPRouteQueryParamMatching

0 comments on commit adb654f

Please sign in to comment.