Skip to content

Commit 1c44104

Browse files
authored
Merge pull request #631 from johscheuer/move-labels-outside-of-controllers
Move labels into api package
2 parents 7b5d775 + 3dd668f commit 1c44104

35 files changed

+303
-294
lines changed

api/v1beta1/foundationdb_labels.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* foundationdb_labels.go
3+
*
4+
* This source file is part of the FoundationDB open source project
5+
*
6+
* Copyright 2021 Apple Inc. and the FoundationDB project authors
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package v1beta1
22+
23+
const (
24+
// LastSpecKey provides the annotation name we use to store the hash of the
25+
// pod spec.
26+
LastSpecKey = "foundationdb.org/last-applied-spec"
27+
28+
// LastConfigMapKey provides the annotation name we use to store the hash of the
29+
// config map.
30+
LastConfigMapKey = "foundationdb.org/last-applied-config-map"
31+
32+
// BackupDeploymentLabel provides the label we use to connect backup
33+
// deployments to a cluster.
34+
BackupDeploymentLabel = "foundationdb.org/backup-for"
35+
36+
// PublicIPSourceAnnotation is an annotation key that specifies where a pod
37+
// gets its public IP from.
38+
PublicIPSourceAnnotation = "foundationdb.org/public-ip-source"
39+
40+
// PublicIPAnnotation is an annotation key that specifies the current public
41+
// IP for a pod.
42+
PublicIPAnnotation = "foundationdb.org/public-ip"
43+
44+
// FDBInstanceIDLabel represents the label that is used to represent a instance ID
45+
FDBInstanceIDLabel = "fdb-instance-id"
46+
47+
// FDBProcessClassLabel represents the label that is used to represent the process class
48+
FDBProcessClassLabel = "fdb-process-class"
49+
50+
// FDBClusterLabel represents the label that is used to represent the cluster of an instance
51+
FDBClusterLabel = "fdb-cluster-name"
52+
53+
// NodeSelectorNoScheduleLabel is a label used when adding node selectors to block scheduling.
54+
NodeSelectorNoScheduleLabel = "foundationdb.org/no-schedule-allowed"
55+
56+
// FDBLocalityInstanceIDKey represents the key in the locality map that
57+
// holds the instance ID.
58+
FDBLocalityInstanceIDKey = "instance_id"
59+
60+
// FDBLocalityZoneIDKey represents the key in the locality map that holds
61+
// the zone ID.
62+
FDBLocalityZoneIDKey = "zoneid"
63+
64+
// FDBLocalityDCIDKey represents the key in the locality map that holds
65+
// the DC ID.
66+
FDBLocalityDCIDKey = "dcid"
67+
)

controllers/add_pods.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (a AddPods) Reconcile(r *FoundationDBClusterReconciler, context ctx.Context
8181
return false, err
8282
}
8383

84-
pod.ObjectMeta.Annotations[LastConfigMapKey] = configMapHash
84+
pod.ObjectMeta.Annotations[fdbtypes.LastConfigMapKey] = configMapHash
8585

8686
if *cluster.Spec.Services.PublicIPSource == fdbtypes.PublicIPSourceService {
8787
service := &corev1.Service{}
@@ -94,7 +94,7 @@ func (a AddPods) Reconcile(r *FoundationDBClusterReconciler, context ctx.Context
9494
log.Info("Service does not have an IP address", "namespace", cluster.Namespace, "cluster", cluster.Name, "podName", pod.Name)
9595
return false, nil
9696
}
97-
pod.Annotations[PublicIPAnnotation] = ip
97+
pod.Annotations[fdbtypes.PublicIPAnnotation] = ip
9898
}
9999

100100
err = r.PodLifecycleManager.CreateInstance(r, context, pod)

controllers/add_pods_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ var _ = Describe("add_pods", func() {
9595
Expect(newPods.Items).To(HaveLen(len(initialPods.Items) + 1))
9696
lastPod := newPods.Items[len(newPods.Items)-1]
9797
Expect(lastPod.Name).To(Equal("operator-test-1-storage-9"))
98-
Expect(lastPod.Labels[FDBInstanceIDLabel]).To(Equal("storage-9"))
99-
Expect(lastPod.Labels[FDBProcessClassLabel]).To(Equal("storage"))
98+
Expect(lastPod.Labels[fdbtypes.FDBInstanceIDLabel]).To(Equal("storage-9"))
99+
Expect(lastPod.Labels[fdbtypes.FDBProcessClassLabel]).To(Equal("storage"))
100100
Expect(lastPod.OwnerReferences).To(Equal(buildOwnerReference(cluster.TypeMeta, cluster.ObjectMeta)))
101101
})
102102

controllers/add_pvcs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ var _ = Describe("add_pvcs", func() {
9595
Expect(newPVCs.Items).To(HaveLen(len(initialPVCs.Items) + 1))
9696
lastPVC := newPVCs.Items[len(newPVCs.Items)-1]
9797
Expect(lastPVC.Name).To(Equal("operator-test-1-storage-9-data"))
98-
Expect(lastPVC.Labels[FDBInstanceIDLabel]).To(Equal("storage-9"))
99-
Expect(lastPVC.Labels[FDBProcessClassLabel]).To(Equal("storage"))
98+
Expect(lastPVC.Labels[fdbtypes.FDBInstanceIDLabel]).To(Equal("storage-9"))
99+
Expect(lastPVC.Labels[fdbtypes.FDBProcessClassLabel]).To(Equal("storage"))
100100

101101
Expect(lastPVC.OwnerReferences).To(Equal(buildOwnerReference(cluster.TypeMeta, cluster.ObjectMeta)))
102102
})

