kyma-project / api-gateway

Apache License 2.0
4 stars 26 forks source link

APIRule v1beta1 -> v2alpha1 conversion should add the domain to the host name (if it is not FQDN) #1166

Closed mluk-sap closed 1 week ago

mluk-sap commented 3 months ago

Description

The host name in APIRule v2alpha1 is expected to be in FQDN format, while in v1beta1 it could be provided in a short name (only host without domain). It would be nice to enhance a conversion webhook, so it adds the domain automatically during conversion from v1beta1 to v2alpha1.

Reasons

It is now still possible to still have a host without domain in v2alpha1 if it is converted from v1beta1.

How to reproduce it:

cat <<EOF | kubectl apply -f -
apiVersion: gateway.kyma-project.io/v1beta1
kind: APIRule
metadata:
  name: httpbin-rule
  namespace: default
spec:
  host: httpbin
  service:
    name: httpbin
    namespace: default
    port: 8000
  gateway: kyma-gateway
  rules:
    - path: /.*
      methods: ["GET"]
      accessStrategies:
        - handler: no_auth
    - path: /post
      methods: ["POST"]
      accessStrategies:
        - handler: no_auth
EOF

Get the apirule resource in v2alpha1:

kubectl get apirules.v2alpha1.gateway.kyma-project.io -A -o yaml >apirule_converted.yaml

It gives:

apiVersion: v1
items:
- apiVersion: gateway.kyma-project.io/v2alpha1
  kind: APIRule
  metadata:
    annotations:
      kubectl.kubernetes.io/last-applied-configuration: |
        {"apiVersion":"gateway.kyma-project.io/v1beta1","kind":"APIRule","metadata":{"annotations":{},"name":"httpbin-rule","namespace":"default"},"spec":{"gateway":"kyma-gateway","host":"httpbin","rules":[{"accessStrategies":[{"handler":"no_auth"}],"methods":["GET"],"path":"/.*"},{"accessStrategies":[{"handler":"no_auth"}],"methods":["POST"],"path":"/post"}],"service":{"name":"httpbin","namespace":"default","port":8000}}}
    creationTimestamp: "2024-07-15T11:22:18Z"
    finalizers:
    - gateway.kyma-project.io/subresources
    generation: 1
    name: httpbin-rule
    namespace: default
    resourceVersion: "5134"
    uid: 10de779e-a02f-4bbe-a4ca-4c2c0a47fb58
  spec:
    gateway: kyma-gateway
    hosts:
    - httpbin
    rules:
    - methods:
      - GET
      noAuth: true
      path: /.*
    - methods:
      - POST
      noAuth: true
      path: /post
    service:
      name: httpbin
      namespace: default
      port: 8000
  status:
    lastProcessedTime: "2024-07-15T11:22:24Z"
    state: Ready
kind: List
metadata:
  resourceVersion: ""

Then let's try to recreate it from the above content:

kubectl delete apirule httpbin-rule
kubectl apply -f ./apirule_converted.yaml
kubectl describe apirule

It gives error:

Status:
  API Rule Status:
    Code:  ERROR
    Desc:  Validation error: Attribute ".spec.hosts[0]": Host is not fully qualified domain name

DoD:

Attachments

strekm commented 2 months ago

@mluk-sap i think it will be resolved with https://github.com/kyma-project/api-gateway/issues/1247