diff --git a/pkg/trafficrouting/manager.go b/pkg/trafficrouting/manager.go index 6af6eced..beaa3a32 100644 --- a/pkg/trafficrouting/manager.go +++ b/pkg/trafficrouting/manager.go @@ -154,7 +154,7 @@ func (m *Manager) DoTrafficRouting(c *TrafficRoutingContext) (bool, error) { klog.Errorf("%s get canary service(%s) failed: %s", c.Key, canaryServiceName, err.Error()) return false, err } else if errors.IsNotFound(err) { - canaryService, err = m.createCanaryService(c, canaryServiceName, *stableService.Spec.DeepCopy()) + canaryService, err = m.createCanaryService(c, canaryServiceName, stableService) if err != nil { return false, err } @@ -428,14 +428,16 @@ func newNetworkProvider(c client.Client, con *TrafficRoutingContext, sService, c return network.CompositeController(networkProviders), nil } -func (m *Manager) createCanaryService(c *TrafficRoutingContext, cService string, spec corev1.ServiceSpec) (*corev1.Service, error) { +func (m *Manager) createCanaryService(c *TrafficRoutingContext, cService string, svc *corev1.Service) (*corev1.Service, error) { canaryService := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Namespace: c.Namespace, Name: cService, OwnerReferences: []metav1.OwnerReference{c.OwnerRef}, + Annotations: svc.Annotations, + Labels: svc.Labels, }, - Spec: spec, + Spec: *svc.Spec.DeepCopy(), } // set field nil diff --git a/test/e2e/rollout_v1beta1_test.go b/test/e2e/rollout_v1beta1_test.go index baf74fc7..200e4ac5 100644 --- a/test/e2e/rollout_v1beta1_test.go +++ b/test/e2e/rollout_v1beta1_test.go @@ -5379,7 +5379,7 @@ var _ = SIGDescribe("Rollout v1beta1", func() { KruiseDescribe("StatefulSet canary rollout with Ingress", func() { KruiseDescribe("Native StatefulSet rollout canary with Ingress", func() { - It("V1->V2: Percentage, 20%,60% Succeeded", func() { + It("V1->V2: Percentage, 20%,60% Succeeded with canary service check", func() { By("Creating Rollout...") rollout := &v1beta1.Rollout{} Expect(ReadYamlToObject("./test_data/rollout/rollout_v1beta1_partition_base.yaml", rollout)).ToNot(HaveOccurred()) @@ -5443,9 +5443,16 @@ var _ = SIGDescribe("Rollout v1beta1", func() { Expect(workload.Status.UpdatedReplicas).Should(BeNumerically("==", 1)) Expect(workload.Status.ReadyReplicas).Should(BeNumerically("==", *workload.Spec.Replicas)) Expect(*workload.Spec.UpdateStrategy.RollingUpdate.Partition).Should(BeNumerically("==", *workload.Spec.Replicas-1)) - By("check cloneSet status & paused success") + + // check service metadata, once is enough + By("check canary service metadata") + canaryService := &v1.Service{} + Expect(GetObject(service.Name+"-canary", canaryService)).NotTo(HaveOccurred()) + Expect(canaryService.Labels).To(BeEquivalentTo(service.Labels)) + Expect(canaryService.Annotations).To(BeEquivalentTo(service.Annotations)) // check rollout status + By("check cloneSet status & paused success") Expect(GetObject(rollout.Name, rollout)).NotTo(HaveOccurred()) Expect(rollout.Status.Phase).Should(Equal(v1beta1.RolloutPhaseProgressing)) Expect(rollout.Status.CanaryStatus.StableRevision).Should(Equal(stableRevision))