Skip to content

Commit

Permalink
Merge pull request #1592 from rohantmp/fixDualStack
Browse files Browse the repository at this point in the history
fix: IPFamilyPolicy not synced for default vcluster service
  • Loading branch information
FabianKramm authored Mar 14, 2024
2 parents 416b991 + cb6ced0 commit 245784c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pkg/specialservices/proxy_service_syncer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package specialservices

import (
"slices"

synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context"
"github.com/loft-sh/vcluster/pkg/util/translate"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -71,11 +73,12 @@ func SyncVclusterProxyService(ctx *synccontext.SyncContext,
return err
}

if vObj.Spec.ClusterIP != pObj.Spec.ClusterIP || !equality.Semantic.DeepEqual(vObj.Spec.ClusterIPs, pObj.Spec.ClusterIPs) {
if vObj.Spec.ClusterIP != pObj.Spec.ClusterIP || !slices.Equal(vObj.Spec.ClusterIPs, pObj.Spec.ClusterIPs) {
newService := vObj.DeepCopy()
newService.Spec.ClusterIP = pObj.Spec.ClusterIP
newService.Spec.ClusterIPs = pObj.Spec.ClusterIPs
newService.Spec.IPFamilies = pObj.Spec.IPFamilies
newService.Spec.IPFamilyPolicy = pObj.Spec.IPFamilyPolicy

// delete & create with correct ClusterIP
err = vClient.Delete(ctx.Context, vObj)
Expand Down
10 changes: 8 additions & 2 deletions pkg/specialservices/service_syncer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package specialservices

import (
"slices"

synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context"
corev1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -53,14 +55,18 @@ func SyncKubernetesService(
return err
}

// detect if cluster ips changed
clusterIPsChanged := vObj.Spec.ClusterIP != pObj.Spec.ClusterIP || !slices.Equal(vObj.Spec.ClusterIPs, pObj.Spec.ClusterIPs)

translatedPorts := svcPortTranslator(pObj.Spec.Ports)
if vObj.Spec.ClusterIP != pObj.Spec.ClusterIP || !equality.Semantic.DeepEqual(vObj.Spec.Ports, translatedPorts) {
if clusterIPsChanged || !equality.Semantic.DeepEqual(vObj.Spec.Ports, translatedPorts) {
newService := vObj.DeepCopy()
newService.Spec.ClusterIP = pObj.Spec.ClusterIP
newService.Spec.ClusterIPs = pObj.Spec.ClusterIPs
newService.Spec.IPFamilies = pObj.Spec.IPFamilies
newService.Spec.IPFamilyPolicy = pObj.Spec.IPFamilyPolicy
newService.Spec.Ports = translatedPorts
if vObj.Spec.ClusterIP != pObj.Spec.ClusterIP || !equality.Semantic.DeepEqual(vObj.Spec.ClusterIPs, pObj.Spec.ClusterIPs) {
if clusterIPsChanged {
// delete & create with correct ClusterIP
err = ctx.VirtualClient.Delete(ctx.Context, vObj)
if err != nil {
Expand Down

0 comments on commit 245784c

Please sign in to comment.