Skip to content

Commit 3484c65

Browse files
Merge pull request #1014 from openshift-bot/synchronize-upstream
OCPBUGS-43966, OCPBUGS-57222: Synchronize From Upstream Repositories
2 parents 917ba60 + d4c0bee commit 3484c65

File tree

7 files changed

+182
-27
lines changed

7 files changed

+182
-27
lines changed

staging/operator-lifecycle-manager/.github/workflows/go-verdiff.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ jobs:
1010
go-verdiff:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v4
14-
with:
15-
fetch-depth: 0
16-
- name: Check golang version
17-
run: hack/tools/check-go-version.sh "${{ github.event.pull_request.base.sha }}"
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- name: Check golang version
17+
run: |
18+
export LABELS="$(gh api repos/$OWNER/$REPO/pulls/$PR --jq '.labels.[].name')"
19+
hack/tools/check-go-version.sh -b "${{ github.event.pull_request.base.sha }}"
20+
shell: bash
21+
env:
22+
GH_TOKEN: ${{ github.token }}
23+
OWNER: ${{ github.repository_owner }}
24+
REPO: ${{ github.event.repository.name }}
25+
PR: ${{ github.event.pull_request.number }}

staging/operator-lifecycle-manager/hack/tools/check-go-version.sh

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,40 @@
1717
# this implementation in the future.
1818
###########################################
1919

20+
U_FLAG='false'
21+
B_FLAG=''
2022

21-
BASE_REF=${1:-main}
22-
GO_VER=$(sed -En 's/^go (.*)$/\1/p' "go.mod")
23+
usage() {
24+
cat <<EOF
25+
Usage:
26+
$0 [-b <git-ref>] [-h] [-u]
27+
28+
Reports on golang mod file version updates, returns an error when a go.mod
29+
file exceeds the root go.mod file (used as a threshold).
30+
31+
Options:
32+
-b <git-ref> git reference (branch or SHA) to use as a baseline.
33+
Defaults to 'main'.
34+
-h Help (this text).
35+
-u Error on any update, even below the threshold.
36+
EOF
37+
}
38+
39+
while getopts 'b:hu' f; do
40+
case "${f}" in
41+
b) B_FLAG="${OPTARG}" ;;
42+
h) usage
43+
exit 0 ;;
44+
u) U_FLAG='true' ;;
45+
*) echo "Unknown flag ${f}"
46+
usage
47+
exit 1 ;;
48+
esac
49+
done
50+
51+
BASE_REF=${B_FLAG:-main}
52+
ROOT_GO_MOD="./go.mod"
53+
GO_VER=$(sed -En 's/^go (.*)$/\1/p' "${ROOT_GO_MOD}")
2354
OLDIFS="${IFS}"
2455
IFS='.' MAX_VER=(${GO_VER})
2556
IFS="${OLDIFS}"
@@ -32,6 +63,7 @@ fi
3263
GO_MAJOR=${MAX_VER[0]}
3364
GO_MINOR=${MAX_VER[1]}
3465
GO_PATCH=${MAX_VER[2]}
66+
OVERRIDE_LABEL="override-go-verdiff"
3567

3668
RETCODE=0
3769

@@ -90,9 +122,32 @@ for f in $(find . -name "*.mod"); do
90122
continue
91123
fi
92124
if [ "${new}" != "${old}" ]; then
93-
echo "${f}: ${v}: Updated golang version from ${old}"
94-
RETCODE=1
125+
# We NEED to report on changes in the root go.mod, regardless of the U_FLAG
126+
if [ "${f}" == "${ROOT_GO_MOD}" ]; then
127+
echo "${f}: ${v}: Updated ROOT golang version from ${old}"
128+
RETCODE=1
129+
continue
130+
fi
131+
if ${U_FLAG}; then
132+
echo "${f}: ${v}: Updated golang version from ${old}"
133+
RETCODE=1
134+
fi
135+
fi
136+
done
137+
138+
for l in ${LABELS}; do
139+
if [ "$l" == "${OVERRIDE_LABEL}" ]; then
140+
if [ ${RETCODE} -eq 1 ]; then
141+
echo ""
142+
echo "Found ${OVERRIDE_LABEL} label, overriding failed results."
143+
RETCODE=0
144+
fi
95145
fi
96146
done
97147

148+
if [ ${RETCODE} -eq 1 ]; then
149+
echo ""
150+
echo "This test result may be overridden by applying the (${OVERRIDE_LABEL}) label to this PR and re-running the CI job."
151+
fi
152+
98153
exit ${RETCODE}

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"k8s.io/apimachinery/pkg/labels"
2020
"k8s.io/apimachinery/pkg/types"
2121
"k8s.io/apimachinery/pkg/util/errors"
22+
"k8s.io/apimachinery/pkg/util/sets"
2223

2324
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
2425
"github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -1047,24 +1048,35 @@ func (a *Operator) ensureOpGroupClusterRole(op *operatorsv1.OperatorGroup, suffi
10471048
}
10481049

