Skip to content

Commit 1f0596e

Browse files
committed
Apply Subscription.Spec.Config.Annotations to ApiServices
1 parent 07b88d2 commit 1f0596e

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

pkg/controller/install/apiservice.go

+32-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
log "github.com/sirupsen/logrus"
99
apierrors "k8s.io/apimachinery/pkg/api/errors"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/labels"
1112
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
1213

1314
"github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -40,6 +41,16 @@ func (i *StrategyDeploymentInstaller) createOrUpdateAPIService(caPEM []byte, des
4041
},
4142
}
4243
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+
}
4354
} else {
4455
apiService = apiService.DeepCopy()
4556
csv, ok := i.owner.(*v1alpha1.ClusterServiceVersion)
@@ -101,10 +112,10 @@ func IsAPIServiceAdoptable(opLister operatorlister.OperatorLister, target *v1alp
101112
return
102113
}
103114

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]
108119

109120
if ownerKind == "" || ownerNamespace == "" || ownerName == "" {
110121
return
@@ -285,3 +296,20 @@ func legacyAPIServiceNameToServiceName(apiServiceName string) string {
285296
// Replace all '.'s with "-"s to convert to a DNS-1035 label
286297
return strings.Replace(apiServiceName, ".", "-", -1)
287298
}
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

Comments
 (0)