11package schemacheck
22
33import (
4+ "errors"
45 "fmt"
56 "os"
67 "path/filepath"
@@ -79,10 +80,10 @@ func (g *generator) Name() string {
7980}
8081
8182// GenGroup runs the schemacheck generator against the given group context.
82- func (g * generator ) GenGroup (groupCtx generation.APIGroupContext ) error {
83+ func (g * generator ) GenGroup (groupCtx generation.APIGroupContext ) ([]generation. Result , error ) {
8384 if g .disabled {
8485 klog .V (2 ).Infof ("Skipping API schema check for %s" , groupCtx .Name )
85- return nil
86+ return nil , nil
8687 }
8788
8889 errs := []error {}
@@ -92,73 +93,80 @@ func (g *generator) GenGroup(groupCtx generation.APIGroupContext) error {
9293 comparatorOptions .DisabledComparators = g .disabledComparators
9394
9495 if err := comparatorOptions .Validate (); err != nil {
95- return fmt .Errorf ("could not validate comparator options: %w" , err )
96+ return nil , fmt .Errorf ("could not validate comparator options: %w" , err )
9697 }
9798
9899 comparatorConfig , err := comparatorOptions .Complete ()
99100 if err != nil {
100- return fmt .Errorf ("could not complete comparator options: %w" , err )
101+ return nil , fmt .Errorf ("could not complete comparator options: %w" , err )
101102 }
102103
104+ var results []generation.Result
105+
103106 for _ , version := range groupCtx .Versions {
104107 klog .V (1 ).Infof ("Verifying API schema for for %s/%s" , groupCtx .Name , version .Name )
105108
106- if err := g .genGroupVersion (groupCtx .Name , version , comparatorConfig ); err != nil {
109+ r , err := g .genGroupVersion (groupCtx .Name , version , comparatorConfig )
110+ if err != nil {
107111 errs = append (errs , fmt .Errorf ("could not run schemacheck generator for group/version %s/%s: %w" , groupCtx .Name , version .Name , err ))
108112 }
113+
114+ results = append (results , r ... )
109115 }
110116
111117 if len (errs ) > 0 {
112- return kerrors .NewAggregate (errs )
118+ return results , kerrors .NewAggregate (errs )
113119 }
114120
115- return nil
121+ return results , nil
116122}
117123
118124// genGroupVersion runs the schemacheck generator against a particular version of the API group.
119- func (g * generator ) genGroupVersion (group string , version generation.APIVersionContext , comparatorConfig * options.ComparatorConfig ) error {
125+ func (g * generator ) genGroupVersion (group string , version generation.APIVersionContext , comparatorConfig * options.ComparatorConfig ) ([]generation. Result , error ) {
120126 contexts , err := loadSchemaCheckGenerationContextsForVersion (version , g .comparisonBase )
121127 if err != nil {
122- return fmt .Errorf ("could not load schema check generation contexts for group/version %s/%s: %w" , group , version .Name , err )
128+ return nil , fmt .Errorf ("could not load schema check generation contexts for group/version %s/%s: %w" , group , version .Name , err )
123129 }
124130
125131 if len (contexts ) == 0 {
126132 klog .V (1 ).Infof ("No CRD manifests found for %s/%s" , group , version .Name )
127- return nil
133+ return nil , nil
128134 }
129135
130136 var manifestErrs []error
137+ var results []generation.Result
131138
132139 for _ , context := range contexts {
133140 klog .V (1 ).Infof ("Verifying schema for %s\n " , context .manifestName )
134141 comparisonResults , errs := comparatorConfig .ComparatorRegistry .Compare (context .oldCRD , context .manifestCRD , comparatorConfig .ComparatorNames ... )
135- if len (errs ) > 0 {
136- return fmt .Errorf ("could not compare manifests for %s: %w" , context .manifestName , kerrors .NewAggregate (errs ))
142+
143+ result := generation.Result {
144+ Generator : g .Name (),
145+ Group : group ,
146+ Version : version .Name ,
147+ Manifest : context .manifestName ,
148+ Errors : errs ,
137149 }
138150
151+ manifestErrs = append (manifestErrs , errs ... )
152+
139153 for _ , comparisonResult := range comparisonResults {
140154 for _ , msg := range comparisonResult .Errors {
141- manifestErrs = append (manifestErrs , fmt .Errorf ("error in %s: %s: %v" , context .manifestName , comparisonResult .Name , msg ))
155+ manifestErrs = append (manifestErrs , errors .New (msg ))
156+ result .Errors = append (result .Errors , errors .New (msg ))
142157 }
143158 }
144-
145159 for _ , comparisonResult := range comparisonResults {
146- for _ , msg := range comparisonResult .Warnings {
147- klog .Warningf ("warning in %s: %s: %v" , context .manifestName , comparisonResult .Name , msg )
148- }
160+ result .Warnings = append (result .Warnings , comparisonResult .Warnings ... )
149161 }
150162 for _ , comparisonResult := range comparisonResults {
151- for _ , msg := range comparisonResult .Infos {
152- klog .Infof ("info in %s: %s: %v" , context .manifestName , comparisonResult .Name , msg )
153- }
163+ result .Info = append (result .Info , comparisonResult .Infos ... )
154164 }
155- }
156165
157- if len (manifestErrs ) > 0 {
158- return kerrors .NewAggregate (manifestErrs )
166+ results = append (results , result )
159167 }
160168
161- return nil
169+ return results , kerrors . NewAggregate ( manifestErrs )
162170}
163171
164172// schemaCheckGenerationContext contains the context required to verify the schema for a particular
0 commit comments