Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS-2317: Add Ingress LB IPs to Infra CR and set DNS unmanaged when BYO DNS is enabled #1016

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update GCPPlatformStatus with Ingress LB IPs when BYO DNS is enabled
sadasu committed Jan 31, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 009644a6b197b67f074cc34a07868ef01db31510
7 changes: 7 additions & 0 deletions manifests/00-cluster-role.yaml
Original file line number Diff line number Diff line change
@@ -119,6 +119,13 @@ rules:
- list
- watch

- apiGroups:
- config.openshift.io
resources:
- infrastructures/status
verbs:
- update

- apiGroups:
- config.openshift.io
resources:
59 changes: 56 additions & 3 deletions pkg/operator/controller/ingress/controller.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@ import (
"strings"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pkg/errors"

logf "github.com/openshift/cluster-ingress-operator/pkg/log"
@@ -1061,12 +1063,11 @@ func (r *reconciler) ensureIngressController(ci *operatorv1.IngressController, d
Controller: &trueVar,
}

var lbService *corev1.Service
var wildcardRecord *iov1.DNSRecord
if haveLB, lb, err := r.ensureLoadBalancerService(ci, deploymentRef, platformStatus); err != nil {
haveLB, lbService, err := r.ensureLoadBalancerService(ci, deploymentRef, platformStatus)
if err != nil {
errs = append(errs, fmt.Errorf("failed to ensure load balancer service for %s: %v", ci.Name, err))
} else {
lbService = lb
dnsRecordName := operatorcontroller.WildcardDNSRecordName(ci)
icRef := metav1.OwnerReference{
APIVersion: operatorv1.GroupVersion.String(),
@@ -1131,6 +1132,18 @@ func (r *reconciler) ensureIngressController(ci *operatorv1.IngressController, d

SetIngressControllerNLBMetric(ci)

// If the lbService exists for the "default" IngressController, then update Infra CR's PlatformStatus with the Ingress LB IPs.
if haveLB && ci.Name == manifests.DefaultIngressControllerName {
if updated, err := computeUpdatedInfraFromService(lbService, infraConfig); err != nil {
errs = append(errs, fmt.Errorf("failed to update Infrastructure PlatformStatus: %w", err))
} else if updated {
if err := r.client.Status().Update(context.TODO(), infraConfig); err != nil {
errs = append(errs, fmt.Errorf("failed to update Infrastructure CR after updating Ingress LB IPs: %w", err))
}
}
log.Info("successfully updated Infra CR with Ingress Load Balancer IPs")
}

errs = append(errs, r.syncRouteStatus(ci)...)

return retryable.NewMaybeRetryableAggregate(errs)
@@ -1205,3 +1218,43 @@ func (r *reconciler) allRouterPodsDeleted(ingress *operatorv1.IngressController)

return true, nil
}

// computeUpdatedInfraFromService updates GCP's PlatformStatus with Ingress LB IPs when the DNSType is `ClusterHosted`.
func computeUpdatedInfraFromService(service *corev1.Service, infraConfig *configv1.Infrastructure) (bool, error) {
platformStatus := infraConfig.Status.PlatformStatus
if platformStatus == nil {
return false, fmt.Errorf("invalid PlatformStatus within Infrastructure config")
}
switch platformStatus.Type {
case configv1.GCPPlatformType:
if platformStatus.GCP != nil && platformStatus.GCP.CloudLoadBalancerConfig != nil && platformStatus.GCP.CloudLoadBalancerConfig.DNSType == configv1.ClusterHostedDNSType {
// The cluster has to run its own CoreDNS pod for DNS. Update Infra CR
// with the Ingress LB IPs. These values are used to configure the
// in-cluster DNS to provide resolution for *.apps.
if platformStatus.GCP.CloudLoadBalancerConfig.ClusterHosted == nil {
platformStatus.GCP.CloudLoadBalancerConfig.ClusterHosted = &configv1.CloudLoadBalancerIPs{}
}
ingresses := service.Status.LoadBalancer.Ingress
ingressLBIPs := []configv1.IP{}
for _, ingress := range ingresses {
if len(ingress.IP) > 0 {
ingressLBIPs = append(ingressLBIPs, configv1.IP(ingress.IP))
}
}
ipCmpOpts := []cmp.Option{
cmpopts.EquateEmpty(),
cmpopts.SortSlices(func(a, b configv1.IP) bool {
return a < b
}),
}
if !cmp.Equal(platformStatus.GCP.CloudLoadBalancerConfig.ClusterHosted.IngressLoadBalancerIPs, ingressLBIPs, ipCmpOpts...) {
platformStatus.GCP.CloudLoadBalancerConfig.ClusterHosted.IngressLoadBalancerIPs = ingressLBIPs
return true, nil
}
}
return false, nil
default:
return false, nil
}
return false, nil
}