Skip to content

Commit 249b784

Browse files
committed
feat: support gatewayAPI
1 parent 0679ab3 commit 249b784

File tree

16 files changed

+14107
-21
lines changed

16 files changed

+14107
-21
lines changed

api/v1beta1/grafana_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
OperatorStageServiceAccount OperatorStageName = "service account"
4343
OperatorStageService OperatorStageName = "service"
4444
OperatorStageIngress OperatorStageName = "ingress"
45+
OperatorStageHTTPRoute OperatorStageName = "http route"
4546
OperatorStagePlugins OperatorStageName = "plugins"
4647
OperatorStageDeployment OperatorStageName = "deployment"
4748
OperatorStageComplete OperatorStageName = "complete"
@@ -71,6 +72,8 @@ type GrafanaSpec struct {
7172
Ingress *IngressNetworkingV1 `json:"ingress,omitempty"`
7273
// Route sets how the ingress object should look like with your grafana instance, this only works in Openshift.
7374
Route *RouteOpenshiftV1 `json:"route,omitempty"`
75+
// HTTPRoute sets how the ingress object should look like with your grafana instance, this only works use gateway api.
76+
HTTPRoute *HTTPRouteV1 `json:"httpRoute,omitempty"`
7477
// Service sets how the service object should look like with your grafana instance, contains a number of defaults.
7578
Service *ServiceV1 `json:"service,omitempty"`
7679
// Version sets the tag of the default image: docker.io/grafana/grafana.

api/v1beta1/typeoverrides.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
networkingv1 "k8s.io/api/networking/v1"
1414
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1515
"k8s.io/apimachinery/pkg/util/strategicpatch"
16+
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
1617
)
1718

1819
// +kubebuilder:object:generate=true
@@ -327,6 +328,13 @@ type RouteOpenshiftV1 struct {
327328
Spec *RouteOpenShiftV1Spec `json:"spec,omitempty"`
328329
}
329330

331+
// +kubebuilder:object:generate=true
332+
333+
type HTTPRouteV1 struct {
334+
ObjectMeta ObjectMeta `json:"metadata,omitempty"`
335+
Spec gwapiv1.HTTPRouteSpec `json:"spec,omitempty"`
336+
}
337+
330338
// RouteTargetReference specifies the target that resolve into endpoints. Only the 'Service'
331339
// kind is allowed. Use 'weight' field to emphasize one over others.
332340
type RouteTargetReference struct {

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/grafana.integreatly.org_grafanas.yaml

Lines changed: 3139 additions & 0 deletions
Large diffs are not rendered by default.

config/rbac/role.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ rules:
5454
- patch
5555
- update
5656
- watch
57+
- apiGroups:
58+
- gateway.networking.k8s.io
59+
resources:
60+
- gateways
61+
verbs:
62+
- get
63+
- list
64+
- watch
65+
- apiGroups:
66+
- gateway.networking.k8s.io
67+
resources:
68+
- httproutes
69+
verbs:
70+
- create
71+
- delete
72+
- get
73+
- list
74+
- patch
75+
- update
76+
- watch
5777
- apiGroups:
5878
- grafana.integreatly.org
5979
resources:

controllers/grafana_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ type GrafanaReconciler struct {
6363
// +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;patch
6464
// +kubebuilder:rbac:groups="",resources=configmaps;secrets;serviceaccounts;services;persistentvolumeclaims,verbs=get;list;watch;create;update;patch;delete
6565
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;create;update;patch;delete
66+
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=httproutes,verbs=get;list;watch;create;update;patch;delete
67+
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gateways,verbs=get;list;watch;
6668

6769
func (r *GrafanaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
6870
log := logf.FromContext(ctx).WithName("GrafanaReconciler")
@@ -349,6 +351,7 @@ func getInstallationStages() []grafanav1beta1.OperatorStageName {
349351
grafanav1beta1.OperatorStageServiceAccount,
350352
grafanav1beta1.OperatorStageService,
351353
grafanav1beta1.OperatorStageIngress,
354+
grafanav1beta1.OperatorStageHTTPRoute,
352355
grafanav1beta1.OperatorStagePlugins,
353356
grafanav1beta1.OperatorStageDeployment,
354357
grafanav1beta1.OperatorStageComplete,
@@ -365,6 +368,8 @@ func (r *GrafanaReconciler) getReconcilerForStage(stage grafanav1beta1.OperatorS
365368
return grafana.NewPvcReconciler(r.Client)
366369
case grafanav1beta1.OperatorStageServiceAccount:
367370
return grafana.NewServiceAccountReconciler(r.Client)
371+
case grafanav1beta1.OperatorStageHTTPRoute:
372+
return grafana.NewHTTPRouteReconciler(r.Client)
368373
case grafanav1beta1.OperatorStageService:
369374
return grafana.NewServiceReconciler(r.Client, r.ClusterDomain)
370375
case grafanav1beta1.OperatorStageIngress:

controllers/model/grafana_resources.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
"k8s.io/apimachinery/pkg/runtime"
1313
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
14+
v2 "sigs.k8s.io/gateway-api/apis/v1"
1415
)
1516

1617
func GetCommonLabels() map[string]string {
@@ -114,6 +115,19 @@ func GetGrafanaIngress(cr *grafanav1beta1.Grafana, scheme *runtime.Scheme) *v12.
114115
return ingress
115116
}
116117

118+
func GetGrafanaHTTPRoute(cr *grafanav1beta1.Grafana, scheme *runtime.Scheme) *v2.HTTPRoute {
119+
httpRoute := &v2.HTTPRoute{
120+
ObjectMeta: metav1.ObjectMeta{
121+
Name: fmt.Sprintf("%s-httproute", cr.Name),
122+
Namespace: cr.Namespace,
123+
Labels: GetCommonLabels(),
124+
},
125+
}
126+
controllerutil.SetControllerReference(cr, httpRoute, scheme) //nolint:errcheck
127+
128+
return httpRoute
129+
}
130+
117131
func GetGrafanaRoute(cr *grafanav1beta1.Grafana, scheme *runtime.Scheme) *routev1.Route {
118132
route := &routev1.Route{
119133
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)