Skip to content

Commit

Permalink
apiproduct: spec.routing.hosts -> spec.hosts (#54)
Browse files Browse the repository at this point in the history
The destination hosts to which traffic is being sent should be first class attr in the spec
  • Loading branch information
eguzki authored Oct 14, 2021
1 parent b23551c commit b4c1fcb
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 46 deletions.
11 changes: 6 additions & 5 deletions apis/networking/v1beta1/apiproduct_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ type SecurityScheme struct {
OpenIDConnectAuth *OpenIDConnectAuth `json:"openIDConnectAuth,omitempty"`
}

type Routing struct {
Hosts []string `json:"hosts"`
}

type Mapping struct {
Prefix string `json:"prefix"`
}
Expand Down Expand Up @@ -106,7 +102,12 @@ type RateLimitSpec struct {

// APIProductSpec defines the desired state of APIProduct
type APIProductSpec struct {
Routing Routing `json:"routing"`
// The destination hosts to which traffic is being sent. Could
// be a DNS name with wildcard prefix or an IP address. Depending on the
// platform, short-names can also be used instead of a FQDN (i.e. has no
// dots in the name). In such a scenario, the FQDN of the host would be
// derived based on the underlying platform.
Hosts []string `json:"hosts"`
SecurityScheme []*SecurityScheme `json:"securityScheme"`
APIs []*APISelector `json:"APIs"`

Expand Down
26 changes: 5 additions & 21 deletions apis/networking/v1beta1/zz_generated.deepcopy.go

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

20 changes: 10 additions & 10 deletions config/crd/bases/networking.kuadrant.io_apiproducts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ spec:
- namespace
type: object
type: array
hosts:
description: The destination hosts to which traffic is being sent.
Could be a DNS name with wildcard prefix or an IP address. Depending
on the platform, short-names can also be used instead of a FQDN
(i.e. has no dots in the name). In such a scenario, the FQDN of
the host would be derived based on the underlying platform.
items:
type: string
type: array
rateLimit:
description: RateLimit configures global rate limit parameters
properties:
Expand Down Expand Up @@ -112,15 +121,6 @@ spec:
- period
type: object
type: object
routing:
properties:
hosts:
items:
type: string
type: array
required:
- hosts
type: object
securityScheme:
items:
properties:
Expand Down Expand Up @@ -159,7 +159,7 @@ spec:
type: array
required:
- APIs
- routing
- hosts
- securityScheme
type: object
status:
Expand Down
4 changes: 1 addition & 3 deletions controllers/apiproduct_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ func apiProduct(ns string) *networkingv1beta1.APIProduct {
},
ObjectMeta: metav1.ObjectMeta{Name: "apiproduct01", Namespace: ns},
Spec: networkingv1beta1.APIProductSpec{
Routing: networkingv1beta1.Routing{
Hosts: []string{"petstore.127.0.0.1.nip.io"},
},
Hosts: []string{"petstore.127.0.0.1.nip.io"},
APIs: []*networkingv1beta1.APISelector{
{
Name: "cats",
Expand Down
2 changes: 1 addition & 1 deletion pkg/authproviders/authorino/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func buildAuthConfig(apip *networkingv1beta1.APIProduct) *authorino.AuthConfig {
Namespace: common.KuadrantNamespace,
},
Spec: authorino.AuthConfigSpec{
Hosts: apip.Spec.Routing.Hosts,
Hosts: apip.Spec.Hosts,
Identity: nil,
Metadata: nil,
Authorization: nil,
Expand Down
2 changes: 1 addition & 1 deletion pkg/ingressproviders/istioprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (is *IstioProvider) virtualServiceFromAPIProduct(ctx context.Context, apip
factory := VirtualServiceFactory{
ObjectName: apip.Name + apip.Namespace,
Namespace: common.KuadrantNamespace,
Hosts: apip.Spec.Routing.Hosts,
Hosts: apip.Spec.Hosts,
HTTPRoutes: httpRoutes,
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/ingressproviders/istioprovider/rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func preAuthEnvoyFilter(apip *networkingv1beta1.APIProduct) *istionetworkingv1al

factory.Patches = append(factory.Patches, preAuthHTTPFilterEnvoyPatch(apip))

for _, host := range apip.Spec.Routing.Hosts {
for _, host := range apip.Spec.Hosts {
factory.Patches = append(factory.Patches, preAuthActionsEnvoyPatch(apip, host))
}

Expand All @@ -114,7 +114,7 @@ func postAuthEnvoyFilter(apip *networkingv1beta1.APIProduct) *istionetworkingv1a

factory.Patches = append(factory.Patches, postAuthHTTPFilterEnvoyPatch(apip))

for _, host := range apip.Spec.Routing.Hosts {
for _, host := range apip.Spec.Hosts {
factory.Patches = append(factory.Patches, postAuthActionsEnvoyPatch(host))
}

Expand Down
5 changes: 2 additions & 3 deletions samples/apiproduct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ kind: APIProduct
metadata:
name: animaltoys
spec:
routing:
hosts:
- api.animaltoys.127.0.0.1.nip.io
hosts:
- api.animaltoys.127.0.0.1.nip.io
APIs:
- name: dogs
namespace: default
Expand Down

0 comments on commit b4c1fcb

Please sign in to comment.