Skip to content

Commit 9729433

Browse files
mclasmeierMoritz Clasmeier
andauthored
Parse YAML for CRD identification (#134)
Co-authored-by: Moritz Clasmeier <mclasmeier@redhat.com>
1 parent 2a60f6b commit 9729433

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

internal/deployer/operator.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ func (d *Deployer) downloadAndExtractOperatorBundle(ctx context.Context, bundleI
9191
return bundleDir, nil
9292
}
9393

94-
// identifyCRDFileNames identifies CRD files in the bundle directory
94+
// identifyCRDFileNames identifies CRD files in the bundle directory.
95+
// Returns list of CRD files found in the bundle.
9596
func (d *Deployer) identifyCRDFileNames(bundleDir string) ([]string, error) {
9697
var crdFiles []string
9798

@@ -108,24 +109,22 @@ func (d *Deployer) identifyCRDFileNames(bundleDir string) ([]string, error) {
108109
return nil
109110
}
110111

111-
// TODO(ROX-34499): The following detection logic does not seem particularly robust. We should
112-
// probably parse the YAML and check api group and kind fields.
113-
name := strings.ToLower(info.Name())
114-
if strings.Contains(name, "customresourcedefinition") ||
115-
strings.Contains(name, "platform.stackrox.io") ||
116-
strings.Contains(name, "config.stackrox.io") {
117-
if strings.Contains(name, "clusterserviceversion") {
118-
return nil
119-
}
112+
content, err := os.ReadFile(path)
113+
if err != nil {
114+
d.logger.Warningf("Failed to read file %q from extracted bundle: %v", path, err)
115+
return nil
116+
}
120117

121-
content, err := os.ReadFile(path)
122-
if err != nil {
123-
return nil
124-
}
118+
var meta struct {
119+
Kind string `yaml:"kind"`
120+
}
121+
if err := yaml.Unmarshal(content, &meta); err != nil {
122+
d.logger.Warningf("Failed to unmarshal file %q from extracted bundle: %v", path, err)
123+
return nil
124+
}
125125

126-
if strings.Contains(string(content), "kind: CustomResourceDefinition") {
127-
crdFiles = append(crdFiles, path)
128-
}
126+
if meta.Kind == "CustomResourceDefinition" {
127+
crdFiles = append(crdFiles, path)
129128
}
130129

131130
return nil

0 commit comments

Comments
 (0)