Skip to content

Commit 02e9c57

Browse files
Merge pull request #2085 from lack/catalogsrc-pod-annotations
Copy all CatalogSource annotations to its Pod
2 parents b11215a + af2c558 commit 02e9c57

File tree

6 files changed

+42
-6
lines changed

6 files changed

+42
-6
lines changed

pkg/controller/operators/catalog/operator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ func toManifest(t *testing.T, obj runtime.Object) string {
14691469
}
14701470

14711471
func pod(s v1alpha1.CatalogSource) *corev1.Pod {
1472-
pod := reconciler.Pod(&s, "registry-server", s.Spec.Image, s.GetName(), s.GetLabels(), 5, 10)
1472+
pod := reconciler.Pod(&s, "registry-server", s.Spec.Image, s.GetName(), s.GetLabels(), s.GetAnnotations(), 5, 10)
14731473
ownerutil.AddOwner(pod, &s, false, false)
14741474
return pod
14751475
}

pkg/controller/registry/reconciler/configmap.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func (s *configMapCatalogSourceDecorator) Labels() map[string]string {
5858
return labels
5959
}
6060

61+
func (s *configMapCatalogSourceDecorator) Annotations() map[string]string {
62+
// TODO: Maybe something better than just a copy of all annotations would be to have a specific 'podMetadata' section in the CatalogSource?
63+
return s.GetAnnotations()
64+
}
65+
6166
func (s *configMapCatalogSourceDecorator) ConfigMapChanges(configMap *v1.ConfigMap) bool {
6267
if s.Status.ConfigMapResource == nil {
6368
return true
@@ -95,7 +100,7 @@ func (s *configMapCatalogSourceDecorator) Service() *v1.Service {
95100
}
96101

97102
func (s *configMapCatalogSourceDecorator) Pod(image string) *v1.Pod {
98-
pod := Pod(s.CatalogSource, "configmap-registry-server", image, "", s.Labels(), 5, 2)
103+
pod := Pod(s.CatalogSource, "configmap-registry-server", image, "", s.Labels(), s.Annotations(), 5, 2)
99104
pod.Spec.ServiceAccountName = s.GetName() + ConfigMapServerPostfix
100105
pod.Spec.Containers[0].Command = []string{"configmap-server", "-c", s.Spec.ConfigMap, "-n", s.GetNamespace()}
101106
ownerutil.AddOwner(pod, s.CatalogSource, false, false)

pkg/controller/registry/reconciler/grpc.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func (s *grpcCatalogSourceDecorator) Labels() map[string]string {
6262
}
6363
}
6464

65+
func (s *grpcCatalogSourceDecorator) Annotations() map[string]string {
66+
// TODO: Maybe something better than just a copy of all annotations would be to have a specific 'podMetadata' section in the CatalogSource?
67+
return s.GetAnnotations()
68+
}
69+
6570
func (s *grpcCatalogSourceDecorator) Service() *corev1.Service {
6671
svc := &corev1.Service{
6772
ObjectMeta: metav1.ObjectMeta{
@@ -115,7 +120,7 @@ func (s *grpcCatalogSourceDecorator) ServiceAccount() *corev1.ServiceAccount {
115120
}
116121

117122
func (s *grpcCatalogSourceDecorator) Pod(saName string) *corev1.Pod {
118-
pod := Pod(s.CatalogSource, "registry-server", s.Spec.Image, saName, s.Labels(), 5, 10)
123+
pod := Pod(s.CatalogSource, "registry-server", s.Spec.Image, saName, s.Labels(), s.Annotations(), 5, 10)
119124
ownerutil.AddOwner(pod, s.CatalogSource, false, false)
120125
return pod
121126
}

pkg/controller/registry/reconciler/grpc_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ func grpcCatalogSourceWithSecret(secretName string) *v1alpha1.CatalogSource {
5050
}
5151
}
5252

53+
func grpcCatalogSourceWithAnnotations(annotations map[string]string) *v1alpha1.CatalogSource {
54+
catsrc := validGrpcCatalogSource("image", "")
55+
catsrc.ObjectMeta.Annotations = annotations
56+
return catsrc
57+
}
58+
5359
func TestGrpcRegistryReconciler(t *testing.T) {
5460
now := func() metav1.Time { return metav1.Date(2018, time.January, 26, 20, 40, 0, 0, time.UTC) }
5561
blockOwnerDeletion := true
@@ -256,6 +262,24 @@ func TestGrpcRegistryReconciler(t *testing.T) {
256262
},
257263
},
258264
},
265+
{
266+
testName: "Grpc/NoExistingRegistry/CreateWithAnnotations",
267+
in: in{
268+
catsrc: grpcCatalogSourceWithAnnotations(map[string]string{
269+
"annotation1": "value1",
270+
"annotation2": "value2",
271+
}),
272+
},
273+
out: out{
274+
status: &v1alpha1.RegistryServiceStatus{
275+
CreatedAt: now(),
276+
Protocol: "grpc",
277+
ServiceName: "img-catalog",
278+
ServiceNamespace: testNamespace,
279+
Port: "50051",
280+
},
281+
},
282+
},
259283
}
260284
for _, tt := range tests {
261285
t.Run(tt.testName, func(t *testing.T) {
@@ -291,6 +315,7 @@ func TestGrpcRegistryReconciler(t *testing.T) {
291315
outPod := outPods.Items[0]
292316
require.Equal(t, pod.GetGenerateName(), outPod.GetGenerateName())
293317
require.Equal(t, pod.GetLabels(), outPod.GetLabels())
318+
require.Equal(t, pod.GetAnnotations(), outPod.GetAnnotations())
294319
require.Equal(t, pod.Spec, outPod.Spec)
295320
require.NoError(t, serviceErr)
296321
require.Equal(t, service, outService)

pkg/controller/registry/reconciler/reconciler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func NewRegistryReconcilerFactory(lister operatorlister.OperatorLister, opClient
9191
}
9292
}
9393

94-
func Pod(source *v1alpha1.CatalogSource, name string, image string, saName string, labels map[string]string, readinessDelay int32, livenessDelay int32) *v1.Pod {
94+
func Pod(source *v1alpha1.CatalogSource, name string, image string, saName string, labels map[string]string, annotations map[string]string, readinessDelay int32, livenessDelay int32) *v1.Pod {
9595
// Ensure the catalog image is always pulled if the image is not based on a digest, measured by whether an "@" is included.
9696
// See https://github.com/docker/distribution/blob/master/reference/reference.go for more info.
9797
// This means recreating non-digest based catalog pods will result in the latest version of the catalog content being delivered on-cluster.
@@ -107,6 +107,7 @@ func Pod(source *v1alpha1.CatalogSource, name string, image string, saName strin
107107
GenerateName: source.GetName() + "-",
108108
Namespace: source.GetNamespace(),
109109
Labels: labels,
110+
Annotations: annotations,
110111
},
111112
Spec: v1.PodSpec{
112113
Containers: []v1.Container{

pkg/controller/registry/reconciler/reconciler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestPodNodeSelector(t *testing.T) {
1919
key := "kubernetes.io/os"
2020
value := "linux"
2121

22-
gotCatSrcPod := Pod(catsrc, "hello", "busybox", "", map[string]string{}, int32(0), int32(0))
22+
gotCatSrcPod := Pod(catsrc, "hello", "busybox", "", map[string]string{}, map[string]string{}, int32(0), int32(0))
2323
gotCatSrcPodSelector := gotCatSrcPod.Spec.NodeSelector
2424

2525
if gotCatSrcPodSelector[key] != value {
@@ -67,7 +67,7 @@ func TestPullPolicy(t *testing.T) {
6767
}
6868

6969
for _, tt := range table {
70-
p := Pod(source, "catalog", tt.image, "", nil, int32(0), int32(0))
70+
p := Pod(source, "catalog", tt.image, "", nil, nil, int32(0), int32(0))
7171
policy := p.Spec.Containers[0].ImagePullPolicy
7272
if policy != tt.policy {
7373
t.Fatalf("expected pull policy %s for image %s", tt.policy, tt.image)

0 commit comments

Comments
 (0)