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

generate istio destinationRule subset from pod-template-hash #212

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (src *Rollout) ConvertTo(dst conversion.Hub) error {
func ConversionToV1beta1TrafficRoutingRef(src TrafficRoutingRef) (dst v1beta1.TrafficRoutingRef) {
dst.Service = src.Service
dst.GracePeriodSeconds = src.GracePeriodSeconds
dst.AdditionalParams = src.AdditionalParams
if src.Ingress != nil {
dst.Ingress = &v1beta1.IngressTrafficRouting{
ClassType: src.Ingress.ClassType,
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/trafficrouting_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

const (
ProgressingRolloutFinalizerPrefix = "progressing.rollouts.kruise.io"
IstioStableSubsetName = "istio.destinationRule.stableSubsetName"
IstioCanarySubsetName = "istio.destinationRule.canarySubsetName"
)

// TrafficRoutingRef hosts all the different configuration for supported service meshes to enable more fine-grained traffic routing
Expand All @@ -38,6 +40,10 @@ type TrafficRoutingRef struct {
Gateway *GatewayTrafficRouting `json:"gateway,omitempty"`
// CustomNetworkRefs hold a list of custom providers to route traffic
CustomNetworkRefs []CustomNetworkRef `json:"customNetworkRefs,omitempty"`
// vaild keys:
// + IstioStableSubsetName
// + IstioCanarySubsetName
AdditionalParams map[string]string `json:"additionalParams,omitempty"`
}

// IngressTrafficRouting configuration for ingress controller to control traffic routing
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

9 changes: 9 additions & 0 deletions api/v1beta1/trafficrouting.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ limitations under the License.

package v1beta1

const (
IstioStableSubsetName = "istio.destinationRule.stableSubsetName"
IstioCanarySubsetName = "istio.destinationRule.canarySubsetName"
)

// TrafficRoutingRef hosts all the different configuration for supported service meshes to enable more fine-grained traffic routing
type TrafficRoutingRef struct {
// Service holds the name of a service which selects pods with stable version and don't select any pods with canary version.
Expand All @@ -29,6 +34,10 @@ type TrafficRoutingRef struct {
Gateway *GatewayTrafficRouting `json:"gateway,omitempty"`
// CustomNetworkRefs hold a list of custom providers to route traffic
CustomNetworkRefs []ObjectRef `json:"customNetworkRefs,omitempty"`
// vaild keys:
// + IstioStableSubsetName
// + IstioCanarySubsetName
AdditionalParams map[string]string `json:"additionalParams,omitempty"`
}

// IngressTrafficRouting configuration for ingress controller to control traffic routing
Expand Down
7 changes: 7 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

10 changes: 10 additions & 0 deletions config/crd/bases/rollouts.kruise.io_rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ spec:
for supported service meshes to enable more fine-grained
traffic routing
properties:
additionalParams:
additionalProperties:
type: string
description: 'vaild keys:'
type: object
customNetworkRefs:
description: CustomNetworkRefs hold a list of custom
providers to route traffic
Expand Down Expand Up @@ -827,6 +832,11 @@ spec:
for supported service meshes to enable more fine-grained
traffic routing
properties:
additionalParams:
additionalProperties:
type: string
description: 'vaild keys:'
type: object
customNetworkRefs:
description: CustomNetworkRefs hold a list of custom
providers to route traffic
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/rollouts.kruise.io_trafficroutings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ spec:
for supported service meshes to enable more fine-grained traffic
routing
properties:
additionalParams:
additionalProperties:
type: string
description: 'vaild keys:'
type: object
customNetworkRefs:
description: CustomNetworkRefs hold a list of custom providers
to route traffic
Expand Down
26 changes: 16 additions & 10 deletions lua_configuration/convert_test_case_to_lua_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ func objectToTable(path string) error {
Annotations: testCase.Original.GetAnnotations(),
Spec: testCase.Original.Object["spec"],
},
Matches: step.TrafficRoutingStrategy.Matches,
CanaryWeight: *weight,
StableWeight: 100 - *weight,
CanaryService: canaryService,
StableService: stableService,
Matches: step.TrafficRoutingStrategy.Matches,
CanaryWeight: *weight,
StableWeight: 100 - *weight,
CanaryService: canaryService,
StableService: stableService,
StableRevision: "podtemplatehash-v1",
CanaryRevision: "podtemplatehash-v2",
RevisionLabelKey: "pod-template-hash",
}
uList[fmt.Sprintf("step_%d", i)] = data
}
Expand All @@ -128,11 +131,14 @@ func objectToTable(path string) error {
Annotations: testCase.Original.GetAnnotations(),
Spec: testCase.Original.Object["spec"],
},
Matches: matches,
CanaryWeight: *weight,
StableWeight: 100 - *weight,
CanaryService: canaryService,
StableService: stableService,
Matches: matches,
CanaryWeight: *weight,
StableWeight: 100 - *weight,
CanaryService: canaryService,
StableService: stableService,
StableRevision: "podtemplatehash-v1",
CanaryRevision: "podtemplatehash-v2",
RevisionLabelKey: "pod-template-hash",
}
uList["steps_0"] = data
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ trafficRouting:
- apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
name: ds-demo
additionalParams:
istio.destinationRule.stableSubsetName: "version-base"
istio.destinationRule.canarySubsetName: "canary"
original:
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
Expand All @@ -27,9 +30,7 @@ original:
loadBalancer:
simple: ROUND_ROBIN
subsets:
- labels:
version: base
name: version-base
- name: version-base
expected:
- apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
Expand All @@ -42,8 +43,8 @@ expected:
simple: ROUND_ROBIN
subsets:
- labels:
version: base
pod-template-hash: "podtemplatehash-v1"
name: version-base
- labels:
istio.service.tag: gray
pod-template-hash: "podtemplatehash-v2"
name: canary
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
local function updateOrCreateSubset(subsets, name, labels)
for _, subset in ipairs(subsets) do
if subset.name == name then
if next(labels) ~= nil then
subset.labels = subset.labels or {}
for key, value in pairs(labels) do
subset.labels[key] = value
end
end
return -- Do not need to continue if name exists,as we update the first occurrence
end
end
table.insert(subsets, {
name = name,
labels = next(labels) ~= nil and labels or nil
})
end

local spec = obj.data.spec
local canary = {}
canary.labels = {}
canary.name = "canary"
local podLabelKey = "istio.service.tag"
canary.labels[podLabelKey] = "gray"
table.insert(spec.subsets, canary)
return obj.data
local pod_label_key = obj.revisionLabelKey
if spec.subsets == nil then
spec.subsets = {}
end

local stable_labels = {}
if obj.stableRevision ~= nil and obj.stableRevision ~= "" then
stable_labels[pod_label_key] = obj.stableRevision
end

local canary_labels = {}
if obj.canaryRevision ~= nil and obj.canaryRevision ~= "" then
canary_labels[pod_label_key] = obj.canaryRevision
end

-- Process stable subset
updateOrCreateSubset(spec.subsets, obj.stableName, stable_labels)

-- Process canary subset
updateOrCreateSubset(spec.subsets, obj.canaryName, canary_labels)

return obj.data
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ trafficRouting:
- apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
name: vs-demo
additionalParams:
istio.destinationRule.stableSubsetName: "base"
istio.destinationRule.canarySubsetName: "canary"
original:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ trafficRouting:
- apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
name: vs-demo
additionalParams:
istio.destinationRule.stableSubsetName: "base"
istio.destinationRule.canarySubsetName: "canary"
original:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ trafficRouting:
- apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
name: vs-demo
additionalParams:
istio.destinationRule.stableSubsetName: "base"
istio.destinationRule.canarySubsetName: "canary"
original:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function GenerateRoutesWithMatches(spec, matches, stableService, canaryService)
-- stableService == canaryService indicates DestinationRule exists and subset is set to be canary by default
if stableService == canaryService then
route.route[1].destination.host = stableService
route.route[1].destination.subset = "canary"
route.route[1].destination.subset = obj.canaryName
else
route.route[1].destination.host = canaryService
end
Expand All @@ -113,7 +113,7 @@ function GenerateRoutes(spec, stableService, canaryService, stableWeight, canary
canary = {
destination = {
host = stableService,
subset = "canary",
subset = obj.canaryName,
},
weight = canaryWeight,
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/rollout/rollout_canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ func (m *canaryReleaseManager) doCanaryFinalising(c *RolloutContext) (bool, erro
if err != nil || !done {
return done, err
}
// 3. set workload.pause=false; set workload.partition=0
done, err = m.finalizingBatchRelease(c)
// 3. modify network api(ingress or gateway api) configuration, and route 100% traffic to stable pods.
done, err = m.trafficRoutingManager.FinalisingTrafficRouting(tr, false)
c.NewStatus.CanaryStatus.LastUpdateTime = tr.LastUpdateTime
if err != nil || !done {
return done, err
}
// 4. modify network api(ingress or gateway api) configuration, and route 100% traffic to stable pods.
done, err = m.trafficRoutingManager.FinalisingTrafficRouting(tr, false)
c.NewStatus.CanaryStatus.LastUpdateTime = tr.LastUpdateTime
// 4. set workload.pause=false; set workload.partition=0
done, err = m.finalizingBatchRelease(c)
if err != nil || !done {
return done, err
}
Expand Down
18 changes: 10 additions & 8 deletions pkg/trafficrouting/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,16 @@ func newNetworkProvider(c client.Client, con *TrafficRoutingContext, sService, c
trafficRouting := con.ObjectRef[0]
if trafficRouting.CustomNetworkRefs != nil {
return custom.NewCustomController(c, custom.Config{
Key: con.Key,
RolloutNs: con.Namespace,
CanaryService: cService,
StableService: sService,
TrafficConf: trafficRouting.CustomNetworkRefs,
OwnerRef: con.OwnerRef,
//only set for CustomController, never work for Ingress and Gateway
DisableGenerateCanaryService: con.DisableGenerateCanaryService,
Key: con.Key,
RolloutNs: con.Namespace,
CanaryService: cService,
StableService: sService,
TrafficConf: trafficRouting.CustomNetworkRefs,
OwnerRef: con.OwnerRef,
AdditionalParams: trafficRouting.AdditionalParams,
RevisionLabelKey: con.RevisionLabelKey,
StableRevision: con.StableRevision,
CanaryRevision: con.CanaryRevision,
})
}
if trafficRouting.Ingress != nil {
Expand Down
Loading
Loading