Skip to content

Commit

Permalink
fixed v1beta1 k8sgatewayapi version
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryce-huang committed Sep 22, 2023
1 parent 0119fd3 commit 8882e05
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 66 deletions.
82 changes: 69 additions & 13 deletions apis/core/v1beta1/function_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ package v1beta1
import (
componentsv1alpha1 "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
"gopkg.in/yaml.v3"
"k8s.io/apimachinery/pkg/util/json"
"sigs.k8s.io/controller-runtime/pkg/conversion"
k8sgatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
k8sgatewayapiv1beata1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/openfunction/apis/core/v1beta2"
)
Expand Down Expand Up @@ -89,11 +92,24 @@ func (src *Function) ConvertTo(dstRaw conversion.Hub) error {
Value: item.Value,
})
}
var hosts []k8sgatewayapiv1beata1.Hostname
for _, host := range src.Status.Route.Hosts {
hosts = append(hosts, k8sgatewayapiv1beata1.Hostname(host))
}
var paths []k8sgatewayapiv1beata1.HTTPPathMatch

for _, path := range src.Status.Route.Paths {
pType := k8sgatewayapiv1beata1.PathMatchType(*path.Type)
paths = append(paths, k8sgatewayapiv1beata1.HTTPPathMatch{
Type: &pType,
Value: path.Value,
})
}

if src.Status.Route != nil {
dst.Status.Route = &v1beta2.RouteStatus{
Hosts: src.Status.Route.Hosts,
Paths: src.Status.Route.Paths,
Hosts: hosts,
Paths: paths,
Conditions: src.Status.Route.Conditions,
}
}
Expand Down Expand Up @@ -166,16 +182,30 @@ func convertRouteTo(route *RouteImpl) *v1beta2.RouteImpl {
if route == nil {
return nil
}
var hosts []k8sgatewayapiv1beata1.Hostname
for _, host := range route.Hostnames {
hosts = append(hosts, k8sgatewayapiv1beata1.Hostname(host))
}

rulesBytes, err := json.Marshal(route.Rules)
if err != nil {
return nil
}
var rules []k8sgatewayapiv1beata1.HTTPRouteRule
err = json.Unmarshal(rulesBytes, &rules)
if err != nil {
return nil
}
nr := &v1beta2.RouteImpl{
Hostnames: route.Hostnames,
Rules: route.Rules,
Hostnames: hosts,
Rules: rules,
}
ns := k8sgatewayapiv1beata1.Namespace(*route.GatewayRef.Namespace)
if route.CommonRouteSpec.GatewayRef != nil {
nr.CommonRouteSpec = v1beta2.CommonRouteSpec{
GatewayRef: &v1beta2.GatewayRef{
Name: route.GatewayRef.Name,
Namespace: route.GatewayRef.Namespace,
Name: k8sgatewayapiv1beata1.ObjectName(route.GatewayRef.Name),
Namespace: &ns,
},
}
}
Expand Down Expand Up @@ -439,11 +469,24 @@ func (dst *Function) ConvertFrom(srcRaw conversion.Hub) error {
Value: item.Value,
})
}
var hosts []k8sgatewayapiv1alpha2.Hostname
for _, host := range src.Status.Route.Hosts {
hosts = append(hosts, k8sgatewayapiv1alpha2.Hostname(host))
}
var paths []k8sgatewayapiv1alpha2.HTTPPathMatch

for _, path := range src.Status.Route.Paths {
pType := k8sgatewayapiv1alpha2.PathMatchType(*path.Type)
paths = append(paths, k8sgatewayapiv1alpha2.HTTPPathMatch{
Type: &pType,
Value: path.Value,
})
}

