8000 Patch canary service selector from PodTemplateMetadata by lujiajing1126 · Pull Request #243 · openkruise/rollouts · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Patch canary service selector from PodTemplateMetadata #243

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

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Fai 8000 led to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/controller/rollout/rollout_progressing.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,16 @@ func newTrafficRoutingContext(c *RolloutContext) *trafficrouting.TrafficRoutingC
if c.Workload != nil {
revisionLabelKey = c.Workload.RevisionLabelKey
}
var selectorPatch map[string]string
if !c.Rollout.Spec.Strategy.DisableGenerateCanaryService() && c.Rollout.Spec.Strategy.Canary.PatchPodTemplateMetadata != nil {
selectorPatch = c.Rollout.Spec.Strategy.Canary.PatchPodTemplateMetadata.Labels
}
return &trafficrouting.TrafficRoutingContext{
Key: fmt.Sprintf("Rollout(%s/%s)", c.Rollout.Namespace, c.Rollout.Name),
Namespace: c.Rollout.Namespace,
ObjectRef: c.Rollout.Spec.Strategy.GetTrafficRouting(),
Strategy: currentStep.TrafficRoutingStrategy,
CanaryServiceSelectorPatch: selectorPatch,
OwnerRef: *metav1.NewControllerRef(c.Rollout, rolloutControllerKind),
RevisionLabelKey: revisionLabelKey,
StableRevision: c.NewStatus.GetSubStatus().StableRevision,
Expand Down
7 changes: 5 additions & 2 deletions pkg/feature/rollout_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ const (
RolloutHistoryGate featuregate.Feature = "RolloutHistory"
// AdvancedDeploymentGate enable advanced deployment controller.
AdvancedDeploymentGate featuregate.Feature = "AdvancedDeployment"
// AppendServiceSelectorGate enable appending pod labels from PodTemplateMetadata to the canary service selector.
AppendServiceSelectorGate featuregate.Feature = "AppendPodSelector"
)

var defaultFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
RolloutHistoryGate: {Default: false, PreRelease: featuregate.Alpha},
AdvancedDeploymentGate: {Default: false, PreRelease: featuregate.Alpha},
RolloutHistoryGate: {Default: false, PreRelease: featuregate.Alpha},
AdvancedDeploymentGate: {Default: false, PreRelease: featuregate.Alpha},
AppendServiceSelectorGate: {Default: false, PreRelease: featuregate.Alpha},
}

func init() {
Expand Down
33 changes: 22 additions & 11 deletions pkg/trafficrouting/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ import (
"fmt"
"time"

"github.com/openkruise/rollouts/api/v1beta1"
"github.com/openkruise/rollouts/pkg/trafficrouting/network"
custom "github.com/openkruise/rollouts/pkg/trafficrouting/network/customNetworkProvider"
"github.com/openkruise/rollouts/pkg/trafficrouting/network/gateway"
"github.com/openkruise/rollouts/pkg/trafficrouting/network/ingress"
"github.com/openkruise/rollouts/pkg/util"
"github.com/openkruise/rollouts/pkg/util/grace"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -36,6 +29,16 @@ import (
"k8s.io/utils/integer"
utilpointer "k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/openkruise/rollouts/api/v1beta1"
"github.com/openkruise/rollouts/pkg/feature"
"github.com/openkruise/rollouts/pkg/trafficrouting/network"
custom "github.com/openkruise/rollouts/pkg/trafficrouting/network/customNetworkProvider"
"github.com/openkruise/rollouts/pkg/trafficrouting/network/gateway"
"github.com/openkruise/rollouts/pkg/trafficrouting/network/ingress"
"github.com/openkruise/rollouts/pkg/util"
utilfeature "github.com/openkruise/rollouts/pkg/util/feature"
"github.com/openkruise/rollouts/pkg/util/grace"
)

var (
Expand All @@ -44,10 +47,11 @@ var (

type TrafficRoutingContext struct {
// only for log info
Key string
Namespace string
ObjectRef []v1beta1.TrafficRoutingRef
Strategy v1beta1.TrafficRoutingStrategy
Key string
Namespace string
ObjectRef []v1beta1.TrafficRoutingRef
Strategy v1beta1.TrafficRoutingStrategy
CanaryServiceSelectorPatch map[string]string
// OnlyTrafficRouting
OnlyTrafficRouting bool
OwnerRef metav1.OwnerReference
Expand Down Expand Up @@ -447,6 +451,13 @@ func (m *Manager) createCanaryService(c *TrafficRoutingContext, cService string,
for i := range canaryService.Spec.Ports {
canaryService.Spec.Ports[i].NodePort = 0
}
for key, val := range c.CanaryServiceSelectorPatch {
if _, ok := canaryService.Spec.Selector[key]; ok {
canaryService.Spec.Selector[key] = val
} else if utilfeature.DefaultFeatureGate.Enabled(feature.AppendServiceSelectorGate) {
canaryService.Spec.Selector[key] = val
}
}
err := m.Create(context.TODO(), canaryService)
if err != nil && !errors.IsAlreadyExists(err) {
klog.Errorf("%s create canary service(%s) failed: %s", c.Key, cService, err.Error())
Expand Down
Loading
0