Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add setHeader functionality for httpRoutes #31

Merged
merged 11 commits into from
Feb 9, 2024

Conversation

Philipp-Plotnikov
Copy link
Collaborator

@Philipp-Plotnikov Philipp-Plotnikov commented Jan 29, 2024

Example of ArgoRollouts

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: rollouts-demo
spec:
  replicas: 4
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: rollouts-demo
  template:
    metadata:
      labels:
        app: rollouts-demo
    spec:
      containers:
      - name: rollouts-demo
        image: argoproj/rollouts-demo:orange
        ports:
        - name: http
          containerPort: 8080
          protocol: TCP
  strategy:
    canary:
      stableService: stable-service
      canaryService: canary-service
      trafficRouting:
        managedRoutes:
          - name: header-route
        plugins:
          argoproj-labs/gatewayAPI:
            namespace: default                                                                                                
            httpRoute: http-route
            configMap: test-gateway
      steps:
      - setWeight: 20
      - pause: {duration: 10}
      - setWeight: 40
      - pause: {duration: 20}
      - setWeight: 60
      - setHeaderRoute:
          name: header-route
          match:
            - headerName: X-Test
              headerValue:
                exact: test
      - pause: {duration: 5}
      - setWeight: 80
      - setHeaderRoute: # remove header route
          name: header-route
      - pause: {}

Plugin will take "http-route" of HttpRoute type and will add rules corresponding setHeaderRoute step. One step - one rule. Also it will add Path and QueryParams match from first HTTPRoute rule where stable and canary service is. GatewayAPI will use rule where more matches fit. Plugin will delete header rules when it will get event removeManagedRoutes or on the step like in the example (remove header route)

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: http-route
spec:
  parentRefs:
    - name: argo-gateway
      sectionName: http
  rules:
    - backendRefs:
      - name: stable-service
        port: 80
        weight: 100
      - name: canary-service
        port: 80
      matches:
      - path:
           type: PathPrefix
           value: /test

After setHeaderRoute step

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: http-route
spec:
  parentRefs:
    - name: argo-gateway
      sectionName: http
  rules:
    - backendRefs:
      - name: stable-service
        port: 80
        weight: 100
      - name: canary-service
        port: 80
      matches:
      - path:
           type: PathPrefix
           value: /
    - backendRefs:                                                                                                              
       - group: ""                                                                                                               
          kind: Service                                                                                                           
          name: canary-service                                                                                                    
          port: 80                                                                                                                
         weight: 1                                                                                                               
      matches:                                                                                                                  
       - headers:                                                                                                                
         - name: X-Test                                                                                                          
            type: Exact                                                                                                           
            value: test                                                                                                           
        path:                                                                                                                   
          type: PathPrefix                                                                                                      
          value: /test

Plugin save where(which index) and what headerRoute step in configMap. Plugin creates if configMap wasn't created with specified name under key configMap and in specified namespace under key namespace like here

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-gateway
  namespace: default
data:
   httpManagedRoutes: '{"header-route": 1}'

If you dont specify the configMap, its default name will be argo-gatewayapi-configmap

Signed-off-by: Philipp Plotnikov <[email protected]>
@Philipp-Plotnikov Philipp-Plotnikov added the enhancement New feature or request label Jan 29, 2024
@Philipp-Plotnikov Philipp-Plotnikov self-assigned this Feb 5, 2024
@Philipp-Plotnikov Philipp-Plotnikov linked an issue Feb 6, 2024 that may be closed by this pull request
@Philipp-Plotnikov Philipp-Plotnikov merged commit 139e9de into main Feb 9, 2024
4 checks passed
@Philipp-Plotnikov Philipp-Plotnikov deleted the philipp/set-header branch February 9, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SetHeader option support
2 participants