Skip to content

Commit d151050

Browse files
committed
fix(control-plane-operator): align HCCO CatalogSource registryPoll interval with OCP defaults
Changes the OLM CatalogSource registry poll interval from 10m to 240m to match OpenShift Container Platform default behavior. Adds unit tests to verify the RegistryPoll configuration is correctly set and to prevent regressions on the interval value. Signed-off-by: Shital Jadhav <shijadha@redhat.com> Commit-Message-Assisted-by: Claude (via Claude Code)
1 parent 1f2811f commit d151050

2 files changed

Lines changed: 166 additions & 2 deletions

File tree

control-plane-operator/hostedclusterconfigoperator/controllers/resources/olm/catalogs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func reconcileCatalogSource(cs *operatorsv1alpha1.CatalogSource, address string,
4141
Priority: priority,
4242
UpdateStrategy: &operatorsv1alpha1.UpdateStrategy{
4343
RegistryPoll: &operatorsv1alpha1.RegistryPoll{
44-
RawInterval: "10m",
45-
Interval: &metav1.Duration{Duration: 10 * time.Minute},
44+
RawInterval: "240m",
45+
Interval: &metav1.Duration{Duration: 240 * time.Minute},
4646
},
4747
},
4848
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package olm
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
. "github.com/onsi/gomega"
8+
9+
hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
10+
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
13+
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
14+
)
15+
16+
func TestReconcileCertifiedOperatorsCatalogSource(t *testing.T) {
17+
testsCases := []struct {
18+
name string
19+
placement hyperv1.OLMCatalogPlacement
20+
params *OperatorLifecycleManagerParams
21+
}{
22+
{
23+
name: "when placement is Management it should set Address",
24+
placement: hyperv1.ManagementOLMCatalogPlacement,
25+
params: &OperatorLifecycleManagerParams{
26+
CertifiedOperatorsImage: "registry.example.com/certified:latest",
27+
OLMCatalogPlacement: hyperv1.ManagementOLMCatalogPlacement,
28+
},
29+
},
30+
{
31+
name: "when placement is Guest it should set Image",
32+
placement: hyperv1.GuestOLMCatalogPlacement,
33+
params: &OperatorLifecycleManagerParams{
34+
CertifiedOperatorsImage: "registry.example.com/certified:latest",
35+
OLMCatalogPlacement: hyperv1.GuestOLMCatalogPlacement,
36+
},
37+
},
38+
}
39+
40+
for _, tc := range testsCases {
41+
t.Run(tc.name, func(t *testing.T) {
42+
g := NewWithT(t)
43+
cs := &operatorsv1alpha1.CatalogSource{}
44+
45+
ReconcileCertifiedOperatorsCatalogSource(cs, tc.params)
46+
47+
// Verify common fields
48+
g.Expect(cs.Spec.SourceType).To(Equal(operatorsv1alpha1.SourceTypeGrpc))
49+
g.Expect(cs.Spec.DisplayName).To(Equal("Certified Operators"))
50+
g.Expect(cs.Spec.Publisher).To(Equal("Red Hat"))
51+
g.Expect(cs.Spec.Priority).To(Equal(-200))
52+
g.Expect(cs.Spec.GrpcPodConfig.SecurityContextConfig).To(Equal(operatorsv1alpha1.Restricted))
53+
g.Expect(cs.Annotations).To(HaveKeyWithValue("target.workload.openshift.io/management", `{"effect": "PreferredDuringScheduling"}`))
54+
55+
// Verify RegistryPoll interval is 240 minutes
56+
g.Expect(cs.Spec.UpdateStrategy).ToNot(BeNil())
57+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll).ToNot(BeNil())
58+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.Interval).ToNot(BeNil())
59+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.RawInterval).To(Equal("240m"))
60+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.Interval.Duration).To(Equal(240 * time.Minute))
61+
62+
// Verify placement-specific fields
63+
if tc.placement == hyperv1.ManagementOLMCatalogPlacement {
64+
g.Expect(cs.Spec.Address).To(Equal("certified-operators:50051"))
65+
g.Expect(cs.Spec.Image).To(BeEmpty())
66+
} else {
67+
g.Expect(cs.Spec.Image).To(Equal("registry.example.com/certified:latest"))
68+
g.Expect(cs.Spec.Address).To(BeEmpty())
69+
}
70+
})
71+
}
72+
}
73+
74+
func TestReconcileCommunityOperatorsCatalogSource(t *testing.T) {
75+
g := NewWithT(t)
76+
77+
params := &OperatorLifecycleManagerParams{
78+
CommunityOperatorsImage: "registry.example.com/community:latest",
79+
OLMCatalogPlacement: hyperv1.GuestOLMCatalogPlacement,
80+
}
81+
82+
cs := &operatorsv1alpha1.CatalogSource{}
83+
ReconcileCommunityOperatorsCatalogSource(cs, params)
84+
85+
// Verify RegistryPoll interval is 240 minutes
86+
g.Expect(cs.Spec.UpdateStrategy).ToNot(BeNil())
87+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll).ToNot(BeNil())
88+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.Interval).ToNot(BeNil())
89+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.RawInterval).To(Equal("240m"))
90+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.Interval.Duration).To(Equal(240 * time.Minute))
91+
92+
g.Expect(cs.Spec.DisplayName).To(Equal("Community Operators"))
93+
g.Expect(cs.Spec.Priority).To(Equal(-400))
94+
g.Expect(cs.Spec.Image).To(Equal("registry.example.com/community:latest"))
95+
}
96+
97+
func TestReconcileRedHatMarketplaceCatalogSource(t *testing.T) {
98+
g := NewWithT(t)
99+
100+
params := &OperatorLifecycleManagerParams{
101+
RedHatMarketplaceImage: "registry.example.com/marketplace:latest",
102+
OLMCatalogPlacement: hyperv1.ManagementOLMCatalogPlacement,
103+
}
104+
105+
cs := &operatorsv1alpha1.CatalogSource{}
106+
ReconcileRedHatMarketplaceCatalogSource(cs, params)
107+
108+
// Verify RegistryPoll interval is 240 minutes
109+
g.Expect(cs.Spec.UpdateStrategy).ToNot(BeNil())
110+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll).ToNot(BeNil())
111+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.Interval).ToNot(BeNil())
112+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.RawInterval).To(Equal("240m"))
113+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.Interval.Duration).To(Equal(240 * time.Minute))
114+
115+
g.Expect(cs.Spec.DisplayName).To(Equal("Red Hat Marketplace"))
116+
g.Expect(cs.Spec.Priority).To(Equal(-300))
117+
g.Expect(cs.Spec.Address).To(Equal("redhat-marketplace:50051"))
118+
}
119+
120+
func TestReconcileRedHatOperatorsCatalogSource(t *testing.T) {
121+
g := NewWithT(t)
122+
123+
params := &OperatorLifecycleManagerParams{
124+
RedHatOperatorsImage: "registry.example.com/redhat-operators:latest",
125+
OLMCatalogPlacement: hyperv1.GuestOLMCatalogPlacement,
126+
}
127+
128+
cs := &operatorsv1alpha1.CatalogSource{}
129+
ReconcileRedHatOperatorsCatalogSource(cs, params)
130+
131+
// Verify RegistryPoll interval is 240 minutes
132+
g.Expect(cs.Spec.UpdateStrategy).ToNot(BeNil())
133+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll).ToNot(BeNil())
134+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.Interval).ToNot(BeNil())
135+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.RawInterval).To(Equal("240m"))
136+
g.Expect(cs.Spec.UpdateStrategy.RegistryPoll.Interval.Duration).To(Equal(240 * time.Minute))
137+
138+
g.Expect(cs.Spec.DisplayName).To(Equal("Red Hat Operators"))
139+
g.Expect(cs.Spec.Priority).To(Equal(-100))
140+
g.Expect(cs.Spec.Image).To(Equal("registry.example.com/redhat-operators:latest"))
141+
}
142+
143+
func TestReconcileCatalogSourcePreservesExistingAnnotations(t *testing.T) {
144+
g := NewWithT(t)
145+
146+
params := &OperatorLifecycleManagerParams{
147+
RedHatOperatorsImage: "registry.example.com/redhat-operators:latest",
148+
OLMCatalogPlacement: hyperv1.GuestOLMCatalogPlacement,
149+
}
150+
151+
cs := &operatorsv1alpha1.CatalogSource{
152+
ObjectMeta: metav1.ObjectMeta{
153+
Annotations: map[string]string{
154+
"existing-annotation": "existing-value",
155+
},
156+
},
157+
}
158+
159+
ReconcileRedHatOperatorsCatalogSource(cs, params)
160+
161+
// Verify existing annotation is preserved and management annotation is added
162+
g.Expect(cs.Annotations).To(HaveKeyWithValue("existing-annotation", "existing-value"))
163+
g.Expect(cs.Annotations).To(HaveKeyWithValue("target.workload.openshift.io/management", `{"effect": "PreferredDuringScheduling"}`))
164+
}

0 commit comments

Comments
 (0)