Skip to content
Closed
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: 0 additions & 1 deletion assets/defaults/cluster-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ apiVersion: ingress.openshift.io/v1alpha1
metadata:
name: default
namespace: openshift-cluster-ingress-operator
finalizers:
# Ensure that only the operator can delete the default cluster ingress object.
finalizers:
- ingress.openshift.io/default-cluster-ingress
Expand Down
4 changes: 2 additions & 2 deletions pkg/manifests/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 46 additions & 6 deletions pkg/stub/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,56 @@ func (h *Handler) EnsureDefaultClusterIngress() error {
return err
}

err = sdk.Create(ci)
if err == nil || errors.IsAlreadyExists(err) {
if err == nil {
logrus.Infof("created default cluster ingress %s/%s", ci.Namespace, ci.Name)
changed, nci, err := checkClusterIngress(ci)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can use: clusterIngressStatusEqual
from PR: #38

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not clusterIngressStatusEqual, but the part that compares .loadBalancer.Ingress could be factored into a function that could be used both by checkClusterIngress and by clusterIngressStatusEqual. Now that #47 is merged, I'll rebase #38 Tuesday and factor out a LoadBalancerStatusEqual function. No need for that to block this PR though; I can change checkClusterIngress to use LoadBalancerStatusEqual if #48 merges before #38 is ready.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err, actually, checkClusterIngress is comparing only .spec.ingressDomain (a string) whereas clusterIngressStatusEqual is comparing .status.loadBalancer (a slice of a struct that has two string values), so there is really no opportunity for code re-use here as far as I see.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be confused but if the LoadBalancerIngress struct are different as being checked in your PR [1] it means there's an update it should be enough for this purpouse.

[1] https://github.com/openshift/cluster-ingress-operator/pull/38/files#diff-9ae69f8dcadd8df44e0b10265f3a91a8R107

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're talking about

if ci.Spec.IngressDomain == nil {
return false, nil, fmt.Errorf("invalid ingress domain for default cluster ingress %s/%s", ci.Namespace, ci.Name)
}
if oldci.Spec.IngressDomain == nil {
oldci.Spec.IngressDomain = new(string)
}
if *oldci.Spec.IngressDomain != *ci.Spec.IngressDomain {
, right? There, we are comparing *string values in order to determine whether the old ClusterIngress and new ClusterIngress specify the same ingress domain. clusterIngressStatusEqual compares []LoadBalancerIngress values, where LoadBalancerIngress is struct { IP, Hostname string }, in order to determine whether the old ClusterIngressStatus and new ClusterIngressStatus have the same ingresses.

return err
}
if changed {
err = sdk.Update(nci)
if err != nil {
return fmt.Errorf("updating default cluster ingress %s/%s: %v", ci.Namespace, ci.Name, err)
}
logrus.Infof("updated default cluster ingress %s/%s", ci.Namespace, ci.Name)
} else if nci == nil {
err = sdk.Create(ci)
if err != nil {
return fmt.Errorf("creating default cluster ingress %s/%s: %v", ci.Namespace, ci.Name, err)
}
logrus.Infof("created default cluster ingress %s/%s", ci.Namespace, ci.Name)
}
return nil
}

return nil
func checkClusterIngress(ci *ingressv1alpha1.ClusterIngress) (bool, *ingressv1alpha1.ClusterIngress, error) {
oldci := &ingressv1alpha1.ClusterIngress{
TypeMeta: metav1.TypeMeta{
Kind: ci.Kind,
APIVersion: ci.APIVersion,
},
ObjectMeta: metav1.ObjectMeta{
Name: ci.Name,
Namespace: ci.Namespace,
},
}
err := sdk.Get(oldci)
if err != nil {
if !errors.IsNotFound(err) {
return false, nil, fmt.Errorf("failed to fetch existing default cluster ingress %s/%s, %v", ci.Namespace, ci.Name, err)
}
return false, nil, nil
}

return fmt.Errorf("creating default cluster ingress %s/%s: %v", ci.Namespace, ci.Name, err)
if ci.Spec.IngressDomain == nil {
return false, nil, fmt.Errorf("invalid ingress domain for default cluster ingress %s/%s", ci.Namespace, ci.Name)
}
if oldci.Spec.IngressDomain == nil {
oldci.Spec.IngressDomain = new(string)
}
if *oldci.Spec.IngressDomain != *ci.Spec.IngressDomain {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If either of this is nil will the function panic?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this https://play.golang.org/p/i0W49iA8Gjh and I didn't see an issue.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me fix this

*oldci.Spec.IngressDomain = *ci.Spec.IngressDomain
return true, oldci, nil
}
return false, oldci, nil
}

// Reconcile performs a full reconciliation loop for ingress, including
Expand Down