@@ -17,8 +17,9 @@ var BundleValidator interfaces.Validator = interfaces.ValidatorFunc(validateBund
17
17
18
18
// max_bundle_size is the maximum size of a bundle in bytes.
19
19
// This ensures the bundle can be staged in a single ConfigMap by OLM during installation.
20
- // The value is derived from the standard upper bound for k8s resources (~4MB).
21
- const max_bundle_size = 4 << (10 * 2 )
20
+ // The value is derived from the standard upper bound for k8s resources (~1MB).
21
+ // We will use this value to check the bundle compressed is < ~1MB
22
+ const max_bundle_size = int64 (1 << (10 * 2 ))
22
23
23
24
func validateBundles (objs ... interface {}) (results []errors.ManifestResult ) {
24
25
for _ , obj := range objs {
@@ -133,23 +134,55 @@ func getOwnedCustomResourceDefintionKeys(csv *operatorsv1alpha1.ClusterServiceVe
133
134
// - we could identify that the bundle size is close to the limit (bigger than 85%)
134
135
func validateBundleSize (bundle * manifests.Bundle ) []errors.Error {
135
136
warnPercent := 0.85
136
- warnSize := int64 (max_bundle_size * warnPercent )
137
+ warnSize := float64 (max_bundle_size ) * warnPercent
137
138
var errs []errors.Error
138
139
139
- if bundle .CompressedSize == nil || * bundle . CompressedSize == 0 {
140
- errs = append (errs , errors .WarnFailedValidation ("unable to check the bundle size" , nil ))
140
+ if bundle .CompressedSize == 0 {
141
+ errs = append (errs , errors .WarnFailedValidation ("unable to check the bundle compressed size" , bundle . Name ))
141
142
return errs
142
143
}
143
144
144
- if * bundle .CompressedSize > max_bundle_size {
145
- errs = append (errs , errors .ErrInvalidBundle (fmt .Sprintf ("maximum bundle compressed size with gzip size exceeded: size=~%d MegaByte, max=%d MegaByte" , * bundle .CompressedSize / (1 << (10 * 2 )), max_bundle_size / (1 << (10 * 2 ))), nil ))
146
- } else if * bundle .CompressedSize > warnSize {
147
- errs = append (errs , errors .WarnInvalidBundle (fmt .Sprintf ("nearing maximum bundle compressed size with gzip: size=~%d MegaByte, max=%d MegaByte" , * bundle .CompressedSize / (1 << (10 * 2 )), max_bundle_size / (1 << (10 * 2 ))), nil ))
145
+ if bundle .Size == 0 {
146
+ errs = append (errs , errors .WarnFailedValidation ("unable to check the bundle size" , bundle .Name ))
147
+ return errs
148
+ }
149
+
150
+ // From OPM (https://github.com/operator-framework/operator-registry) 1.17.5
151
+ // and OLM (https://github.com/operator-framework/operator-lifecycle-manager) : v0.19.0
152
+ // the total size checked is compressed
153
+ if bundle .CompressedSize > max_bundle_size {
154
+ errs = append (errs , errors .ErrInvalidBundle (
155
+ fmt .Sprintf ("maximum bundle compressed size with gzip size exceeded: size=~%s , max=%s. Bundle uncompressed size is %s" ,
156
+ formatBytesInUnit (bundle .CompressedSize ),
157
+ formatBytesInUnit (max_bundle_size ),
158
+ formatBytesInUnit (bundle .Size )),
159
+ bundle .Name ))
160
+ } else if float64 (bundle .CompressedSize ) > warnSize {
161
+ errs = append (errs , errors .WarnInvalidBundle (
162
+ fmt .Sprintf ("nearing maximum bundle compressed size with gzip: size=~%s , max=%s. Bundle uncompressed size is %s" ,
163
+ formatBytesInUnit (bundle .CompressedSize ),
164
+ formatBytesInUnit (max_bundle_size ),
165
+ formatBytesInUnit (bundle .Size )),
166
+ bundle .Name ))
148
167
}
149
168
150
169
return errs
151
170
}
152
171
172
+ func formatBytesInUnit (b int64 ) string {
173
+ const unit = 1000
174
+ if b < unit {
175
+ return fmt .Sprintf ("%d B" , b )
176
+ }
177
+ div , exp := int64 (unit ), 0
178
+ for n := b / unit ; n >= unit ; n /= unit {
179
+ div *= unit
180
+ exp ++
181
+ }
182
+ return fmt .Sprintf ("%.1f %cB" ,
183
+ float64 (b )/ float64 (div ), "kMGTPE" [exp ])
184
+ }
185
+
153
186
// getBundleCRDKeys returns a set of definition keys for all CRDs in bundle.
154
187
func getBundleCRDKeys (bundle * manifests.Bundle ) (keys []schema.GroupVersionKind ) {
155
188
// Collect all v1 and v1beta1 CRD keys, skipping group which CSVs do not support.
0 commit comments