Skip to content

Commit d9c94c9

Browse files
committed
Add logging and reduce the amount of metadata in the TransformFunc
Signed-off-by: Todd Short <[email protected]>
1 parent 443a4f2 commit d9c94c9

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pkg/controller/operators/olm/operator.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,24 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
338338
Spec: v1alpha1.ClusterServiceVersionSpec{},
339339
Status: v1alpha1.ClusterServiceVersionStatus{},
340340
}
341-
if csv.Annotations == nil {
342-
csv.Annotations = make(map[string]string, 2)
341+
// copy only the nececessary labels
342+
labels := csv.Labels
343+
csv.Labels = make(map[string]string, 2)
344+
if l, ok := labels[v1alpha1.CopiedLabelKey]; ok {
345+
csv.Labels[v1alpha1.CopiedLabelKey] = l
346+
}
347+
if l, ok := labels[install.OLMManagedLabelKey]; ok {
348+
csv.Labels[install.OLMManagedLabelKey] = l
349+
}
350+
351+
// copy only the nececessary annotations
352+
annotations := csv.Annotations
353+
csv.Annotations = make(map[string]string, 4)
354+
if a, ok := annotations[operatorsv1.OperatorGroupAnnotationKey]; ok {
355+
csv.Annotations[operatorsv1.OperatorGroupAnnotationKey] = a
356+
}
357+
if a, ok := annotations[operatorsv1.OperatorGroupNamespaceAnnotationKey]; ok {
358+
csv.Annotations[operatorsv1.OperatorGroupNamespaceAnnotationKey] = a
343359
}
344360
// fake CSV hashes for tracking purposes only
345361
csv.Annotations[copyCSVSpecHash] = specHash

pkg/controller/operators/olm/operatorgroup.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,11 @@ func (a *Operator) copyToNamespace(prototype *v1alpha1.ClusterServiceVersion, ns
812812
if _, err := a.client.OperatorsV1alpha1().ClusterServiceVersions(nsTo).UpdateStatus(context.TODO(), created, metav1.UpdateOptions{}); err != nil {
813813
return nil, fmt.Errorf("failed to update status on new CSV: %w", err)
814814
}
815+
a.logger.WithFields(logrus.Fields{
816+
"nsFrom": nsFrom,
817+
"nsTo": nsTo,
818+
"csv": prototype.Name,
819+
}).Info("copyToNamespace: created")
815820
return &v1alpha1.ClusterServiceVersion{
816821
ObjectMeta: metav1.ObjectMeta{
817822
Name: created.Name,
@@ -838,6 +843,7 @@ func (a *Operator) copyToNamespace(prototype *v1alpha1.ClusterServiceVersion, ns
838843
a.logger.WithFields(logrus.Fields{
839844
"nsFrom": nsFrom,
840845
"nsTo": nsTo,
846+
"csv": updated.Name,
841847
}).Info("copyToNamespace: updated Metadata+Spec")
842848
} else {
843849
// Avoid mutating cached copied CSV.
@@ -852,6 +858,7 @@ func (a *Operator) copyToNamespace(prototype *v1alpha1.ClusterServiceVersion, ns
852858
a.logger.WithFields(logrus.Fields{
853859
"nsFrom": nsFrom,
854860
"nsTo": nsTo,
861+
"csv": updated.Name,
855862
}).Info("copyToNamespace: updated Status")
856863
}
857864
return &v1alpha1.ClusterServiceVersion{

0 commit comments

Comments
 (0)