Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions internal/deployer/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -108,24 +109,22 @@ 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 {
d.logger.Warningf("Failed to read file %q from extracted bundle: %v", path, err)
return nil
Comment thread
mclasmeier marked this conversation as resolved.
}

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that these files are sizes are rather large and that we only need a single string from them, would it make sense to use a streaming decoder that doesn't require allocating memory for the whole file?

d.logger.Warningf("Failed to unmarshal file %q from extracted bundle: %v", path, err)
return nil
}

if strings.Contains(string(content), "kind: CustomResourceDefinition") {
crdFiles = append(crdFiles, path)
}
if meta.Kind == "CustomResourceDefinition" {
crdFiles = append(crdFiles, path)
}

return nil
Expand Down
Loading