From 95f7d1a2a94fb4c4b46403a9e1cae270b7b34953 Mon Sep 17 00:00:00 2001 From: Moritz Clasmeier Date: Mon, 4 May 2026 18:53:03 +0200 Subject: [PATCH 1/2] Parse YAML for CRD identification --- internal/deployer/operator.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/internal/deployer/operator.go b/internal/deployer/operator.go index 2a043936..4737260f 100644 --- a/internal/deployer/operator.go +++ b/internal/deployer/operator.go @@ -91,7 +91,8 @@ func (d *Deployer) downloadAndExtractOperatorBundle(ctx context.Context, bundleI return bundleDir, nil } -// identifyCRDFileNames identifies CRD files in the bundle directory +// identifyCRDFileNames identifies CRD files in the bundle directory. +// Returns list of CRD files found in the bundle. func (d *Deployer) identifyCRDFileNames(bundleDir string) ([]string, error) { var crdFiles []string @@ -108,24 +109,20 @@ func (d *Deployer) identifyCRDFileNames(bundleDir string) ([]string, error) { return nil } - // TODO(ROX-34499): The following detection logic does not seem particularly robust. We should - // probably parse the YAML and check api group and kind fields. - name := strings.ToLower(info.Name()) - if strings.Contains(name, "customresourcedefinition") || - strings.Contains(name, "platform.stackrox.io") || - strings.Contains(name, "config.stackrox.io") { - if strings.Contains(name, "clusterserviceversion") { - return nil - } + content, err := os.ReadFile(path) + if err != nil { + return nil + } - content, err := os.ReadFile(path) - if err != nil { - return nil - } + var meta struct { + Kind string `yaml:"kind"` + } + if err := yaml.Unmarshal(content, &meta); err != nil { + return nil + } - if strings.Contains(string(content), "kind: CustomResourceDefinition") { - crdFiles = append(crdFiles, path) - } + if meta.Kind == "CustomResourceDefinition" { + crdFiles = append(crdFiles, path) } return nil From d9f799e436fd3d642a70f7a263d62043410dd0e2 Mon Sep 17 00:00:00 2001 From: Moritz Clasmeier Date: Tue, 5 May 2026 22:06:59 +0200 Subject: [PATCH 2/2] Add logging --- internal/deployer/operator.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/deployer/operator.go b/internal/deployer/operator.go index 4737260f..e66221e9 100644 --- a/internal/deployer/operator.go +++ b/internal/deployer/operator.go @@ -111,6 +111,7 @@ func (d *Deployer) identifyCRDFileNames(bundleDir string) ([]string, error) { content, err := os.ReadFile(path) if err != nil { + d.logger.Warningf("Failed to read file %q from extracted bundle: %v", path, err) return nil } @@ -118,6 +119,7 @@ func (d *Deployer) identifyCRDFileNames(bundleDir string) ([]string, error) { Kind string `yaml:"kind"` } if err := yaml.Unmarshal(content, &meta); err != nil { + d.logger.Warningf("Failed to unmarshal file %q from extracted bundle: %v", path, err) return nil }