Skip to content

Commit 00aae12

Browse files
authored
Feature: copy annotations and labels from the stable service to the canary service (#301)
* copy annotations and labels from the stable service to the canary service Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com> * optimize code Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com> --------- Signed-off-by: AiRanthem <zhongtianyun.zty@alibaba-inc.com>
1 parent 87f7e65 commit 00aae12

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

pkg/trafficrouting/manager.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func (m *Manager) DoTrafficRouting(c *TrafficRoutingContext) (bool, error) {
154154
klog.Errorf("%s get canary service(%s) failed: %s", c.Key, canaryServiceName, err.Error())
155155
return false, err
156156
} else if errors.IsNotFound(err) {
157-
canaryService, err = m.createCanaryService(c, canaryServiceName, *stableService.Spec.DeepCopy())
157+
canaryService, err = m.createCanaryService(c, canaryServiceName, stableService)
158158
if err != nil {
159159
return false, err
160160
}
@@ -428,14 +428,16 @@ func newNetworkProvider(c client.Client, con *TrafficRoutingContext, sService, c
428428
return network.CompositeController(networkProviders), nil
429429
}
430430

431-
func (m *Manager) createCanaryService(c *TrafficRoutingContext, cService string, spec corev1.ServiceSpec) (*corev1.Service, error) {
431+
func (m *Manager) createCanaryService(c *TrafficRoutingContext, cService string, svc *corev1.Service) (*corev1.Service, error) {
432432
canaryService := &corev1.Service{
433433
ObjectMeta: metav1.ObjectMeta{
434434
Namespace: c.Namespace,
435435
Name: cService,
436436
OwnerReferences: []metav1.OwnerReference{c.OwnerRef},
437+
Annotations: svc.Annotations,
438+
Labels: svc.Labels,
437439
},
438-
Spec: spec,
440+
Spec: *svc.Spec.DeepCopy(),
439441
}
440442

441443
// set field nil

test/e2e/rollout_v1beta1_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5379,7 +5379,7 @@ var _ = SIGDescribe("Rollout v1beta1", func() {
53795379

53805380
KruiseDescribe("StatefulSet canary rollout with Ingress", func() {
53815381
KruiseDescribe("Native StatefulSet rollout canary with Ingress", func() {
5382-
It("V1->V2: Percentage, 20%,60% Succeeded", func() {
5382+
It("V1->V2: Percentage, 20%,60% Succeeded with canary service check", func() {
53835383
By("Creating Rollout...")
53845384
rollout := &v1beta1.Rollout{}
53855385
Expect(ReadYamlToObject("./test_data/rollout/rollout_v1beta1_partition_base.yaml", rollout)).ToNot(HaveOccurred())
@@ -5443,9 +5443,16 @@ var _ = SIGDescribe("Rollout v1beta1", func() {
54435443
Expect(workload.Status.UpdatedReplicas).Should(BeNumerically("==", 1))
54445444
Expect(workload.Status.ReadyReplicas).Should(BeNumerically("==", *workload.Spec.Replicas))
54455445
Expect(*workload.Spec.UpdateStrategy.RollingUpdate.Partition).Should(BeNumerically("==", *workload.Spec.Replicas-1))
5446-
By("check cloneSet status & paused success")
5446+
5447+
// check service metadata, once is enough
5448+
By("check canary service metadata")
5449+
canaryService := &v1.Service{}
5450+
Expect(GetObject(service.Name+"-canary", canaryService)).NotTo(HaveOccurred())
5451+
Expect(canaryService.Labels).To(BeEquivalentTo(service.Labels))
5452+
Expect(canaryService.Annotations).To(BeEquivalentTo(service.Annotations))
54475453

54485454
// check rollout status
5455+
By("check cloneSet status & paused success")
54495456
Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred())
54505457
Expect(rollout.Status.Phase).Should(Equal(v1beta1.RolloutPhaseProgressing))
54515458
Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(stableRevision))

0 commit comments

Comments
 (0)