Commit afa9249a authored by Jack Henschel's avatar Jack Henschel
Browse files

Merge branch 'cern-4.9-dev' into 'cern-4.9'

Pass-through annotations and labels for services

See merge request !4
parents 72a9b458 5efa54e5
Pipeline #3928009 passed with stage
in 2 minutes and 18 seconds
......@@ -5,6 +5,52 @@ Openshift's ingress operator gives us very little flexibility for configuration
One issue in particular made it necessary to fork the upstream component and add our own modifications: the ability to modify Loadbalancer services created by the operator (we need to set specific annotations for Openstack) and the ability to selectively enable the PROXY protocol for specific router shards.
Details can be found in [okd4-install!703](https://gitlab.cern.ch/paas-tools/okd4-install/-/merge_requests/703).
In particular, the following IngressController configuration:
```yaml
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
name: apps-lb-1
annotations:
okd.cern.ch/service-annotations: |
{
"annotation1": "value1",
"annotation2": "value2"
}
okd.cern.ch/service-labels: |
{
"label1": "value1"
}
spec:
endpointPublishingStrategy:
type: LoadBalancerService
# [...]
```
will result in the creation of this Service resource:
```yaml
kind: Service
apiVersion: v1
metadata:
name: router-apps-lb-1
annotations:
loadbalancer.openstack.org/proxy-protocol: 'true'
annotation1: foo
annotation2: bar
labels:
ingresscontroller.operator.openshift.io/owning-ingresscontroller: apps-lb-1
router: router-apps-lb-1
label1: foo
spec:
externalTrafficPolicy: Local
type: LoadBalancer
# [...]
```
**Note**: this behavior is only implemented for `LoadBalancerService` ingresscontrollers, but not `HostNetwork` ICs.
The Gitlab repository is configured to automatically mirror the [upstream cluster-ingress-operator repository](https://github.com/openshift/cluster-ingress-operator).
Use the following workflow to port our custom patches to a new release:
......
......@@ -252,6 +252,30 @@ func desiredLoadBalancerService(ci *operatorv1.IngressController, deploymentRef
service.Annotations["loadbalancer.openstack.org/proxy-protocol"] = "true"
}
extraAnnotationsJson := ci.Annotations["okd.cern.ch/service-annotations"]
if extraAnnotationsJson != "" {
var extraAnnotations map[string]string
if err := json.Unmarshal([]byte(extraAnnotationsJson), &extraAnnotations); err != nil {
log.Error(err, "Failed to unmarshal content of okd.cern.ch/service-annotations")
} else {
for k, v := range extraAnnotations {
service.Annotations[k] = v
}
}
}
extraLabelsJson := ci.Annotations["okd.cern.ch/service-labels"]
if extraLabelsJson != "" {
var extraLabels map[string]string
if err := json.Unmarshal([]byte(extraLabelsJson), &extraLabels); err != nil {
log.Error(err, "Failed to unmarshal content of okd.cern.ch/service-labels")
} else {
for k, v := range extraLabels {
service.Labels[k] = v
}
}
}
if platform != nil {
if isInternal {
annotation := InternalLBAnnotations[platform.Type]
......@@ -456,11 +480,7 @@ var managedLoadBalancerServiceAnnotations = sets.NewString(
// loadBalancerServiceChanged checks if the current load balancer service
// matches the expected and if not returns an updated one.
func loadBalancerServiceChanged(current, expected *corev1.Service) (bool, *corev1.Service) {
annotationCmpOpts := []cmp.Option{
cmpopts.IgnoreMapEntries(func(k, _ string) bool {
return !managedLoadBalancerServiceAnnotations.Has(k)
}),
}
annotationCmpOpts := []cmp.Option{}
if cmp.Equal(current.Annotations, expected.Annotations, annotationCmpOpts...) {
return false, nil
}
......@@ -478,14 +498,15 @@ func loadBalancerServiceChanged(current, expected *corev1.Service) (bool, *corev
updated.Annotations = map[string]string{}
}
for annotation := range managedLoadBalancerServiceAnnotations {
currentVal, have := current.Annotations[annotation]
expectedVal, want := expected.Annotations[annotation]
if want && (!have || currentVal != expectedVal) {
updated.Annotations[annotation] = expected.Annotations[annotation]
} else if have && !want {
delete(updated.Annotations, annotation)
}
for annotation := range expected.Annotations {
updated.Annotations[annotation] = expected.Annotations[annotation]
}
if updated.Labels == nil {
updated.Labels = map[string]string{}
}
for label := range expected.Labels {
updated.Labels[label] = expected.Labels[label]
}
return true, updated
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment