Skip to content

NO-ISSUE: Synchronize From Upstream Repositories #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/mikefarah/yq/v3 v3.0.0-20201202084205-8846255d1c37
github.com/onsi/ginkgo/v2 v2.15.0
github.com/openshift/api v3.9.0+incompatible
github.com/operator-framework/api v0.21.0
github.com/operator-framework/api v0.22.0
github.com/operator-framework/operator-lifecycle-manager v0.0.0-00010101000000-000000000000
github.com/operator-framework/operator-registry v1.35.0
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -165,7 +165,7 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/gomega v1.31.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/image-spec v1.1.0-rc6 // indirect
github.com/opencontainers/runc v1.1.12 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI=
github.com/opencontainers/image-spec v1.1.0-rc5/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
github.com/opencontainers/image-spec v1.1.0-rc6 h1:XDqvyKsJEbRtATzkgItUqBA7QHk58yxX1Ov9HERHNqU=
github.com/opencontainers/image-spec v1.1.0-rc6/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/opencontainers/runc v1.1.12 h1:BOIssBaW1La0/qbNZHXOOa71dZfZEQOzW7dqQf3phss=
github.com/opencontainers/runc v1.1.12/go.mod h1:S+lQwSfncpBha7XTy/5lBwWgm5+y5Ma/O44Ekby9FK8=
github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg=
Expand Down
17 changes: 17 additions & 0 deletions manifests/0000_50_olm_99-operatorstatus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ status:
versions:
- name: operator
version: "0.0.1-snapshot"
relatedObjects:
- group: operators.coreos.com
name: packageserver
namespace: openshift-operator-lifecycle-manager
resource: clusterserviceversions
---
apiVersion: config.openshift.io/v1
kind: ClusterOperator
Expand All @@ -25,6 +30,10 @@ status:
versions:
- name: operator
version: "0.0.1-snapshot"
relatedObjects:
- group: ""
name: openshift-operator-lifecycle-manager
resource: namespaces
---
apiVersion: config.openshift.io/v1
kind: ClusterOperator
Expand All @@ -39,3 +48,11 @@ status:
versions:
- name: operator
version: "0.0.1-snapshot"
relatedObjects:
- group: ""
name: openshift-operator-lifecycle-manager
resource: namespaces
- group: operators.coreos.com
name: packageserver
namespace: openshift-operator-lifecycle-manager
resource: clusterserviceversions
17 changes: 17 additions & 0 deletions microshift-manifests/0000_50_olm_99-operatorstatus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ status:
versions:
- name: operator
version: "0.0.1-snapshot"
relatedObjects:
- group: operators.coreos.com
name: packageserver
namespace: openshift-operator-lifecycle-manager
resource: clusterserviceversions
---
apiVersion: config.openshift.io/v1
kind: ClusterOperator
Expand All @@ -25,6 +30,10 @@ status:
versions:
- name: operator
version: "0.0.1-snapshot"
relatedObjects:
- group: ""
name: openshift-operator-lifecycle-manager
resource: namespaces
---
apiVersion: config.openshift.io/v1
kind: ClusterOperator
Expand All @@ -39,3 +48,11 @@ status:
versions:
- name: operator
version: "0.0.1-snapshot"
relatedObjects:
- group: ""
name: openshift-operator-lifecycle-manager
resource: namespaces
- group: operators.coreos.com
name: packageserver
namespace: openshift-operator-lifecycle-manager
resource: clusterserviceversions
9 changes: 2 additions & 7 deletions staging/operator-lifecycle-manager/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ This is a rough outline of what a contributor's workflow looks like:
- Identify or create an issue.
- Create a topic branch from where to base the contribution. This is usually the master branch.
- Make commits of logical units.
- Make sure commit messages are in the proper format ([see below][commit-messages]).
- Ensure all relevant commit messages contain a valid sign-off message ([see below][commit-messages]).
- Push changes in a topic branch to a personal fork of the repository.
- Submit a pull request to the operator-framework/operator-lifecycle-manager repository.
- Wait and respond to feedback from the maintainers listed in the OWNERS file.
Expand Down Expand Up @@ -62,11 +60,9 @@ In addition to the linked style documentation, OLM formats Golang packages using

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

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

A [sign-off][sign-off] is a line towards the end of a commit message that certifies the commit author(s).

For more information on the structuring of commit messages, read the information in the [DCO][dco] application that the OLM projects uses.
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.

## Documentation