controllers/add_services.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func GetHeadlessService(cluster *fdbtypes.FoundationDBCluster) *corev1.Service {
107107
}
108108
service.ObjectMeta.Name = cluster.ObjectMeta.Name
109109
service.Spec.ClusterIP = "None"
110-
service.Spec.Selector = map[string]string{FDBClusterLabel: cluster.Name}
110+
service.Spec.Selector = map[string]string{fdbtypes.FDBClusterLabel: cluster.Name}
111111

112112
return service
113113
}

controllers/add_services_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ var _ = Describe("add_services", func() {
9999
Expect(newServices.Items).To(HaveLen(len(initialServices.Items) + 1))
100100
lastService := newServices.Items[len(newServices.Items)-1]
101101
Expect(lastService.Name).To(Equal("operator-test-1-storage-9"))
102-
Expect(lastService.Labels[FDBInstanceIDLabel]).To(Equal("storage-9"))
103-
Expect(lastService.Labels[FDBProcessClassLabel]).To(Equal("storage"))
102+
Expect(lastService.Labels[fdbtypes.FDBInstanceIDLabel]).To(Equal("storage-9"))
103+
Expect(lastService.Labels[fdbtypes.FDBProcessClassLabel]).To(Equal("storage"))
104104
Expect(lastService.Spec.ClusterIP).NotTo(Equal("None"))
105105
Expect(lastService.OwnerReferences).To(Equal(buildOwnerReference(cluster.TypeMeta, cluster.ObjectMeta)))
106106
})
@@ -154,7 +154,7 @@ var _ = Describe("add_services", func() {
154154
firstService := newServices.Items[0]
155155

156156
Expect(firstService.Name).To(Equal("operator-test-1"))
157-
Expect(firstService.Labels[FDBInstanceIDLabel]).To(Equal(""))
157+
Expect(firstService.Labels[fdbtypes.FDBInstanceIDLabel]).To(Equal(""))
158158
Expect(firstService.Spec.ClusterIP).To(Equal("None"))
159159
})
160160

controllers/admin_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (client *CliAdminClient) runCommand(command cliCommand) (string, error) {
229229

230230
args = append(args, command.getClusterFileFlag(), client.clusterFilePath, "--log")
231231
if command.hasTimeoutArg() {
232-
args = append(args, "--timeout", fmt.Sprintf("%d", DefaultCLITimeout))
232+
args = append(args, "--timeout", strconv.Itoa(DefaultCLITimeout))
233233
hardTimeout += DefaultCLITimeout
234234
}
235235
if command.hasDashInLogDir() {

controllers/change_coordinators.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ func (c ChangeCoordinators) Reconcile(r *FoundationDBClusterReconciler, context
8989

9090
candidates := make([]localityInfo, 0, len(status.Cluster.Processes))
9191
for _, process := range status.Cluster.Processes {
92-
eligible := !process.Excluded && isStateful(process.ProcessClass) && !cluster.InstanceIsBeingRemoved(process.Locality[FDBInstanceIDLabel])
92+
eligible := !process.Excluded && isStateful(process.ProcessClass) && !cluster.InstanceIsBeingRemoved(process.Locality[fdbtypes.FDBInstanceIDLabel])
9393
if eligible {
9494
candidates = append(candidates, localityInfoForProcess(process))
9595
}
9696
}
9797

9898
coordinatorCount := cluster.DesiredCoordinatorCount()
9999
coordinators, err := chooseDistributedProcesses(candidates, coordinatorCount, processSelectionConstraint{
100-
HardLimits: map[string]int{FDBLocalityZoneIDKey: 1},
100+
HardLimits: map[string]int{fdbtypes.FDBLocalityZoneIDKey: 1},
101101
})
102102
if err != nil {
103103
return false, err

controllers/choose_removals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (c ChooseRemovals) Reconcile(r *FoundationDBClusterReconciler, context ctx.
6161
}
6262
localityMap := make(map[string]localityInfo)
6363
for _, process := range status.Cluster.Processes {
64-
id := process.Locality[FDBLocalityInstanceIDKey]
64+
id := process.Locality[fdbtypes.FDBLocalityInstanceIDKey]
6565
localityMap[id] = localityInfo{ID: id, Address: process.Address, LocalityData: process.Locality}
6666
}
6767

controllers/choose_removals_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ var _ = Describe("choose_removals", func() {
110110

111111
Context("with multiple processes on one rack", func() {
112112
BeforeEach(func() {
113-
adminClient.MockLocalityInfo("storage-1", map[string]string{FDBLocalityZoneIDKey: "r1"})
114-
adminClient.MockLocalityInfo("storage-2", map[string]string{FDBLocalityZoneIDKey: "r1"})
113+
adminClient.MockLocalityInfo("storage-1", map[string]string{fdbtypes.FDBLocalityZoneIDKey: "r1"})
114+
adminClient.MockLocalityInfo("storage-2", map[string]string{fdbtypes.FDBLocalityZoneIDKey: "r1"})
115115
})
116116

117117
It("should not requeue", func() {

0 commit comments

Comments
 (0)