Skip to content

Commit 21dd386

Browse files
committed
More Label-Selector support
The label-selector flag needs to get exposed as a config value, and the leader election needs to be independent per label.
1 parent 016d31d commit 21dd386

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

charts/openstack-hypervisor-operator/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: openstack-hypervisor-operator
33
description: A Helm chart for Kubernetes
44
appVersion: 0.1.0
5-
version: 0.1.8
5+
version: 0.2.0
66
type: application

charts/openstack-hypervisor-operator/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ spec:
3939
secretKeyRef:
4040
key: SERVICE_PASSWORD
4141
name: {{ include "openstack-hypervisor-operator.fullname" . }}-secret
42+
- name: LABEL_SELECTOR
43+
value: {{ quote .Values.controllerManager.manager.env.labelSelector }}
4244
- name: KUBERNETES_CLUSTER_DOMAIN
4345
value: {{ quote .Values.kubernetesClusterDomain }}
4446
image: {{ .Values.controllerManager.manager.image.repository }}:{{ .Values.controllerManager.manager.image.tag

charts/openstack-hypervisor-operator/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ controllerManager:
44
- --metrics-bind-address=:8443
55
- --leader-elect
66
- --health-probe-bind-address=:8081
7+
- --label-selector=${LABEL_SELECTOR}
78
containerSecurityContext:
89
allowPrivilegeEscalation: false
910
capabilities:
1011
drop:
1112
- ALL
1213
env:
14+
labelSelector: ""
1315
osAuthUrl: ""
1416
osProjectDomainName: ""
1517
osProjectName: ""

cmd/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ limitations under the License.
1818
package main
1919

2020
import (
21+
"crypto/sha256"
2122
"crypto/tls"
2223
"flag"
2324
"fmt"
@@ -162,6 +163,7 @@ func main() {
162163
bininfo.Component(), bininfo.VersionOr("devel"), gruntime.GOOS, gruntime.GOARCH,
163164
bininfo.CommitOr("edge"))
164165

166+
leaderElectionID := "4c28796a.cloud.sap"
165167
var cacheOptions cache.Options
166168
if global.LabelSelector != "" {
167169
setupLog.Info("setting up cache with label selector", "selector", global.LabelSelector)
@@ -182,6 +184,11 @@ func main() {
182184
},
183185
},
184186
}
187+
188+
h := sha256.New()
189+
h.Write([]byte(leaderElectionID)) // Seed it with something "unique" to the project
190+
h.Write([]byte(global.LabelSelector))
191+
leaderElectionID = fmt.Sprintf("%x.cloud.sap", h.Sum(nil))
185192
}
186193

187194
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
@@ -190,7 +197,7 @@ func main() {
190197
WebhookServer: webhookServer,
191198
HealthProbeBindAddress: probeAddr,
192199
LeaderElection: enableLeaderElection,
193-
LeaderElectionID: "4c28796a.cloud.sap",
200+
LeaderElectionID: leaderElectionID,
194201
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
195202
// when the Manager ends. This requires the binary to immediately end when the
196203
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly

config/manager/manager.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ spec:
6161
- args:
6262
- --leader-elect
6363
- --health-probe-bind-address=:8081
64+
- --label-selector=${LABEL_SELECTOR}
6465
env:
6566
- name: OS_AUTH_URL
6667
- name: OS_PROJECT_DOMAIN_NAME
@@ -73,6 +74,7 @@ spec:
7374
secretKeyRef:
7475
name: secret
7576
key: SERVICE_PASSWORD
77+
- name: LABEL_SELECTOR
7678
image: keppel.eu-de-1.cloud.sap/ccloud/openstack-hypervisor-operator:latest
7779
name: manager
7880
securityContext:

0 commit comments

Comments
 (0)