Expand All @@ -84,4 +80,3 @@ The OLM documentation mainly lives in the [operator-framework/olm-docs][olm-docs
[sign-off]: <https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---signoff>
[goimports]: <https://pkg.go.dev/golang.org/x/tools/cmd/goimports>
[gofmt]: <https://pkg.go.dev/cmd/gofmt>
[commit-messages]: <https://github.com/operator-framework/operator-lifecycle-manager/blob/master/CONTRIBUTING.md#commit-messages-and-sign-off-dco>
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ spec:
topologyKey:
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.
type: string
annotations:
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.
type: object
additionalProperties:
type: string
env:
description: Env is a list of environment variables to set in the container. Cannot be updated.
type: array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ status:
versions:
- name: operator
version: "0.0.1-snapshot"
relatedObjects:
- group: operators.coreos.com
name: packageserver
namespace: openshift-operator-lifecycle-manager
resource: clusterserviceversions
---
apiVersion: config.openshift.io/v1
kind: ClusterOperator
Expand All @@ -16,6 +21,10 @@ status:
versions:
- name: operator
version: "0.0.1-snapshot"
relatedObjects:
- group: ""
name: openshift-operator-lifecycle-manager
resource: namespaces
{{- if .Values.writePackageServerStatusName }}
---
apiVersion: config.openshift.io/v1
Expand All @@ -26,5 +35,13 @@ status:
versions:
- name: operator
version: "0.0.1-snapshot"
relatedObjects:
- group: ""
name: openshift-operator-lifecycle-manager
resource: namespaces
- group: operators.coreos.com
name: packageserver
namespace: openshift-operator-lifecycle-manager
resource: clusterserviceversions
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion staging/operator-lifecycle-manager/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/onsi/gomega v1.29.0
github.com/openshift/api v3.9.0+incompatible
github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a
github.com/operator-framework/api v0.21.0
github.com/operator-framework/api v0.22.0
github.com/operator-framework/operator-registry v1.35.0
github.com/otiai10/copy v1.14.0
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions staging/operator-lifecycle-manager/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ github.com/openshift/api v0.0.0-20221021112143-4226c2167e40 h1:PxjGCA72RtsdHWToZ
github.com/openshift/api v0.0.0-20221021112143-4226c2167e40/go.mod h1:aQ6LDasvHMvHZXqLHnX2GRmnfTWCF/iIwz8EMTTIE9A=
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c h1:CV76yFOTXmq9VciBR3Bve5ZWzSxdft7gaMVB3kS0rwg=
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c/go.mod h1:lFMO8mLHXWFzSdYvGNo8ivF9SfF6zInA8ZGw4phRnUE=
github.com/operator-framework/api v0.21.0 h1:89LhqGTLskxpPR4siEaorkF9PY3KLI51S5mFxP6q1G8=
github.com/operator-framework/api v0.21.0/go.mod h1:3tsDLxXChMY1KgxO5v1CZQogHNQCIMy14YXkXqA5lT4=
github.com/operator-framework/api v0.22.0 h1:UZSn+iaQih4rCReezOnWTTJkMyawwV5iLnIItaOzytY=
github.com/operator-framework/api v0.22.0/go.mod h1:p/7YDbr+n4fmESfZ47yLAV1SvkfE6NU2aX8KhcfI0GA=
github.com/operator-framework/operator-registry v1.35.0 h1:BvytqLwhgb0QiAkEODEKXq3vc2vWiHQq0IlofvFA+OI=
github.com/operator-framework/operator-registry v1.35.0/go.mod h1:foC+NO1V9JuDIOk3pjjlrPE0KVkq09m8oDVRz/a/nFA=
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
log "github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"

"github.com/operator-framework/api/pkg/operators/v1alpha1"
Expand Down Expand Up @@ -40,6 +41,16 @@ func (i *StrategyDeploymentInstaller) createOrUpdateAPIService(caPEM []byte, des
},
}
apiService.SetName(apiServiceName)

