Skip to content

Commit aec0f1d

Browse files
Merge pull request #695 from openshift-bot/synchronize-upstream
NO-ISSUE: Synchronize From Upstream Repositories
2 parents 12a2e2f + ac771e7 commit aec0f1d

File tree

38 files changed

+616
-70
lines changed

38 files changed

+616
-70
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/mikefarah/yq/v3 v3.0.0-20201202084205-8846255d1c37
1414
github.com/onsi/ginkgo/v2 v2.15.0
1515
github.com/openshift/api v3.9.0+incompatible
16-
github.com/operator-framework/api v0.21.0
16+
github.com/operator-framework/api v0.22.0
1717
github.com/operator-framework/operator-lifecycle-manager v0.0.0-00010101000000-000000000000
1818
github.com/operator-framework/operator-registry v1.35.0
1919
github.com/sirupsen/logrus v1.9.3
@@ -165,7 +165,7 @@ require (
165165
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
166166
github.com/onsi/gomega v1.31.1 // indirect
167167
github.com/opencontainers/go-digest v1.0.0 // indirect
168-
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
168+
github.com/opencontainers/image-spec v1.1.0-rc6 // indirect
169169
github.com/opencontainers/runc v1.1.12 // indirect
170170
github.com/opencontainers/runtime-spec v1.1.0 // indirect
171171
github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,8 @@ github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
727727
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
728728
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
729729
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
730-
github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI=
731-
github.com/opencontainers/image-spec v1.1.0-rc5/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
730+
github.com/opencontainers/image-spec v1.1.0-rc6 h1:XDqvyKsJEbRtATzkgItUqBA7QHk58yxX1Ov9HERHNqU=
731+
github.com/opencontainers/image-spec v1.1.0-rc6/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
732732
github.com/opencontainers/runc v1.1.12 h1:BOIssBaW1La0/qbNZHXOOa71dZfZEQOzW7dqQf3phss=
733733
github.com/opencontainers/runc v1.1.12/go.mod h1:S+lQwSfncpBha7XTy/5lBwWgm5+y5Ma/O44Ekby9FK8=
734734
github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg=

manifests/0000_50_olm_99-operatorstatus.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ status:
1111
versions:
1212
- name: operator
1313
version: "0.0.1-snapshot"
14+
relatedObjects:
15+
- group: operators.coreos.com
16+
name: packageserver
17+
namespace: openshift-operator-lifecycle-manager
18+
resource: clusterserviceversions
1419
---
1520
apiVersion: config.openshift.io/v1
1621
kind: ClusterOperator
@@ -25,6 +30,10 @@ status:
2530
versions:
2631
- name: operator
2732
version: "0.0.1-snapshot"
33+
relatedObjects:
34+
- group: ""
35+
name: openshift-operator-lifecycle-manager
36+
resource: namespaces
2837
---
2938
apiVersion: config.openshift.io/v1
3039
kind: ClusterOperator
@@ -39,3 +48,11 @@ status:
3948
versions:
4049
- name: operator
4150
version: "0.0.1-snapshot"
51+
relatedObjects:
52+
- group: ""
53+
name: openshift-operator-lifecycle-manager
54+
resource: namespaces
55+
- group: operators.coreos.com
56+
name: packageserver
57+
namespace: openshift-operator-lifecycle-manager
58+
resource: clusterserviceversions

microshift-manifests/0000_50_olm_99-operatorstatus.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ status:
1111
versions:
1212
- name: operator
1313
version: "0.0.1-snapshot"
14+
relatedObjects:
15+
- group: operators.coreos.com
16+
name: packageserver
17+
namespace: openshift-operator-lifecycle-manager
18+
resource: clusterserviceversions
1419
---
1520
apiVersion: config.openshift.io/v1
1621
kind: ClusterOperator
@@ -25,6 +30,10 @@ status:
2530
versions:
2631
- name: operator
2732
version: "0.0.1-snapshot"
33+
relatedObjects:
34+
- group: ""
35+
name: openshift-operator-lifecycle-manager
36+
resource: namespaces
2837
---
2938
apiVersion: config.openshift.io/v1
3039
kind: ClusterOperator
@@ -39,3 +48,11 @@ status:
3948
versions:
4049
- name: operator
4150
version: "0.0.1-snapshot"
51+
relatedObjects:
52+
- group: ""
53+
name: openshift-operator-lifecycle-manager
54+
resource: namespaces
55+
- group: operators.coreos.com
56+
name: packageserver
57+
namespace: openshift-operator-lifecycle-manager
58+
resource: clusterserviceversions

staging/operator-lifecycle-manager/CONTRIBUTING.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ This is a rough outline of what a contributor's workflow looks like:
3131
- Identify or create an issue.
3232
- Create a topic branch from where to base the contribution. This is usually the master branch.
3333
- Make commits of logical units.
34-
- Make sure commit messages are in the proper format ([see below][commit-messages]).
35-
- Ensure all relevant commit messages contain a valid sign-off message ([see below][commit-messages]).
3634
- Push changes in a topic branch to a personal fork of the repository.
3735
- Submit a pull request to the operator-framework/operator-lifecycle-manager repository.
3836
- Wait and respond to feedback from the maintainers listed in the OWNERS file.
@@ -62,11 +60,9 @@ In addition to the linked style documentation, OLM formats Golang packages using
6260

6361
Please follow this style to make the OLM project easier to review, maintain and develop.
6462

65-
### Commit Messages and Sign-off ([DCO][DCO])
63+
### Developer Certificate of Origin ([DCO][DCO])
6664

67-
A [sign-off][sign-off] is a line towards the end of a commit message that certifies the commit author(s).
68-
69-
For more information on the structuring of commit messages, read the information in the [DCO][dco] application that the OLM projects uses.
65+
By contributing to this project you agree to the Developer Certificate of Origin (DCO). This document was created by the Linux Kernl community and is a simple statement that you, as a contributor, have the legal right to make the contribution. See the [DCO][dco] file for details.
7066

7167
## Documentation
7268

@@ -84,4 +80,3 @@ The OLM documentation mainly lives in the [operator-framework/olm-docs][olm-docs
8480
[sign-off]: <https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---signoff>
8581
[goimports]: <https://pkg.go.dev/golang.org/x/tools/cmd/goimports>
8682
[gofmt]: <https://pkg.go.dev/cmd/gofmt>
87-
[commit-messages]: <https://github.com/operator-framework/operator-lifecycle-manager/blob/master/CONTRIBUTING.md#commit-messages-and-sign-off-dco>

staging/operator-lifecycle-manager/deploy/chart/crds/0000_50_olm_00-subscriptions.crd.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ spec:
524524
topologyKey:
525525
description: This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching the labelSelector in the specified namespaces, where co-located is defined as running on a node whose value of the label with key topologyKey matches that of any node on which any of the selected pods is running. Empty topologyKey is not allowed.
526526
type: string
527+
annotations:
528+
description: Annotations is an unstructured key value map stored with each Deployment, Pod, APIService in the Operator. Typically, annotations may be set by external tools to store and retrieve arbitrary metadata. Use this field to pre-define annotations that OLM should add to each of the Subscription's deployments, pods, and apiservices.
529+
type: object
530+
additionalProperties:
531+
type: string
527532
env:
528533
description: Env is a list of environment variables to set in the container. Cannot be updated.
529534
type: array

staging/operator-lifecycle-manager/deploy/chart/templates/0000_50_olm_99-operatorstatus.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ status:
77
versions:
88
- name: operator
99
version: "0.0.1-snapshot"
10+
relatedObjects:
11+
- group: operators.coreos.com
12+
name: packageserver
13+
namespace: openshift-operator-lifecycle-manager
14+
resource: clusterserviceversions
1015
---
1116
apiVersion: config.openshift.io/v1
1217
kind: ClusterOperator
@@ -16,6 +21,10 @@ status:
1621
versions:
1722
- name: operator
1823
version: "0.0.1-snapshot"
24+
relatedObjects:
25+
- group: ""
26+
name: openshift-operator-lifecycle-manager
27+
resource: namespaces
1928
{{- if .Values.writePackageServerStatusName }}
2029
---
2130
apiVersion: config.openshift.io/v1
@@ -26,5 +35,13 @@ status:
2635
versions:
2736
- name: operator
2837
version: "0.0.1-snapshot"
38+
relatedObjects:
39+
- group: ""
40+
name: openshift-operator-lifecycle-manager
41+
resource: namespaces
42+
- group: operators.coreos.com
43+
name: packageserver
44+
namespace: openshift-operator-lifecycle-manager
45+
resource: clusterserviceversions
2946
{{- end }}
3047
{{- end }}

staging/operator-lifecycle-manager/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/onsi/gomega v1.29.0
2525
github.com/openshift/api v3.9.0+incompatible
2626
github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a
27-
github.com/operator-framework/api v0.21.0
27+
github.com/operator-framework/api v0.22.0
2828
github.com/operator-framework/operator-registry v1.35.0
2929
github.com/otiai10/copy v1.14.0
3030
github.com/pkg/errors v0.9.1

staging/operator-lifecycle-manager/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,8 @@ github.com/openshift/api v0.0.0-20221021112143-4226c2167e40 h1:PxjGCA72RtsdHWToZ
672672
github.com/openshift/api v0.0.0-20221021112143-4226c2167e40/go.mod h1:aQ6LDasvHMvHZXqLHnX2GRmnfTWCF/iIwz8EMTTIE9A=
673673
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c h1:CV76yFOTXmq9VciBR3Bve5ZWzSxdft7gaMVB3kS0rwg=
674674
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c/go.mod h1:lFMO8mLHXWFzSdYvGNo8ivF9SfF6zInA8ZGw4phRnUE=
675-
github.com/operator-framework/api v0.21.0 h1:89LhqGTLskxpPR4siEaorkF9PY3KLI51S5mFxP6q1G8=
676-
github.com/operator-framework/api v0.21.0/go.mod h1:3tsDLxXChMY1KgxO5v1CZQogHNQCIMy14YXkXqA5lT4=
675+
github.com/operator-framework/api v0.22.0 h1:UZSn+iaQih4rCReezOnWTTJkMyawwV5iLnIItaOzytY=
676+
github.com/operator-framework/api v0.22.0/go.mod h1:p/7YDbr+n4fmESfZ47yLAV1SvkfE6NU2aX8KhcfI0GA=
677677
github.com/operator-framework/operator-registry v1.35.0 h1:BvytqLwhgb0QiAkEODEKXq3vc2vWiHQq0IlofvFA+OI=
678678
github.com/operator-framework/operator-registry v1.35.0/go.mod h1:foC+NO1V9JuDIOk3pjjlrPE0KVkq09m8oDVRz/a/nFA=
679679
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=

staging/operator-lifecycle-manager/pkg/controller/install/apiservice.go

Lines changed: 32 additions & 4 deletions
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+
}

staging/operator-lifecycle-manager/pkg/controller/install/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (i *StrategyDeploymentInstaller) deploymentForSpec(name string, spec appsv1
144144
for k, v := range dep.Spec.Template.GetAnnotations() {
145145
annotations[k] = v
146146
}
147-
for k, v := range i.templateAnnotations {
147+
for k, v := range i.templateAnnotations { // templateAnnotations comes from CSV.Annotations
148148
annotations[k] = v
149149
}
150150
dep.Spec.Template.SetAnnotations(annotations)
@@ -159,6 +159,7 @@ func (i *StrategyDeploymentInstaller) deploymentForSpec(name string, spec appsv1
159159
ownerutil.AddNonBlockingOwner(dep, i.owner)
160160
ownerutil.AddOwnerLabelsForKind(dep, i.owner, v1alpha1.ClusterServiceVersionKind)
161161

162+
// Any admin-provided config (Subscription.Spec.Config) gets injected here.
162163
if applyErr := i.initializers.Apply(dep); applyErr != nil {
163164
err = applyErr
164165
return

staging/operator-lifecycle-manager/pkg/controller/operators/olm/overrides/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type operatorConfig struct {
1616
logger *logrus.Logger
1717
}
1818

19-
func (o *operatorConfig) GetConfigOverrides(ownerCSV ownerutil.Owner) (envVarOverrides []corev1.EnvVar, volumeOverrides []corev1.Volume, volumeMountOverrides []corev1.VolumeMount, tolerationOverrides []corev1.Toleration, resourcesOverride *corev1.ResourceRequirements, nodeSelectorOverride map[string]string, affinity *corev1.Affinity, err error) {
19+
func (o *operatorConfig) GetConfigOverrides(ownerCSV ownerutil.Owner) (envVarOverrides []corev1.EnvVar, volumeOverrides []corev1.Volume, volumeMountOverrides []corev1.VolumeMount, tolerationOverrides []corev1.Toleration, resourcesOverride *corev1.ResourceRequirements, nodeSelectorOverride map[string]string, affinity *corev1.Affinity, annotations map[string]string, err error) {
2020
list, listErr := o.lister.OperatorsV1alpha1().SubscriptionLister().Subscriptions(ownerCSV.GetNamespace()).List(labels.Everything())
2121
if listErr != nil {
2222
err = fmt.Errorf("failed to list subscription namespace=%s - %v", ownerCSV.GetNamespace(), listErr)
@@ -41,6 +41,7 @@ func (o *operatorConfig) GetConfigOverrides(ownerCSV ownerutil.Owner) (envVarOve
4141
resourcesOverride = owner.Spec.Config.Resources
4242
nodeSelectorOverride = owner.Spec.Config.NodeSelector
4343
affinity = owner.Spec.Config.Affinity
44+
annotations = owner.Spec.Config.Annotations
4445

4546
return
4647
}

staging/operator-lifecycle-manager/pkg/controller/operators/olm/overrides/initializer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (d *DeploymentInitializer) initialize(ownerCSV ownerutil.Owner, deployment
4545
var envVarOverrides, proxyEnvVar, merged []corev1.EnvVar
4646
var err error
4747

48-
envVarOverrides, volumeOverrides, volumeMountOverrides, tolerationOverrides, resourcesOverride, nodeSelectorOverride, affinity, err := d.config.GetConfigOverrides(ownerCSV)
48+
envVarOverrides, volumeOverrides, volumeMountOverrides, tolerationOverrides, resourcesOverride, nodeSelectorOverride, affinity, annotations, err := d.config.GetConfigOverrides(ownerCSV)
4949
if err != nil {
5050
err = fmt.Errorf("failed to get subscription pod configuration - %v", err)
5151
return err
@@ -96,6 +96,10 @@ func (d *DeploymentInitializer) initialize(ownerCSV ownerutil.Owner, deployment
9696
return fmt.Errorf("failed to inject affinity into deployment spec name=%s - %s", deployment.Name, err)
9797
}
9898

99+
if err = inject.InjectAnnotationsIntoDeployment(deployment, annotations); err != nil {
100+
return fmt.Errorf("failed to inject annotations into deployment spec name=%s - %s", deployment.Name, err)
101+
}
102+
99103
return nil
100104
}
101105

staging/operator-lifecycle-manager/pkg/controller/operators/olm/overrides/inject/inject.go

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"errors"
55
"reflect"
66

7+
appsv1 "k8s.io/api/apps/v1"
78
corev1 "k8s.io/api/core/v1"
89
)
910

1011
// InjectEnvIntoDeployment injects the proxy env variables specified in
1112
// proxyEnvVar into the container(s) of the given PodSpec.
1213
//
1314
// If any Container in PodSpec already defines an env variable of the same name
14-
// as any of the proxy env variables then it
15+
// as any of the proxy env variables then it will be overwritten.
1516
func InjectEnvIntoDeployment(podSpec *corev1.PodSpec, envVars []corev1.EnvVar) error {
1617
if podSpec == nil {
1718
return errors.New("no pod spec provided")
@@ -217,8 +218,7 @@ func InjectResourcesIntoDeployment(podSpec *corev1.PodSpec, resources *corev1.Re
217218
// InjectNodeSelectorIntoDeployment injects the provided NodeSelector
218219
// into the container(s) of the given PodSpec.
219220
//
220-
// If any Container in PodSpec already defines a NodeSelector it will
221-
// be overwritten.
221+
// If the PodSpec already defines a NodeSelector it will be overwritten.
222222
func InjectNodeSelectorIntoDeployment(podSpec *corev1.PodSpec, nodeSelector map[string]string) error {
223223
if podSpec == nil {
224224
return errors.New("no pod spec provided")
@@ -300,3 +300,40 @@ func OverrideDeploymentAffinity(podSpec *corev1.PodSpec, affinity *corev1.Affini
300300

301301
return nil
302302
}
303+
304+
// InjectAnnotationsIntoDeployment injects the provided Annotations
305+
// into the container(s) of the given PodSpec.
306+
//
307+
// If the Deployment already defines any Annotations they will NOT be overwritten.
308+
func InjectAnnotationsIntoDeployment(deployment *appsv1.Deployment, newAnnotations map[string]string) error {
309+
if deployment == nil {
310+
return errors.New("no deployment provided")
311+
}
312+
313+
// do not override existing annotations
314+
if newAnnotations != nil {
315+
mergedDeploymentAnnotations := map[string]string{}
316+
mergedPodAnnotations := map[string]string{}
317+
318+
// add newAnnotations first to prevent them from overwriting the defaults
319+
for k, v := range newAnnotations {
320+
mergedDeploymentAnnotations[k] = v
321+
mergedPodAnnotations[k] = v
322+
}
323+
324+
// then replace any duplicate annotations with the default annotation
325+
for k, v := range deployment.Annotations {
326+
mergedDeploymentAnnotations[k] = v
327+
}
328+
for k, v := range deployment.Spec.Template.GetAnnotations() {
329+
mergedPodAnnotations[k] = v
330+
}
331+
332+
// Inject Into Deployment
333+
deployment.SetAnnotations(mergedDeploymentAnnotations)
334+
// Inject Into Pod Spec
335+
deployment.Spec.Template.SetAnnotations(mergedPodAnnotations)
336+
}
337+
338+
return nil
339+
}

0 commit comments

Comments
 (0)