Skip to content

Commit

Permalink
fixup! fixup! Add fine-grain ingress DNS control through CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibault Jamet committed Dec 13, 2024
1 parent f130928 commit 849e8c8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
24 changes: 16 additions & 8 deletions helm-chart/traffic-controller/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ metadata:
namespace: {{ .Release.Namespace }}
name: "{{ .Release.Name }}-leader-election-role"
rules:
- apiGroups:
- ingress.adevinta.com
resources:
- "clusteringressservicednsweights"
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -58,6 +50,22 @@ metadata:
creationTimestamp: null
name: "{{ .Release.Name }}-manager-role"
rules:
- apiGroups:
- ingress.adevinta.com
resources:
- "clusteringressservicednsweights"
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- "services"
verbs:
- get
- list
- watch
- apiGroups:
- externaldns.k8s.io
resources:
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/ingress.adevinta.com/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package v1alpha1 contains API Schema definitions for the deployment v1alpha1 API group
// Package v1beta1 contains API Schema definitions for the deployment v1beta1 API group
// +kubebuilder:object:generate=true
// +groupName=ingress.adevinta.com
package v1beta1
Expand All @@ -10,7 +10,7 @@ import (

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "ingress.adevinta.com", Version: "v1alpha1"}
GroupVersion = schema.GroupVersion{Group: "ingress.adevinta.com", Version: "v1beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
Expand Down
14 changes: 13 additions & 1 deletion pkg/controllers/ingress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ func (r *IngressReconciler) addIngressTargetsToEndpoint(endpoint *externaldnsk8s
}
}

func (r *IngressReconciler) addServiceTargetsToEndpoint(endpoint *externaldnsk8siov1alpha1.Endpoint, service *v1.Service) {
for _, lb := range service.Status.LoadBalancer.Ingress {
if lb.Hostname != "" {
hostName := lb.Hostname
if r.DevMode {
hostName = "devmode"
}
endpoint.Targets = append(endpoint.Targets, hostName)
}
}
}

func (r *IngressReconciler) listClusterIngressServiceDNSWeightsForIngress(ctx context.Context, ingress *netv1.Ingress) ([]ingressv1beta1.ClusterIngressServiceDNSWeight, error) {
clusterIngressServiceDNSWeights := &ingressv1beta1.ClusterIngressServiceDNSWeightList{}
err := r.List(ctx, clusterIngressServiceDNSWeights)
Expand Down Expand Up @@ -232,7 +244,7 @@ func (r *IngressReconciler) addCRDsTargetsToEndpoint(ctx context.Context, dnsEnd
RecordType: "CNAME",
SetIdentifier: clusterIngressServiceDNSWeight.Spec.Identifier,
}
r.addIngressTargetsToEndpoint(ep, ingress)
r.addServiceTargetsToEndpoint(ep, &service)

endpointWeight := ingressDNSWeight * clusterIngressServiceDNSWeight.Spec.Weight / 100

Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/ingress_controller_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func TestAddCRDsTargetsToDNSEndpoint(t *testing.T) {
MockService(
WithObjectName[*v1.Service]("service-1"), WithObjectNamespace[*v1.Service]("test-namespace"),
WithObjectLabels[*v1.Service](map[string]string{"test-key": "test-value"}),
WithServiceLoadBalancerHostnames("bar-celona"),
WithServiceLoadBalancerHostnames("service-lb"),
),
).Build()
r := IngressReconciler{
Expand All @@ -404,7 +404,7 @@ func TestAddCRDsTargetsToDNSEndpoint(t *testing.T) {
assert.Equal(t, "www.example.com", dnsEndpoint.Spec.Endpoints[1].DNSName)
for _, e := range dnsEndpoint.Spec.Endpoints {
assert.Equal(t, "30", e.ProviderSpecific[0].Value)
assert.Equal(t, endpoint.Targets{"bar-celona"}, e.Targets)
assert.Equal(t, endpoint.Targets{"service-lb"}, e.Targets)
assert.Equal(t, WeightProperty, e.ProviderSpecific[0].Name)
}
})
Expand Down

0 comments on commit 849e8c8

Please sign in to comment.