if src.Status.Route != nil {
dst.Status.Route = &RouteStatus{
Hosts: src.Status.Route.Hosts,
Paths: src.Status.Route.Paths,
Hosts: hosts,
Paths: paths,
Conditions: src.Status.Route.Conditions,
}
}
Expand Down Expand Up @@ -639,16 +682,29 @@ func convertRouteFrom(route *v1beta2.RouteImpl) *RouteImpl {
if route == nil {
return nil
}

var hosts []k8sgatewayapiv1alpha2.Hostname
for _, host := range route.Hostnames {
hosts = append(hosts, k8sgatewayapiv1alpha2.Hostname(host))
}
rulesBytes, err := json.Marshal(route.Rules)
if err != nil {
return nil
}
var rules []k8sgatewayapiv1alpha2.HTTPRouteRule
err = json.Unmarshal(rulesBytes, &rules)
if err != nil {
return nil
}
nr := &RouteImpl{
Hostnames: route.Hostnames,
Rules: route.Rules,
Hostnames: hosts,
Rules: rules,
}
ns := k8sgatewayapiv1alpha2.Namespace(*route.GatewayRef.Namespace)
if route.CommonRouteSpec.GatewayRef != nil {
nr.CommonRouteSpec = CommonRouteSpec{
GatewayRef: &GatewayRef{
Name: route.GatewayRef.Name,
Namespace: route.GatewayRef.Namespace,
Name: k8sgatewayapiv1alpha2.ObjectName(route.GatewayRef.Name),
Namespace: &ns,
},
}
}
Expand Down
14 changes: 7 additions & 7 deletions apis/core/v1beta1/function_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
componentsv1alpha1 "github.com/dapr/dapr/pkg/apis/components/v1alpha1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sgatewayapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
k8sgatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down Expand Up @@ -99,10 +99,10 @@ type ShipwrightEngine struct {
type GatewayRef struct {
// Name is the name of the referent.
// It refers to the name of a Gateway resource.
Name k8sgatewayapiv1beta1.ObjectName `json:"name"`
Name k8sgatewayapiv1alpha2.ObjectName `json:"name"`
// Namespace is the namespace of the referent. When unspecified,
// this refers to the local namespace of the Route.
Namespace *k8sgatewayapiv1beta1.Namespace `json:"namespace"`
Namespace *k8sgatewayapiv1alpha2.Namespace `json:"namespace"`
}

// CommonRouteSpec defines the common attributes that all Routes MUST include
Expand All @@ -122,12 +122,12 @@ type RouteImpl struct {
//
// +optional
// +kubebuilder:validation:MaxItems=16
Hostnames []k8sgatewayapiv1beta1.Hostname `json:"hostnames,omitempty"`
Hostnames []k8sgatewayapiv1alpha2.Hostname `json:"hostnames,omitempty"`
// Rules are a list of HTTP matchers, filters and actions.
//
// +optional
// +kubebuilder:validation:MaxItems=16
Rules []k8sgatewayapiv1beta1.HTTPRouteRule `json:"rules,omitempty"`
Rules []k8sgatewayapiv1alpha2.HTTPRouteRule `json:"rules,omitempty"`
}

type BuildImpl struct {
Expand Down Expand Up @@ -273,12 +273,12 @@ type RouteStatus struct {
//
// +optional
// +kubebuilder:validation:MaxItems=16
Hosts []k8sgatewayapiv1beta1.Hostname `json:"hosts,omitempty"`
Hosts []k8sgatewayapiv1alpha2.Hostname `json:"hosts,omitempty"`
// Paths list all actual paths of HTTPRoute.
//
// +optional
// +kubebuilder:validation:MaxItems=16
Paths []k8sgatewayapiv1beta1.HTTPPathMatch `json:"paths,omitempty"`
Paths []k8sgatewayapiv1alpha2.HTTPPathMatch `json:"paths,omitempty"`
// Conditions describes the status of the route with respect to the Gateway.
// Note that the route's availability is also subject to the Gateway's own
// status conditions and listener status.
Expand Down
12 changes: 6 additions & 6 deletions apis/core/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 21 additions & 26 deletions config/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2210,11 +2210,12 @@ spec:
description: "Namespace is the namespace
of the backend. When unspecified,
the local namespace is inferred. \n
Note that when a namespace is specified,
a ReferenceGrant object is required
in the referent namespace to allow
that namespace's owner to accept the
reference. See the ReferenceGrant
Note that when a different namespace
is specified, a ReferenceGrant object
with ReferenceGrantTo.Kind=Service
is required in the referent namespace
to allow that namespace's owner to
accept the reference. See the ReferenceGrant
documentation for details. \n Support:
Core"
maxLength: 63
Expand Down Expand Up @@ -2485,11 +2486,12 @@ spec:
namespace:
description: "Namespace is the namespace of the backend.
When unspecified, the local namespace is inferred.
\n Note that when a namespace is specified, a ReferenceGrant
object is required in the referent namespace to
allow that namespace's owner to accept the reference.
See the ReferenceGrant documentation for details.
\n Support: Core"
\n Note that when a different namespace is specified,
a ReferenceGrant object with ReferenceGrantTo.Kind=Service
is required in the referent namespace to allow that
namespace's owner to accept the reference. See the
ReferenceGrant documentation for details. \n Support:
Core"
maxLength: 63
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
Expand Down Expand Up @@ -2744,10 +2746,11 @@ spec:
description: "Namespace is the namespace of
the backend. When unspecified, the local
namespace is inferred. \n Note that when
a namespace is specified, a ReferenceGrant
object is required in the referent namespace
to allow that namespace's owner to accept
the reference. See the ReferenceGrant documentation
a different namespace is specified, a ReferenceGrant
object with ReferenceGrantTo.Kind=Service
is required in the referent namespace to
allow that namespace's owner to accept the
reference. See the ReferenceGrant documentation
for details. \n Support: Core"
maxLength: 63
minLength: 1
Expand Down Expand Up @@ -39597,18 +39600,10 @@ subjects:
---
apiVersion: v1
data:
controller_manager_config.yaml: |
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
kind: ControllerManagerConfig
health:
healthProbeBindAddress: :8081
metrics:
bindAddress: 127.0.0.1:8080
webhook:
port: 9443
leaderElection:
leaderElect: true
resourceName: 79f0111e.openfunction.io
controller_manager_config.yaml: "apiVersion: controller-runtime.sigs.k8s.io/v1alpha1\r\nkind:
ControllerManagerConfig\r\nhealth:\r\n healthProbeBindAddress: :8081\r\nmetrics:\r\n
\ bindAddress: 127.0.0.1:8080\r\nwebhook:\r\n port: 9443\r\nleaderElection:\r\n
\ leaderElect: true\r\n resourceName: 79f0111e.openfunction.io\r\n"
kind: ConfigMap
metadata:
name: openfunction-manager-config
Expand Down
31 changes: 17 additions & 14 deletions config/crd/bases/core.openfunction.io_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,12 @@ spec:
description: "Namespace is the namespace
of the backend. When unspecified,
the local namespace is inferred. \n
Note that when a namespace is specified,
a ReferenceGrant object is required
in the referent namespace to allow
that namespace's owner to accept the
reference. See the ReferenceGrant
Note that when a different namespace
is specified, a ReferenceGrant object
with ReferenceGrantTo.Kind=Service
is required in the referent namespace
to allow that namespace's owner to
accept the reference. See the ReferenceGrant
documentation for details. \n Support:
Core"
maxLength: 63
Expand Down Expand Up @@ -763,11 +764,12 @@ spec:
namespace:
description: "Namespace is the namespace of the backend.
When unspecified, the local namespace is inferred.
\n Note that when a namespace is specified, a ReferenceGrant
object is required in the referent namespace to
allow that namespace's owner to accept the reference.
See the ReferenceGrant documentation for details.
\n Support: Core"
\n Note that when a different namespace is specified,
a ReferenceGrant object with ReferenceGrantTo.Kind=Service
is required in the referent namespace to allow that
namespace's owner to accept the reference. See the
ReferenceGrant documentation for details. \n Support:
Core"
maxLength: 63
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
Expand Down Expand Up @@ -1022,10 +1024,11 @@ spec:
description: "Namespace is the namespace of
the backend. When unspecified, the local
namespace is inferred. \n Note that when
a namespace is specified, a ReferenceGrant
object is required in the referent namespace
to allow that namespace's owner to accept
the reference. See the ReferenceGrant documentation
a different namespace is specified, a ReferenceGrant
object with ReferenceGrantTo.Kind=Service
is required in the referent namespace to
allow that namespace's owner to accept the
reference. See the ReferenceGrant documentation
for details. \n Support: Core"
maxLength: 63
minLength: 1
Expand Down

0 comments on commit 8882e05

Please sign in to comment.