MCPcopy
hub / github.com/operator-framework/operator-sdk / ValidateBundleContent

Function ValidateBundleContent

internal/registry/validate.go:37–102  ·  view source on GitHub ↗

ValidateBundleContent confirms that the CSV and CRD files inside the bundle directory are valid and can be installed in a cluster. Other GVK types are also validated to confirm if they are "kubectl-able" to a cluster meaning if they can be applied to a cluster using `kubectl` provided users have all

(logger *log.Entry, bundle *apimanifests.Bundle, mediaType string)

Source from the content-addressed store, hash-verified

35// if they can be applied to a cluster using `kubectl` provided users have all
36// necessary permissions and configurations.
37func ValidateBundleContent(logger *log.Entry, bundle *apimanifests.Bundle, mediaType string) []apierrors.ManifestResult {
38 if logger == nil {
39 logger = DiscardLogger()
40 }
41
42 // Use errs to collect bundle-level validation errors.
43 errs := apierrors.ManifestResult{
44 Name: bundle.Name,
45 }
46
47 logger.Debug("Validating bundle contents")
48
49 // helm+vX media types are not supported by this validation function.
50 switch mediaType {
51 case registrybundle.HelmType:
52 return []apierrors.ManifestResult{errs}
53 }
54
55 for _, u := range bundle.Objects {
56 // CSVs and CRDs will be validated separately.
57 gvk := u.GetObjectKind().GroupVersionKind()
58 if gvk.Kind == "ClusterServiceVersion" || gvk.Kind == "CustomResourceDefinition" {
59 continue
60 }
61
62 logger.Debugf("Validating %s %q", gvk, u.GetName())
63
64 // Verify if the object kind is supported for registry+v1 format.
65 supported, _ := registrybundle.IsSupported(gvk.Kind)
66 if mediaType == registrybundle.RegistryV1Type && !supported {
67 errs.Add(apierrors.ErrInvalidBundle(fmt.Sprintf("unsupported media type %s for bundle object", mediaType), gvk))
68 continue
69 }
70
71 if err := validateObject(metav1.Object(u)); err != nil {
72 errs.Add(apierrors.ErrFailedValidation(err.Error(), u.GetName()))
73 }
74 }
75
76 // Validate bundle itself.
77 results := apivalidation.BundleValidator.Validate(bundle)
78
79 // All bundles must have a CSV currently.
80 if bundle.CSV != nil {
81 results = append(results, apivalidation.ClusterServiceVersionValidator.Validate(bundle.CSV)...)
82 } else {
83 errs.Add(apierrors.ErrInvalidBundle("no ClusterServiceVersion in bundle", bundle.Name))
84 }
85
86 // Validate all CRD versions in the bundle together.
87 var crds []any
88 for _, crd := range bundle.V1beta1CRDs {
89 crds = append(crds, crd)
90 }
91 for _, crd := range bundle.V1CRDs {
92 crds = append(crds, crd)
93 }
94 if len(crds) != 0 {

Callers

nothing calls this directly

Calls 5

DiscardLoggerFunction · 0.85
validateObjectFunction · 0.85
appendResultFunction · 0.85
ErrorMethod · 0.45
ValidateMethod · 0.45

Tested by

no test coverage detected