Skip to content

Commit f4e2f70

Browse files
authored
Merge branch 'master' into fixConversion
2 parents b4a96c1 + 1fed5af commit f4e2f70

File tree

34 files changed

+764
-568
lines changed

34 files changed

+764
-568
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM quay.io/fedora/fedora:34-x86_64 as builder
1+
FROM quay.io/fedora/fedora:37-x86_64 as builder
22
LABEL stage=builder
33
WORKDIR /build
44

Dockerfile.goreleaser

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=$BUILDPLATFORM gcr.io/distroless/static:debug
1+
FROM gcr.io/distroless/static:debug
22
LABEL stage=olm
33
WORKDIR /
44
# bundle unpack Jobs require cp at /bin/cp

deploy/chart/templates/0000_50_olm_17-upstream-operators.catalogsource.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ spec:
99
image: quay.io/operatorhubio/catalog:latest
1010
displayName: Community Operators
1111
publisher: OperatorHub.io
12+
grpcPodConfig:
13+
securityContextConfig: restricted
1214
updateStrategy:
1315
registryPoll:
1416
interval: 60m

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ require (
225225
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
226226
golang.org/x/sys v0.0.0-20220907062415-87db552b00fd // indirect
227227
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
228-
golang.org/x/text v0.3.7 // indirect
228+
golang.org/x/text v0.3.8 // indirect
229229
golang.org/x/tools v0.1.12 // indirect
230230
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
231231
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect

go.sum

+2-1
Original file line numberDiff line numberDiff line change
@@ -1670,8 +1670,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
16701670
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
16711671
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
16721672
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
1673-
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
16741673
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
1674+
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
1675+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
16751676
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
16761677
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
16771678
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

pkg/controller/operators/catalog/operator.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -749,16 +749,19 @@ func (o *Operator) syncRegistryServer(logger *logrus.Entry, in *v1alpha1.Catalog
749749
logger.Debug("ensured registry server")
750750

751751
// requeue the catalog sync based on the polling interval, for accurate syncs of catalogs with polling enabled
752-
if out.Spec.UpdateStrategy != nil {
753-
if out.Spec.UpdateStrategy.RegistryPoll != nil {
754-
if out.Spec.UpdateStrategy.RegistryPoll.ParsingError != "" && out.Status.Reason != v1alpha1.CatalogSourceIntervalInvalidError {
755-
out.SetError(v1alpha1.CatalogSourceIntervalInvalidError, fmt.Errorf(out.Spec.UpdateStrategy.RegistryPoll.ParsingError))
756-
}
757-
logger.Debugf("requeuing registry server sync based on polling interval %s", out.Spec.UpdateStrategy.Interval.Duration.String())
758-
resyncPeriod := reconciler.SyncRegistryUpdateInterval(out, time.Now())
759-
o.catsrcQueueSet.RequeueAfter(out.GetNamespace(), out.GetName(), queueinformer.ResyncWithJitter(resyncPeriod, 0.1)())
752+
if out.Spec.UpdateStrategy != nil && out.Spec.UpdateStrategy.RegistryPoll != nil {
753+
if out.Spec.UpdateStrategy.Interval == nil {
754+
syncError = fmt.Errorf("empty polling interval; cannot requeue registry server sync without a provided polling interval")
755+
out.SetError(v1alpha1.CatalogSourceIntervalInvalidError, syncError)
760756
return
761757
}
758+
if out.Spec.UpdateStrategy.RegistryPoll.ParsingError != "" && out.Status.Reason != v1alpha1.CatalogSourceIntervalInvalidError {
759+
out.SetError(v1alpha1.CatalogSourceIntervalInvalidError, fmt.Errorf(out.Spec.UpdateStrategy.RegistryPoll.ParsingError))
760+
}
761+
logger.Debugf("requeuing registry server sync based on polling interval %s", out.Spec.UpdateStrategy.Interval.Duration.String())
762+
resyncPeriod := reconciler.SyncRegistryUpdateInterval(out, time.Now())
763+
o.catsrcQueueSet.RequeueAfter(out.GetNamespace(), out.GetName(), queueinformer.ResyncWithJitter(resyncPeriod, 0.1)())
764+
return
762765
}
763766

764767
if err := o.sources.Remove(sourceKey); err != nil {

pkg/controller/operators/catalog/operator_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,54 @@ func TestValidateExistingCRs(t *testing.T) {
14151415
}
14161416
}
14171417

1418+
func TestSyncRegistryServer(t *testing.T) {
1419+
namespace := "ns"
1420+
1421+
tests := []struct {
1422+
testName string
1423+
err error
1424+
catSrc *v1alpha1.CatalogSource
1425+
clientObjs []runtime.Object
1426+
}{
1427+
{
1428+
testName: "EmptyRegistryPoll",
1429+
err: fmt.Errorf("empty polling interval; cannot requeue registry server sync without a provided polling interval"),
1430+
catSrc: &v1alpha1.CatalogSource{
1431+
Spec: v1alpha1.CatalogSourceSpec{
1432+
UpdateStrategy: &v1alpha1.UpdateStrategy{
1433+
RegistryPoll: &v1alpha1.RegistryPoll{},
1434+
},
1435+
},
1436+
},
1437+
},
1438+
}
1439+
1440+
for _, tt := range tests {
1441+
t.Run(tt.testName, func(t *testing.T) {
1442+
ctx, cancel := context.WithCancel(context.TODO())
1443+
defer cancel()
1444+
1445+
tt.clientObjs = append(tt.clientObjs, tt.catSrc)
1446+
op, err := NewFakeOperator(ctx, namespace, []string{namespace}, withClientObjs(tt.clientObjs...))
1447+
require.NoError(t, err)
1448+
1449+
op.reconciler = &fakes.FakeRegistryReconcilerFactory{
1450+
ReconcilerForSourceStub: func(source *v1alpha1.CatalogSource) reconciler.RegistryReconciler {
1451+
return &fakes.FakeRegistryReconciler{
1452+
EnsureRegistryServerStub: func(source *v1alpha1.CatalogSource) error {
1453+
return nil
1454+
},
1455+
}
1456+
},
1457+
}
1458+
require.NotPanics(t, func() {
1459+
_, _, err = op.syncRegistryServer(logrus.NewEntry(op.logger), tt.catSrc)
1460+
})
1461+
require.Equal(t, tt.err, err)
1462+
})
1463+
}
1464+
}
1465+
14181466
func fakeConfigMapData() map[string]string {
14191467
data := make(map[string]string)
14201468
yaml, err := yaml.Marshal([]apiextensionsv1beta1.CustomResourceDefinition{crd("fake-crd")})

pkg/controller/registry/reconciler/reconciler.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,9 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, img string, saNam
162162
Command: []string{"grpc_health_probe", "-addr=:50051"},
163163
},
164164
},
165-
FailureThreshold: 15,
165+
FailureThreshold: 10,
166166
PeriodSeconds: 10,
167+
TimeoutSeconds: 5,
167168
},
168169
Resources: corev1.ResourceRequirements{
169170
Requests: corev1.ResourceList{

pkg/metrics/metrics.go

+36-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package metrics
22

33
import (
4+
"sync"
45
"time"
56

67
"github.com/prometheus/client_golang/prometheus"
@@ -199,12 +200,37 @@ var (
199200
},
200201
)
201202

202-
// subscriptionSyncCounters keeps a record of the Prometheus counters emitted by
203-
// Subscription objects. The key of a record is the Subscription name, while the value
204-
// is struct containing label values used in the counter
205-
subscriptionSyncCounters = make(map[string]subscriptionSyncLabelValues)
203+
subscriptionSyncCounters = newSubscriptionSyncCounter()
206204
)
207205

206+
// subscriptionSyncCounter keeps a record of the Prometheus counters emitted by
207+
// Subscription objects. The key of a record is the Subscription name, while the value
208+
// is struct containing label values used in the counter. Read and Write access are
209+
// protected by mutex.
210+
type subscriptionSyncCounter struct {
211+
counters map[string]subscriptionSyncLabelValues
212+
countersLock sync.RWMutex
213+
}
214+
215+
func newSubscriptionSyncCounter() subscriptionSyncCounter {
216+
return subscriptionSyncCounter{
217+
counters: make(map[string]subscriptionSyncLabelValues),
218+
}
219+
}
220+
221+
func (s *subscriptionSyncCounter) setValues(key string, val subscriptionSyncLabelValues) {
222+
s.countersLock.Lock()
223+
defer s.countersLock.Unlock()
224+
s.counters[key] = val
225+
}
226+
227+
func (s *subscriptionSyncCounter) readValues(key string) (subscriptionSyncLabelValues, bool) {
228+
s.countersLock.RLock()
229+
defer s.countersLock.RUnlock()
230+
val, ok := s.counters[key]
231+
return val, ok
232+
}
233+
208234
type subscriptionSyncLabelValues struct {
209235
installedCSV string
210236
pkg string
@@ -280,14 +306,15 @@ func EmitSubMetric(sub *operatorsv1alpha1.Subscription) {
280306
if sub.Spec == nil {
281307
return
282308
}
309+
283310
SubscriptionSyncCount.WithLabelValues(sub.GetName(), sub.Status.InstalledCSV, sub.Spec.Channel, sub.Spec.Package, string(sub.Spec.InstallPlanApproval)).Inc()
284-
if _, present := subscriptionSyncCounters[sub.GetName()]; !present {
285-
subscriptionSyncCounters[sub.GetName()] = subscriptionSyncLabelValues{
311+
if _, present := subscriptionSyncCounters.readValues(sub.GetName()); !present {
312+
subscriptionSyncCounters.setValues(sub.GetName(), subscriptionSyncLabelValues{
286313
installedCSV: sub.Status.InstalledCSV,
287314
pkg: sub.Spec.Package,
288315
channel: sub.Spec.Channel,
289316
approvalStrategy: string(sub.Spec.InstallPlanApproval),
290-
}
317+
})
291318
}
292319
}
293320

@@ -302,7 +329,7 @@ func UpdateSubsSyncCounterStorage(sub *operatorsv1alpha1.Subscription) {
302329
if sub.Spec == nil {
303330
return
304331
}
305-
counterValues := subscriptionSyncCounters[sub.GetName()]
332+
counterValues, _ := subscriptionSyncCounters.readValues(sub.GetName())
306333
approvalStrategy := string(sub.Spec.InstallPlanApproval)
307334

308335
if sub.Spec.Channel != counterValues.channel ||
@@ -317,7 +344,7 @@ func UpdateSubsSyncCounterStorage(sub *operatorsv1alpha1.Subscription) {
317344
counterValues.channel = sub.Spec.Channel
318345
counterValues.approvalStrategy = approvalStrategy
319346

320-
subscriptionSyncCounters[sub.GetName()] = counterValues
347+
subscriptionSyncCounters.setValues(sub.GetName(), counterValues)
321348
}
322349
}
323350

pkg/metrics/metrics_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package metrics_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
9+
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
10+
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
11+
)
12+
13+
func TestUpdateSubsSyncCounterStorageThreadSafety(t *testing.T) {
14+
for i := 0; i < 1000; i++ {
15+
go func(ii int) {
16+
sub := &operatorsv1alpha1.Subscription{
17+
ObjectMeta: metav1.ObjectMeta{
18+
Namespace: "foo",
19+
Name: "foo",
20+
},
21+
Spec: &operatorsv1alpha1.SubscriptionSpec{
22+
Channel: "foo",
23+
Package: "foo",
24+
InstallPlanApproval: "automatic",
25+
},
26+
Status: operatorsv1alpha1.SubscriptionStatus{
27+
InstalledCSV: "foo",
28+
},
29+
}
30+
sub.Spec.Channel = fmt.Sprintf("bar-%v", ii)
31+
metrics.UpdateSubsSyncCounterStorage(sub)
32+
}(i)
33+
}
34+
}

vendor/golang.org/x/text/AUTHORS

-3
This file was deleted.

vendor/golang.org/x/text/CONTRIBUTORS

-3
This file was deleted.

vendor/golang.org/x/text/encoding/htmlindex/tables.go

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/text/encoding/internal/identifier/mib.go

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/text/encoding/simplifiedchinese/gbk.go

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/text/internal/language/compact/tables.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/golang.org/x/text/internal/language/lookup.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)