Skip to content
Merged
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
75 changes: 46 additions & 29 deletions pkg/operator/controller/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func setDefaultDomain(ic *operatorv1.IngressController, ingressConfig *configv1.
}

func setDefaultPublishingStrategy(ic *operatorv1.IngressController, infraConfig *configv1.Infrastructure) bool {
effectiveStrategy := ic.Spec.EndpointPublishingStrategy
effectiveStrategy := ic.Spec.EndpointPublishingStrategy.DeepCopy()
if effectiveStrategy == nil {
var strategyType operatorv1.EndpointPublishingStrategyType
switch infraConfig.Status.Platform {
Expand Down Expand Up @@ -392,40 +392,57 @@ func setDefaultPublishingStrategy(ic *operatorv1.IngressController, infraConfig
return true
}

// Detect changes to GCP LB provider parameters, which is something we can safely roll out.
statusLB := ic.Status.EndpointPublishingStrategy.LoadBalancer
specLB := effectiveStrategy.LoadBalancer
if specLB != nil && statusLB != nil {
// If the ProviderParameters field does not exist for spec or status,
// just propagate (or remove) ProviderParameters in it's entirety
// (as long as GCP parameters are specified one way or the other).
if specLB.ProviderParameters == nil && statusLB.ProviderParameters != nil && statusLB.ProviderParameters.GCP != nil ||
specLB.ProviderParameters != nil && specLB.ProviderParameters.GCP != nil && statusLB.ProviderParameters == nil {
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters = specLB.ProviderParameters
// Detect changes to endpoint publishing strategy parameters that the
// operator can safely update.
switch effectiveStrategy.Type {
case operatorv1.LoadBalancerServiceStrategyType:
// Update if GCP LB provider parameters changed.
statusLB := ic.Status.EndpointPublishingStrategy.LoadBalancer
specLB := effectiveStrategy.LoadBalancer
if specLB != nil && statusLB != nil {
changed := false

// If the ProviderParameters field does not exist for spec or status,
// just propagate (or remove) ProviderParameters in its entirety
// (as long as GCP parameters are specified one way or the other).
if specLB.ProviderParameters == nil && statusLB.ProviderParameters != nil && statusLB.ProviderParameters.GCP != nil ||
specLB.ProviderParameters != nil && specLB.ProviderParameters.GCP != nil && statusLB.ProviderParameters == nil {
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters = specLB.ProviderParameters
changed = true
}

if specLB.ProviderParameters != nil && statusLB.ProviderParameters != nil &&
specLB.ProviderParameters.GCP != statusLB.ProviderParameters.GCP {
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.GCP = specLB.ProviderParameters.GCP
changed = true
}

return changed
}
case operatorv1.NodePortServiceStrategyType:
// Update if PROXY protocol is turned on or off.
if ic.Status.EndpointPublishingStrategy.NodePort == nil {
ic.Status.EndpointPublishingStrategy.NodePort = &operatorv1.NodePortStrategy{}
}
statusNP := ic.Status.EndpointPublishingStrategy.NodePort
specNP := effectiveStrategy.NodePort
if specNP != nil && specNP.Protocol != statusNP.Protocol {
Copy link
Contributor

Choose a reason for hiding this comment

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

I still have a question about this - if someone sets ic.Spec.EndpointPublishingStrategy.NodePort to nil (or removes it), then it won't update ic.Status nor return true here, will it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Line 375 initializes ic.Spec.EndpointPublishingStrategy.NodePort if it is nil. In fact, for that reason, we probably don't need the specNP != nil check anyway.

effectiveStrategy := ic.Spec.EndpointPublishingStrategy


case operatorv1.NodePortServiceStrategyType:
if effectiveStrategy.NodePort == nil {
effectiveStrategy.NodePort = &operatorv1.NodePortStrategy{}

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay. That had a code smell and I guess this explains it.

statusNP.Protocol = specNP.Protocol
return true
}

if specLB.ProviderParameters != nil && statusLB.ProviderParameters != nil &&
specLB.ProviderParameters.GCP != statusLB.ProviderParameters.GCP {
ic.Status.EndpointPublishingStrategy.LoadBalancer.ProviderParameters.GCP = specLB.ProviderParameters.GCP
case operatorv1.HostNetworkStrategyType:
// Update if PROXY protocol is turned on or off.
if ic.Status.EndpointPublishingStrategy.HostNetwork == nil {
ic.Status.EndpointPublishingStrategy.HostNetwork = &operatorv1.HostNetworkStrategy{}
}
statusHN := ic.Status.EndpointPublishingStrategy.HostNetwork
specHN := effectiveStrategy.HostNetwork
if specHN != nil && specHN.Protocol != statusHN.Protocol {
statusHN.Protocol = specHN.Protocol
return true
}
}

// Update if PROXY protocol is turned on or off.
statusNP := ic.Status.EndpointPublishingStrategy.NodePort
specNP := effectiveStrategy.NodePort
if specNP != nil && statusNP != nil && specNP.Protocol != statusNP.Protocol {
statusNP.Protocol = specNP.Protocol
return true
}
statusHN := ic.Status.EndpointPublishingStrategy.HostNetwork
specHN := effectiveStrategy.HostNetwork
if specHN != nil && statusHN != nil && specHN.Protocol != statusHN.Protocol {
statusHN.Protocol = specHN.Protocol
return true
}

return false
}

Expand Down
Loading