Skip to content

Commit ba6a07c

Browse files
committed
The function now uses additionalDestinations passed from the interface
instead of pulling from rollout status for better responsiveness. Addresses issue #112. Signed-off-by: vthiruveedhi <[email protected]>
1 parent 21ecff5 commit ba6a07c

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

pkg/plugin/experiment.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
gatewayApiClientset "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"
1313
)
1414

15-
func HandleExperiment(ctx context.Context, clientset *kubernetes.Clientset, gatewayClient *gatewayApiClientset.Clientset, logger *logrus.Entry, rollout *v1alpha1.Rollout, httpRoute *gatewayv1.HTTPRoute) error {
15+
func HandleExperiment(ctx context.Context, clientset *kubernetes.Clientset, gatewayClient *gatewayApiClientset.Clientset, logger *logrus.Entry, rollout *v1alpha1.Rollout, httpRoute *gatewayv1.HTTPRoute, additionalDestinations []v1alpha1.WeightDestination) error {
1616
ruleIdx := -1
1717
stableService := rollout.Spec.Strategy.Canary.StableService
1818
canaryService := rollout.Spec.Strategy.Canary.CanaryService
@@ -47,8 +47,8 @@ func HandleExperiment(ctx context.Context, clientset *kubernetes.Clientset, gate
4747
if isExperimentActive {
4848
logger.Info(fmt.Sprintf("Found active experiment %s", rollout.Status.Canary.CurrentExperiment))
4949

50-
if len(rollout.Status.Canary.Weights.Additional) == 0 {
51-
logger.Info("No experiment services found in rollout status, skipping experiment service addition")
50+
if len(additionalDestinations) == 0 {
51+
logger.Info("No experiment services found in additionalDestinations, skipping experiment service addition")
5252
return nil
5353
}
5454

@@ -60,9 +60,9 @@ func HandleExperiment(ctx context.Context, clientset *kubernetes.Clientset, gate
6060
}
6161
}
6262

63-
for _, additionalDestination := range rollout.Status.Canary.Weights.Additional {
64-
serviceName := additionalDestination.ServiceName
65-
weight := additionalDestination.Weight
63+
for _, additionalDest := range additionalDestinations {
64+
serviceName := additionalDest.ServiceName
65+
weight := additionalDest.Weight
6666

6767
exists := false
6868
for _, backendRef := range httpRoute.Spec.Rules[ruleIdx].BackendRefs {

pkg/plugin/httproute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717
HTTPConfigMapKey = "httpManagedRoutes"
1818
)
1919

20-
func (r *RpcPlugin) setHTTPRouteWeight(rollout *v1alpha1.Rollout, desiredWeight int32, gatewayAPIConfig *GatewayAPITrafficRouting) pluginTypes.RpcError {
20+
func (r *RpcPlugin) setHTTPRouteWeight(rollout *v1alpha1.Rollout, desiredWeight int32, additionalDestinations []v1alpha1.WeightDestination, gatewayAPIConfig *GatewayAPITrafficRouting) pluginTypes.RpcError {
2121
ctx := context.TODO()
2222
httpRouteClient := r.HTTPRouteClient
2323
if !r.IsTest {
@@ -52,7 +52,7 @@ func (r *RpcPlugin) setHTTPRouteWeight(rollout *v1alpha1.Rollout, desiredWeight
5252
for _, ref := range stableBackendRefs {
5353
ref.Weight = &restWeight
5454
}
55-
err = HandleExperiment(ctx, r.Clientset, r.GatewayAPIClientset, r.LogCtx, rollout, httpRoute)
55+
err = HandleExperiment(ctx, r.Clientset, r.GatewayAPIClientset, r.LogCtx, rollout, httpRoute, additionalDestinations)
5656
if err != nil {
5757
r.LogCtx.Error(err, "Failed to handle experiment services")
5858
}

pkg/plugin/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (r *RpcPlugin) SetWeight(rollout *v1alpha1.Rollout, desiredWeight int32, ad
7878
r.LogCtx.Info(fmt.Sprintf("[SetWeight] plugin %q controls HTTPRoutes: %v", PluginName, getGatewayAPIRouteNameList(gatewayAPIConfig.HTTPRoutes)))
7979
rpcError := forEachGatewayAPIRoute(gatewayAPIConfig.HTTPRoutes, func(route HTTPRoute) pluginTypes.RpcError {
8080
gatewayAPIConfig.HTTPRoute = route.Name
81-
return r.setHTTPRouteWeight(rollout, desiredWeight, gatewayAPIConfig)
81+
return r.setHTTPRouteWeight(rollout, desiredWeight, additionalDestinations, gatewayAPIConfig)
8282
})
8383
if rpcError.HasError() {
8484
return rpcError

0 commit comments

Comments
 (0)