Skip to content

shengjiangfeng/istio-virtualservice-merger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ec54fa4 · Sep 20, 2024

History

50 Commits
Aug 17, 2022
Sep 20, 2024
Aug 26, 2022
Sep 11, 2024
Dec 14, 2021
Sep 20, 2024
Aug 16, 2022
Jul 22, 2022
Sep 11, 2024
Jul 31, 2022
Sep 11, 2024
Sep 11, 2024
Dec 14, 2021
Sep 11, 2024
Dec 14, 2021
Sep 11, 2024
Dec 14, 2021
Sep 11, 2024
Sep 11, 2024
Sep 11, 2024
Aug 26, 2022

Repository files navigation

istio-virtualservice-merger

Fork from https://github.com/monimesl/istio-virtualservice-merger.git. It cannot support istio 1.21

A simple kubernetes operator to merge seperated Istio virtual services using the same host.

Note: This a temporary solution to the issue

Please read the above issue to understand why this is needed

Installation

Install the CRD

kubectl apply -f https://raw.githubusercontent.com/shengjiangfeng/istio-virtualservice-merger/main/manifest/crd.yaml

Deploy the operator

kubectl apply -f https://raw.githubusercontent.com/shengjiangfeng/istio-virtualservice-merger/master/manifest/operator.yaml
Create a target virtual service on which seperated patches are merged into.
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: api-routes
spec:
  gateways:
    - "mesh"
  hosts:
    - "internal-api.monime.sl"
Create a review VirtualServiceMerge
apiVersion: istiomerger.monime.sl/v1alpha1
kind: VirtualServiceMerge
metadata:
  name: review-routes
  namespace: app-space
spec:
  target:
    name: "api-routes" ## the virtual service above
    namespace: "" # empty or omitted means the same as the VirtualServiceMerge
  patch: # same as https://istio.io/latest/docs/reference/config/networking/virtual-service/#VirtualService
    http:
      - match:
          - uri:
              prefix: "/reviews"
        route:
          - destination:
              port:
                number: 8080
              host: "review-service"
Create a product VirtualServiceMerge
apiVersion: istiomerger.monime.sl/v1alpha1
kind: VirtualServiceMerge
metadata:
  name: product-routes
  namespace: app-space
spec:
  target:
    name: "api-routes" ## the virtual service above
    namespace: "" # empty or omitted means the same as the VirtualServiceMerge
  patch: # same as https://istio.io/latest/docs/reference/config/networking/virtual-service/#VirtualService
    http:
      - match:
          - uri:
              prefix: "/products"
        route:
          - destination:
              port:
                number: 8080
              host: "product-service"

The two VirtualServiceMerge objects will be merged into the targeted VirtualServices to produce a result similar to below:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: api-routes
spec:
  gateways:
    - "mesh"
  hosts:
    - "internal-api.monime.sl"
  http:
    - match:
        - uri:
            prefix: "/reviews"
      name: review-routes-0 # 0 is the precedence
      route:
        - destination:
            port:
              number: 8080
            host: "review-service"
    - match:
        - uri:
            prefix: "/products"
      # 1 is the precedence, 'product-routes' route will appear before any routes with lesser 
      # precedence that were merged onto the target even if they're from a different patch.      
      name: product-routes-1
      route:
        - destination:
            port:
              number: 8080
            host: "product-service"

The merging works for TCP and TLS routes as well