Skip to content

Commit

Permalink
Merge pull request #382 from FabianKramm/main
Browse files Browse the repository at this point in the history
refactor: spec.loadBalancerSourceRanges from vcluster
  • Loading branch information
FabianKramm authored Feb 17, 2022
2 parents 8c89bf3 + e66b639 commit a666f0d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
35 changes: 18 additions & 17 deletions pkg/controllers/resources/services/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestSync(t *testing.T) {
ExternalName: "external",
ExternalTrafficPolicy: corev1.ServiceExternalTrafficPolicyTypeLocal,
SessionAffinity: corev1.ServiceAffinityClientIP,
LoadBalancerSourceRanges: []string{"backwardRange"},
SessionAffinityConfig: &corev1.SessionAffinityConfig{
ClientIP: &corev1.ClientIPConfig{},
},
Expand Down Expand Up @@ -94,17 +95,15 @@ func TestSync(t *testing.T) {
Spec: updateForwardSpec,
}
updateBackwardSpec := corev1.ServiceSpec{
ExternalName: "backwardExternal",
ExternalIPs: []string{"123:221:123:221"},
LoadBalancerIP: "123:213:123:213",
LoadBalancerSourceRanges: []string{"backwardRange"},
ExternalName: "backwardExternal",
ExternalIPs: []string{"123:221:123:221"},
LoadBalancerIP: "123:213:123:213",
}
updateBackwardRecreateSpec := corev1.ServiceSpec{
ClusterIP: "123:123:123:123",
ExternalName: updateBackwardSpec.ExternalName,
ExternalIPs: updateBackwardSpec.ExternalIPs,
LoadBalancerIP: updateBackwardSpec.LoadBalancerIP,
LoadBalancerSourceRanges: updateBackwardSpec.LoadBalancerSourceRanges,
ClusterIP: "123:123:123:123",
ExternalName: updateBackwardSpec.ExternalName,
ExternalIPs: updateBackwardSpec.ExternalIPs,
LoadBalancerIP: updateBackwardSpec.LoadBalancerIP,
}
updateBackwardSpecService := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -113,17 +112,20 @@ func TestSync(t *testing.T) {
Labels: pObjectMeta.Labels,
Annotations: pObjectMeta.Annotations,
},
Spec: updateBackwardSpec,
Spec: corev1.ServiceSpec{
ExternalName: "backwardExternal",
ExternalIPs: []string{"123:221:123:221"},
LoadBalancerIP: "123:213:123:213",
},
}
updatedBackwardSpecService := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: vObjectMeta.Name,
Namespace: vObjectMeta.Namespace,
},
Spec: corev1.ServiceSpec{
ExternalIPs: []string{"123:221:123:221"},
LoadBalancerIP: "123:213:123:213",
LoadBalancerSourceRanges: []string{"backwardRange"},
ExternalIPs: []string{"123:221:123:221"},
LoadBalancerIP: "123:213:123:213",
},
}
updateBackwardSpecRecreateService := &corev1.Service{
Expand All @@ -142,10 +144,9 @@ func TestSync(t *testing.T) {
ClusterName: vObjectMeta.ClusterName,
},
Spec: corev1.ServiceSpec{
ClusterIP: "123:123:123:123",
ExternalIPs: []string{"123:221:123:221"},
LoadBalancerIP: "123:213:123:213",
LoadBalancerSourceRanges: []string{"backwardRange"},
ClusterIP: "123:123:123:123",
ExternalIPs: []string{"123:221:123:221"},
LoadBalancerIP: "123:213:123:213",
},
}
updateBackwardStatus := corev1.ServiceStatus{
Expand Down
11 changes: 6 additions & 5 deletions pkg/controllers/resources/services/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ func (s *serviceSyncer) translateUpdateBackwards(pObj, vObj *corev1.Service) *co
updated.Spec.LoadBalancerIP = pObj.Spec.LoadBalancerIP
}

if !equality.Semantic.DeepEqual(vObj.Spec.LoadBalancerSourceRanges, pObj.Spec.LoadBalancerSourceRanges) {
updated = newIfNil(updated, vObj)
updated.Spec.LoadBalancerSourceRanges = pObj.Spec.LoadBalancerSourceRanges
}

// check if we need to sync node ports from host to virtual
if portsEqual(pObj, vObj) && !equality.Semantic.DeepEqual(vObj.Spec.Ports, pObj.Spec.Ports) {
updated = newIfNil(updated, vObj)
Expand Down Expand Up @@ -124,6 +119,12 @@ func (s *serviceSyncer) translateUpdate(pObj, vObj *corev1.Service) *corev1.Serv
updated.Spec.SessionAffinityConfig = vObj.Spec.SessionAffinityConfig
}

// load balancer source ranges
if !equality.Semantic.DeepEqual(vObj.Spec.LoadBalancerSourceRanges, pObj.Spec.LoadBalancerSourceRanges) {
updated = newIfNil(updated, pObj)
updated.Spec.LoadBalancerSourceRanges = vObj.Spec.LoadBalancerSourceRanges
}

// healthCheckNodePort
if vObj.Spec.HealthCheckNodePort != pObj.Spec.HealthCheckNodePort {
updated = newIfNil(updated, pObj)
Expand Down

0 comments on commit a666f0d

Please sign in to comment.