@@ -143,30 +143,36 @@ func NewManager(logger logr.Logger, kubeClient kubeclient.Client, leaderElection
143143 }
144144}
145145
146- func (m * Manager ) ListCRDs (ctx context.Context ) ([]apiextensions.CustomResourceDefinition , error ) {
147- list := apiextensions.CustomResourceDefinitionList {}
146+ // ListCRDs lists ASO CRDs.
147+ // This accepts a list rather than returning one to allow re-using the same list object (they're large and having multiple)
148+ // copies of the collection results in huge memory usage.
149+ func (m * Manager ) ListCRDs (ctx context.Context , list * apiextensions.CustomResourceDefinitionList ) error {
150+ // Clear the existing list, if there is one.
151+ list .Items = nil
152+ list .Continue = ""
153+ list .ResourceVersion = ""
148154
149155 selector := labels .NewSelector ()
150156 requirement , err := labels .NewRequirement (ServiceOperatorAppLabel , selection .Equals , []string {ServiceOperatorAppValue })
151157 if err != nil {
152- return nil , err
158+ return err
153159 }
154160 selector = selector .Add (* requirement )
155161
156162 match := client.MatchingLabelsSelector {
157163 Selector : selector ,
158164 }
159165
160- err = m .kubeClient .List (ctx , & list , match )
166+ err = m .kubeClient .List (ctx , list , match )
161167 if err != nil {
162- return nil , eris .Wrapf (err , "failed to list CRDs" )
168+ return eris .Wrapf (err , "failed to list CRDs" )
163169 }
164170
165171 for _ , crd := range list .Items {
166172 m .logger .V (Verbose ).Info ("Found an existing CRD" , "CRD" , crd .Name )
167173 }
168174
169- return list . Items , nil
175+ return nil
170176}
171177
172178func (m * Manager ) LoadOperatorCRDs (path string , podNamespace string ) ([]apiextensions.CustomResourceDefinition , error ) {
@@ -345,11 +351,11 @@ func (m *Manager) applyCRDs(
345351 // Double-checked locking, we need to make sure once we have the lock there's still work to do, as it may
346352 // already have been done while we were waiting for the lock.
347353 m .logger .V (Status ).Info ("Double-checked locking - ensure there's still CRDs to apply..." )
348- existingCRDs , err := m .ListCRDs (ctx )
354+ err := m .ListCRDs (ctx , options . ExistingCRDs )
349355 if err != nil {
350356 return eris .Wrap (err , "failed to list current CRDs" )
351357 }
352- instructions , err = m .DetermineCRDsToInstallOrUpgrade (goalCRDs , existingCRDs , options .CRDPatterns )
358+ instructions , err = m .DetermineCRDsToInstallOrUpgrade (goalCRDs , options . ExistingCRDs . Items , options .CRDPatterns )
353359 if err != nil {
354360 return eris .Wrap (err , "failed to determine CRDs to apply" )
355361 }
@@ -411,7 +417,7 @@ type Options struct {
411417 Path string
412418 Namespace string
413419 CRDPatterns string
414- ExistingCRDs [] apiextensions.CustomResourceDefinition
420+ ExistingCRDs * apiextensions.CustomResourceDefinitionList
415421}
416422
417423func (m * Manager ) Install (ctx context.Context , options Options ) error {
@@ -420,7 +426,7 @@ func (m *Manager) Install(ctx context.Context, options Options) error {
420426 return eris .Wrap (err , "failed to load CRDs from disk" )
421427 }
422428
423- installationInstructions , err := m .DetermineCRDsToInstallOrUpgrade (goalCRDs , options .ExistingCRDs , options .CRDPatterns )
429+ installationInstructions , err := m .DetermineCRDsToInstallOrUpgrade (goalCRDs , options .ExistingCRDs . Items , options .CRDPatterns )
424430 if err != nil {
425431 return eris .Wrap (err , "failed to determine CRDs to apply" )
426432 }
0 commit comments