10491050
func (a *Operator) getClusterRoleAggregationRule(apis cache.APISet, suffix string) (*rbacv1.AggregationRule, error) {
1050-
var selectors []metav1.LabelSelector
1051+
if len(apis) == 0 {
1052+
return nil, nil
1053+
}
1054+
1055+
aggregationLabels := sets.New[string]()
10511056
for api := range apis {
10521057
aggregationLabel, err := aggregationLabelFromAPIKey(api, suffix)
10531058
if err != nil {
10541059
return nil, err
10551060
}
1061+
aggregationLabels.Insert(aggregationLabel)
1062+
}
1063+
1064+
// The order of the resulting selectors MUST BE deterministic in order
1065+
// to avoid unnecessary writes against the API server where only the order
1066+
// is changing. Therefore, we use `sets.List` to iterate. It returns a
1067+
// sorted slice of the aggregation labels.
1068+
selectors := make([]metav1.LabelSelector, 0, aggregationLabels.Len())
1069+
for _, aggregationLabel := range sets.List(aggregationLabels) {
10561070
selectors = append(selectors, metav1.LabelSelector{
10571071
MatchLabels: map[string]string{
10581072
aggregationLabel: "true",
10591073
},
10601074
})
10611075
}
1062-
if len(selectors) > 0 {
1063-
return &rbacv1.AggregationRule{
1064-
ClusterRoleSelectors: selectors,
1065-
}, nil
1066-
}
1067-
return nil, nil
1076+
1077+
return &rbacv1.AggregationRule{
1078+
ClusterRoleSelectors: selectors,
1079+
}, nil
10681080
}
10691081

10701082
func (a *Operator) ensureOpGroupClusterRoles(op *operatorsv1.OperatorGroup, apis cache.APISet) error {

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

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import (
88
"github.com/sirupsen/logrus/hooks/test"
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
11-
"k8s.io/client-go/metadata/metadatalister"
12-
11+
rbacv1 "k8s.io/api/rbac/v1"
1312
"k8s.io/apimachinery/pkg/api/errors"
1413
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1514
"k8s.io/apimachinery/pkg/labels"
15+
"k8s.io/client-go/metadata/metadatalister"
1616
ktesting "k8s.io/client-go/testing"
1717

1818
"github.com/operator-framework/api/pkg/operators/v1alpha1"
1919
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned/fake"
20+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/cache"
21+
"github.com/operator-framework/operator-registry/pkg/registry"
2022
)
2123

2224
func TestCopyToNamespace(t *testing.T) {
@@ -407,3 +409,65 @@ func TestCSVCopyPrototype(t *testing.T) {
407409
},
408410
}, dst)
409411
}
412+
413+
func TestOperator_getClusterRoleAggregationRule(t *testing.T) {
414+
tests := []struct {
415+
name string
416+
apis cache.APISet
417+
suffix string
418+
want func(*testing.T, *rbacv1.AggregationRule)
419+
wantErr require.ErrorAssertionFunc
420+
}{
421+
{
422+
name: "no aggregation rule when no APIs",
423+
apis: cache.APISet{},
424+
suffix: "admin",
425+
want: func(t *testing.T, rule *rbacv1.AggregationRule) {
426+
require.Nil(t, rule)
427+
},
428+
wantErr: require.NoError,
429+
},
430+
{
431+
name: "ordered selectors in aggregation rule",
432+
apis: cache.APISet{
433+
registry.APIKey{Group: "example.com", Version: "v1alpha1", Kind: "Foo"}: {},
434+
registry.APIKey{Group: "example.com", Version: "v1alpha2", Kind: "Foo"}: {},
435+
registry.APIKey{Group: "example.com", Version: "v1alpha3", Kind: "Foo"}: {},
436+
registry.APIKey{Group: "example.com", Version: "v1alpha4", Kind: "Foo"}: {},
437+
registry.APIKey{Group: "example.com", Version: "v1alpha5", Kind: "Foo"}: {},
438+
registry.APIKey{Group: "example.com", Version: "v1alpha1", Kind: "Bar"}: {},
439+
registry.APIKey{Group: "example.com", Version: "v1alpha2", Kind: "Bar"}: {},
440+
registry.APIKey{Group: "example.com", Version: "v1alpha3", Kind: "Bar"}: {},
441+
registry.APIKey{Group: "example.com", Version: "v1alpha4", Kind: "Bar"}: {},
442+
registry.APIKey{Group: "example.com", Version: "v1alpha5", Kind: "Bar"}: {},
443+
},
444+
suffix: "admin",
445+
want: func(t *testing.T, rule *rbacv1.AggregationRule) {
446+
getOneKey := func(t *testing.T, m map[string]string) string {
447+
require.Len(t, m, 1)
448+
for k := range m {
449+
return k
450+
}
451+
t.Fatalf("no keys found in map")
452+
return ""
453+
}
454+
455+
a := getOneKey(t, rule.ClusterRoleSelectors[0].MatchLabels)
456+
for _, selector := range rule.ClusterRoleSelectors[1:] {
457+
b := getOneKey(t, selector.MatchLabels)
458+
require.Lessf(t, a, b, "expected selector match labels keys to be in sorted ascending order")
459+
a = b
460+
}
461+
},
462+
wantErr: require.NoError,
463+
},
464+
}
465+
for _, tt := range tests {
466+
t.Run(tt.name, func(t *testing.T) {
467+
a := &Operator{}
468+
got, err := a.getClusterRoleAggregationRule(tt.apis, tt.suffix)
469+
tt.wantErr(t, err)
470+
tt.want(t, got)
471+
})
472+
}
473+
}

staging/operator-lifecycle-manager/pkg/controller/registry/resolver/source_registry.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ type RegistrySourceProvider struct {
7575
invalidator *sourceInvalidator
7676
}
7777

78+
const defaultCacheLifetime time.Duration = 30 * time.Minute
79+
7880
func SourceProviderFromRegistryClientProvider(rcp RegistryClientProvider, catsrcLister v1alpha1listers.CatalogSourceLister, logger logrus.StdLogger) *RegistrySourceProvider {
7981
return &RegistrySourceProvider{
8082
rcp: rcp,
8183
logger: logger,
8284
catsrcLister: catsrcLister,
8385
invalidator: &sourceInvalidator{
8486
validChans: make(map[cache.SourceKey]chan struct{}),
85-
ttl: 5 * time.Minute,
87+
ttl: defaultCacheLifetime,
8688
},
8789
}
8890
}

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/operatorgroup.go

Lines changed: 19 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/source_registry.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)