ownerSubscription, err := i.findOwnerSubscription()
if err != nil {
return err
} else if ownerSubscription == nil {
// This is not an error. For example, the PackageServer CSV in OLM is created without a Subscription.
logger.Debugf("failed to get the owner subscription csv=%s", i.owner.GetName())
} else if ownerSubscription.Spec.Config != nil {
apiService.SetAnnotations(ownerSubscription.Spec.Config.Annotations)
}
} else {
apiService = apiService.DeepCopy()
csv, ok := i.owner.(*v1alpha1.ClusterServiceVersion)
Expand Down Expand Up @@ -101,10 +112,10 @@ func IsAPIServiceAdoptable(opLister operatorlister.OperatorLister, target *v1alp
return
}

labels := apiService.GetLabels()
ownerKind := labels[ownerutil.OwnerKind]
ownerName := labels[ownerutil.OwnerKey]
ownerNamespace := labels[ownerutil.OwnerNamespaceKey]
apiServiceLabels := apiService.GetLabels()
ownerKind := apiServiceLabels[ownerutil.OwnerKind]
ownerName := apiServiceLabels[ownerutil.OwnerKey]
ownerNamespace := apiServiceLabels[ownerutil.OwnerNamespaceKey]

if ownerKind == "" || ownerNamespace == "" || ownerName == "" {
return
Expand Down Expand Up @@ -285,3 +296,20 @@ func legacyAPIServiceNameToServiceName(apiServiceName string) string {
// Replace all '.'s with "-"s to convert to a DNS-1035 label
return strings.Replace(apiServiceName, ".", "-", -1)
}

func (i *StrategyDeploymentInstaller) findOwnerSubscription() (*v1alpha1.Subscription, error) {
list, listErr := i.strategyClient.GetOpLister().OperatorsV1alpha1().SubscriptionLister().Subscriptions(i.owner.GetNamespace()).List(labels.Everything())
if listErr != nil {
err := fmt.Errorf("failed to list subscription namespace=%s - %v", i.owner.GetNamespace(), listErr)
return nil, err
}

for idx := range list {
sub := list[idx]
if sub.Status.InstalledCSV == i.owner.GetName() {
return sub, nil
}
}

return nil, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (i *StrategyDeploymentInstaller) deploymentForSpec(name string, spec appsv1
for k, v := range dep.Spec.Template.GetAnnotations() {
annotations[k] = v
}
for k, v := range i.templateAnnotations {
for k, v := range i.templateAnnotations { // templateAnnotations comes from CSV.Annotations
annotations[k] = v
}
dep.Spec.Template.SetAnnotations(annotations)
Expand All @@ -159,6 +159,7 @@ func (i *StrategyDeploymentInstaller) deploymentForSpec(name string, spec appsv1
ownerutil.AddNonBlockingOwner(dep, i.owner)
ownerutil.AddOwnerLabelsForKind(dep, i.owner, v1alpha1.ClusterServiceVersionKind)

// Any admin-provided config (Subscription.Spec.Config) gets injected here.
if applyErr := i.initializers.Apply(dep); applyErr != nil {
err = applyErr
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type operatorConfig struct {
logger *logrus.Logger
}

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) {
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) {
list, listErr := o.lister.OperatorsV1alpha1().SubscriptionLister().Subscriptions(ownerCSV.GetNamespace()).List(labels.Everything())
if listErr != nil {
err = fmt.Errorf("failed to list subscription namespace=%s - %v", ownerCSV.GetNamespace(), listErr)
Expand All @@ -41,6 +41,7 @@ func (o *operatorConfig) GetConfigOverrides(ownerCSV ownerutil.Owner) (envVarOve
resourcesOverride = owner.Spec.Config.Resources
nodeSelectorOverride = owner.Spec.Config.NodeSelector
affinity = owner.Spec.Config.Affinity
annotations = owner.Spec.Config.Annotations

return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (d *DeploymentInitializer) initialize(ownerCSV ownerutil.Owner, deployment
var envVarOverrides, proxyEnvVar, merged []corev1.EnvVar
var err error

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

if err = inject.InjectAnnotationsIntoDeployment(deployment, annotations); err != nil {
return fmt.Errorf("failed to inject annotations into deployment spec name=%s - %s", deployment.Name, err)
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"errors"
"reflect"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)

// InjectEnvIntoDeployment injects the proxy env variables specified in
// proxyEnvVar into the container(s) of the given PodSpec.
//
// If any Container in PodSpec already defines an env variable of the same name
// as any of the proxy env variables then it
// as any of the proxy env variables then it will be overwritten.
func InjectEnvIntoDeployment(podSpec *corev1.PodSpec, envVars []corev1.EnvVar) error {
if podSpec == nil {
return errors.New("no pod spec provided")
Expand Down Expand Up @@ -217,8 +218,7 @@ func InjectResourcesIntoDeployment(podSpec *corev1.PodSpec, resources *corev1.Re
// InjectNodeSelectorIntoDeployment injects the provided NodeSelector
// into the container(s) of the given PodSpec.
//
// If any Container in PodSpec already defines a NodeSelector it will
// be overwritten.
// If the PodSpec already defines a NodeSelector it will be overwritten.
func InjectNodeSelectorIntoDeployment(podSpec *corev1.PodSpec, nodeSelector map[string]string) error {
if podSpec == nil {
return errors.New("no pod spec provided")
Expand Down Expand Up @@ -300,3 +300,40 @@ func OverrideDeploymentAffinity(podSpec *corev1.PodSpec, affinity *corev1.Affini

return nil
}

// InjectAnnotationsIntoDeployment injects the provided Annotations
// into the container(s) of the given PodSpec.
//
// If the Deployment already defines any Annotations they will NOT be overwritten.
func InjectAnnotationsIntoDeployment(deployment *appsv1.Deployment, newAnnotations map[string]string) error {
if deployment == nil {
return errors.New("no deployment provided")
}

// do not override existing annotations
if newAnnotations != nil {
mergedDeploymentAnnotations := map[string]string{}
mergedPodAnnotations := map[string]string{}

// add newAnnotations first to prevent them from overwriting the defaults
for k, v := range newAnnotations {
mergedDeploymentAnnotations[k] = v
mergedPodAnnotations[k] = v
}

// then replace any duplicate annotations with the default annotation
for k, v := range deployment.Annotations {
mergedDeploymentAnnotations[k] = v
}
for k, v := range deployment.Spec.Template.GetAnnotations() {
mergedPodAnnotations[k] = v
}

// Inject Into Deployment
deployment.SetAnnotations(mergedDeploymentAnnotations)
// Inject Into Pod Spec
deployment.Spec.Template.SetAnnotations(mergedPodAnnotations)
}

return nil
}
Loading