|
8 | 8 | log "github.com/sirupsen/logrus"
|
9 | 9 | apierrors "k8s.io/apimachinery/pkg/api/errors"
|
10 | 10 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
| 11 | + "k8s.io/apimachinery/pkg/labels" |
11 | 12 | apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
|
12 | 13 |
|
13 | 14 | "github.com/operator-framework/api/pkg/operators/v1alpha1"
|
@@ -40,6 +41,16 @@ func (i *StrategyDeploymentInstaller) createOrUpdateAPIService(caPEM []byte, des
|
40 | 41 | },
|
41 | 42 | }
|
42 | 43 | apiService.SetName(apiServiceName)
|
| 44 | + |
| 45 | + ownerSubscription, err := i.findOwnerSubscription() |
| 46 | + if err != nil { |
| 47 | + return err |
| 48 | + } else if ownerSubscription == nil { |
| 49 | + // This is not an error. For example, the PackageServer CSV in OLM is created without a Subscription. |
| 50 | + logger.Debugf("failed to get the owner subscription csv=%s", i.owner.GetName()) |
| 51 | + } else if ownerSubscription.Spec.Config != nil { |
| 52 | + apiService.SetAnnotations(ownerSubscription.Spec.Config.Annotations) |
| 53 | + } |
43 | 54 | } else {
|
44 | 55 | apiService = apiService.DeepCopy()
|
45 | 56 | csv, ok := i.owner.(*v1alpha1.ClusterServiceVersion)
|
@@ -101,10 +112,10 @@ func IsAPIServiceAdoptable(opLister operatorlister.OperatorLister, target *v1alp
|
101 | 112 | return
|
102 | 113 | }
|
103 | 114 |
|
104 |
| - labels := apiService.GetLabels() |
105 |
| - ownerKind := labels[ownerutil.OwnerKind] |
106 |
| - ownerName := labels[ownerutil.OwnerKey] |
107 |
| - ownerNamespace := labels[ownerutil.OwnerNamespaceKey] |
| 115 | + apiServiceLabels := apiService.GetLabels() |
| 116 | + ownerKind := apiServiceLabels[ownerutil.OwnerKind] |
| 117 | + ownerName := apiServiceLabels[ownerutil.OwnerKey] |
| 118 | + ownerNamespace := apiServiceLabels[ownerutil.OwnerNamespaceKey] |
108 | 119 |
|
109 | 120 | if ownerKind == "" || ownerNamespace == "" || ownerName == "" {
|
110 | 121 | return
|
@@ -285,3 +296,20 @@ func legacyAPIServiceNameToServiceName(apiServiceName string) string {
|
285 | 296 | // Replace all '.'s with "-"s to convert to a DNS-1035 label
|
286 | 297 | return strings.Replace(apiServiceName, ".", "-", -1)
|
287 | 298 | }
|
| 299 | + |
| 300 | +func (i *StrategyDeploymentInstaller) findOwnerSubscription() (*v1alpha1.Subscription, error) { |
| 301 | + list, listErr := i.strategyClient.GetOpLister().OperatorsV1alpha1().SubscriptionLister().Subscriptions(i.owner.GetNamespace()).List(labels.Everything()) |
| 302 | + if listErr != nil { |
| 303 | + err := fmt.Errorf("failed to list subscription namespace=%s - %v", i.owner.GetNamespace(), listErr) |
| 304 | + return nil, err |
| 305 | + } |
| 306 | + |
| 307 | + for idx := range list { |
| 308 | + sub := list[idx] |
| 309 | + if sub.Status.InstalledCSV == i.owner.GetName() { |
| 310 | + return sub, nil |
| 311 | + } |
| 312 | + } |
| 313 | + |
| 314 | + return nil, nil |
| 315 | +} |
0 commit comments