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

🐛 Fix servcie mutator, reset pService ClusterIPs #327

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions virtualcluster/pkg/syncer/conversion/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ func (s *serviceMutator) Mutate(vService *v1.Service) {
anno[constants.LabelClusterIP] = vService.Spec.ClusterIP
s.pService.SetAnnotations(anno)
s.pService.Spec.ClusterIP = ""
s.pService.Spec.ClusterIPs = []string{}
}
s.pService.Spec.HealthCheckNodePort = 0
for i := range s.pService.Spec.Ports {
Expand Down
14 changes: 14 additions & 0 deletions virtualcluster/pkg/syncer/resources/service/dws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ func tenantService(name, namespace, uid string) *corev1.Service {
}
}

func applyClusterIPToService(service *corev1.Service, clusterIP string) *corev1.Service {
service.Spec.ClusterIP = clusterIP
if service.Spec.ClusterIPs == nil {
service.Spec.ClusterIPs = make([]string, 1)
}
service.Spec.ClusterIPs[0] = clusterIP
return service
}

func superService(name, namespace, uid, clusterKey string) *corev1.Service {
return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -89,6 +98,11 @@ func TestDWServiceCreation(t *testing.T) {
ExistingObjectInTenant: tenantService("svc-1", "default", "12345"),
ExpectedCreatedServices: []string{superDefaultNSName + "/svc-1"},
},
"new service with clusterIP": {
ExistingObjectInSuper: []runtime.Object{},
ExistingObjectInTenant: applyClusterIPToService(tenantService("svc-1", "default", "12345"), "1.1.1.1"),
ExpectedCreatedServices: []string{superDefaultNSName + "/svc-1"},
},
"new service but already exists": {
ExistingObjectInSuper: []runtime.Object{
superService("svc-1", superDefaultNSName, "12345", defaultClusterKey),
Expand Down