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: allow VirtualService HTTPRoute to be inferred if there is single route #1273

Merged
merged 2 commits into from
Jun 15, 2021

Conversation

jessesuen
Copy link
Member

@jessesuen jessesuen commented Jun 12, 2021

Currently, the istio configuration in the rollout requires a VirtualService HTTPRoute name to be explicitly specified.
This change makes it possible to infer the HTTP route in the event that there is only a single route specified, simplifying the Rollout config. e.g.:

  strategy:
    canary:
      trafficRouting:
        istio:
          virtualService: 
            name: istio-subset-split-single-route-vsvc
          destinationRule:
            name: istio-subset-split-single-route-destrule
            canarySubsetName: canary
            stableSubsetName: stable

Signed-off-by: Jesse Suen [email protected]

@codecov
Copy link

codecov bot commented Jun 12, 2021

Codecov Report

Merging #1273 (de2c209) into master (fe4bb1b) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1273      +/-   ##
==========================================
+ Coverage   81.35%   81.39%   +0.03%     
==========================================
  Files         106      106              
  Lines        9597     9604       +7     
==========================================
+ Hits         7808     7817       +9     
+ Misses       1260     1259       -1     
+ Partials      529      528       -1     
Impacted Files Coverage Δ
pkg/apis/rollouts/validation/validation.go 91.61% <ø> (+1.16%) ⬆️
rollout/trafficrouting/istio/istio.go 78.66% <100.00%> (+0.62%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe4bb1b...de2c209. Read the comment docs.

rollout/trafficrouting/istio/istio_test.go Outdated Show resolved Hide resolved
rollout/trafficrouting/istio/istio.go Outdated Show resolved Hide resolved
vsvcUn, err := client.Resource(istioutil.GetIstioVirtualServiceGVR()).Namespace(ro.Namespace).Get(context.TODO(), "vsvc", metav1.GetOptions{})
assert.NoError(t, err)
routes, _, _ := unstructured.NestedSlice(vsvcUn.Object, "spec", "http")
route := routes[0].(map[string]interface{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add an assert.Equal to verify the route name is correctly inferred?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the test VirtualService intentionally does not have a route name so there's no name to verify:

kind: VirtualService
metadata:
  name: vsvc
  namespace: default
spec:
  gateways:
  - istio-rollout-gateway
  hosts:
  - istio-rollout.dev.argoproj.io
  http:
  - route:
    - destination:
        host: 'stable'
      weight: 100
    - destination:
        host: canary
      weight: 0

@sonarcloud
Copy link

sonarcloud bot commented Jun 15, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
11.3% 11.3% Duplication

Copy link
Contributor

@alexmt alexmt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Added one comment

canarySubset := ""
stableSubset := ""
if r.rollout.Spec.Strategy.Canary.TrafficRouting.Istio.DestinationRule != nil {
canarySubset = r.rollout.Spec.Strategy.Canary.TrafficRouting.Istio.DestinationRule.CanarySubsetName
stableSubset = r.rollout.Spec.Strategy.Canary.TrafficRouting.Istio.DestinationRule.StableSubsetName
}

// err can be ignored because we already called ValidateHTTPRoutes earlier
routeIndexesToPatch, _ := getRouteIndexesToPatch(r.rollout.Spec.Strategy.Canary.TrafficRouting.Istio.VirtualService.Routes, httpRoutes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: I would panic just in case. If for some reason getRouteIndexesToPatch returns error then routeIndexesToPatch is nil/empty slice. The crash is better than silently do nothing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did consider that but determined it was safe to proceed, even on error because we would only iterate a nil slice, which is safe. Having a panic would be equivalent to allowing a nil pointer dereference.

@huikang
Copy link
Member

huikang commented Jun 15, 2021

LGTM

@jessesuen jessesuen merged commit 7a23fe5 into argoproj:master Jun 15, 2021
@jessesuen jessesuen deleted the istio-optional-route branch June 15, 2021 19:27
perenesenko pushed a commit to perenesenko/argo-rollouts that referenced this pull request Jun 22, 2021
mbhatip pushed a commit to mbhatip/argo-rollouts that referenced this pull request Jun 22, 2021
mbhatip pushed a commit to mbhatip/argo-rollouts that referenced this pull request Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants