Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit c5935f8

Browse files
authored
Merge pull request #327 from wondywang/service-sync
🐛 Fix servcie mutator, reset pService ClusterIPs
2 parents 1d8fa4e + 57587e5 commit c5935f8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

virtualcluster/pkg/syncer/conversion/mutate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ func (s *serviceMutator) Mutate(vService *v1.Service) {
428428
anno[constants.LabelClusterIP] = vService.Spec.ClusterIP
429429
s.pService.SetAnnotations(anno)
430430
s.pService.Spec.ClusterIP = ""
431+
s.pService.Spec.ClusterIPs = []string{}
431432
}
432433
s.pService.Spec.HealthCheckNodePort = 0
433434
for i := range s.pService.Spec.Ports {

virtualcluster/pkg/syncer/resources/service/dws_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ func tenantService(name, namespace, uid string) *corev1.Service {
4747
}
4848
}
4949

50+
func applyClusterIPToService(service *corev1.Service, clusterIP string) *corev1.Service {
51+
service.Spec.ClusterIP = clusterIP
52+
if service.Spec.ClusterIPs == nil {
53+
service.Spec.ClusterIPs = make([]string, 1)
54+
}
55+
service.Spec.ClusterIPs[0] = clusterIP
56+
return service
57+
}
58+
5059
func superService(name, namespace, uid, clusterKey string) *corev1.Service {
5160
return &corev1.Service{
5261
ObjectMeta: metav1.ObjectMeta{
@@ -89,6 +98,11 @@ func TestDWServiceCreation(t *testing.T) {
8998
ExistingObjectInTenant: tenantService("svc-1", "default", "12345"),
9099
ExpectedCreatedServices: []string{superDefaultNSName + "/svc-1"},
91100
},
101+
"new service with clusterIP": {
102+
ExistingObjectInSuper: []runtime.Object{},
103+
ExistingObjectInTenant: applyClusterIPToService(tenantService("svc-1", "default", "12345"), "1.1.1.1"),
104+
ExpectedCreatedServices: []string{superDefaultNSName + "/svc-1"},
105+
},
92106
"new service but already exists": {
93107
ExistingObjectInSuper: []runtime.Object{
94108
superService("svc-1", superDefaultNSName, "12345", defaultClusterKey),

0 commit comments

Comments
 (0)