@@ -9,12 +9,22 @@ import (
99 "time"
1010
1111 releasecontroller "github.com/openshift/release-controller/pkg/release-controller"
12-
12+ "github.com/openshift/release-controller/pkg/releasequalifiers"
1313 "gopkg.in/robfig/cron.v2"
14+ "gopkg.in/yaml.v2"
1415 utilerrors "k8s.io/apimachinery/pkg/util/errors"
1516)
1617
17- func validateConfigs (configDir string ) error {
18+ func validateConfigs (options * options ) error {
19+ errors := []error {}
20+ errors = append (errors , validateReleaseConfigs (options .validateConfigs ))
21+ if len (options .ReleaseQualifiersConfigPath ) > 0 {
22+ errors = append (errors , validateReleaseQualifiersConfig (options .ReleaseQualifiersConfigPath )... )
23+ }
24+ return utilerrors .NewAggregate (errors )
25+ }
26+
27+ func validateReleaseConfigs (configDir string ) error {
1828 errors := []error {}
1929 releaseConfigs := []releasecontroller.ReleaseConfig {}
2030 err := filepath .Walk (configDir , func (path string , info os.FileInfo , err error ) error {
@@ -37,8 +47,10 @@ func validateConfigs(configDir string) error {
3747 if err != nil {
3848 return fmt .Errorf ("error encountered while trying to read config files: %w" , err )
3949 }
50+ errors = append (errors , validateUpgradeJobs (releaseConfigs )... )
4051 errors = append (errors , verifyPeriodicFields (releaseConfigs )... )
4152 errors = append (errors , findDuplicatePeriodics (releaseConfigs )... )
53+ errors = append (errors , validateQualifiers (releaseConfigs )... )
4254 return utilerrors .NewAggregate (errors )
4355}
4456
@@ -105,3 +117,46 @@ func findDuplicatePeriodics(releaseConfigs []releasecontroller.ReleaseConfig) []
105117 }
106118 return duplicates
107119}
120+
121+ // validateQualifiers validates the contents of releasequalifiers.ReleaseQualifiers defined in releasecontroller.ReleaseConfig
122+ func validateQualifiers (releaseConfigs []releasecontroller.ReleaseConfig ) []error {
123+ errors := []error {}
124+ for _ , config := range releaseConfigs {
125+ for verificationName , verification := range config .Verify {
126+ for qualifierId , overrides := range verification .Qualifiers {
127+ if err := validateQualifier (qualifierId , overrides ); err != nil {
128+ errors = append (errors , fmt .Errorf ("unable to validate %q release qualifier %s: %v" , verificationName , qualifierId , err ))
129+ }
130+ }
131+ }
132+ }
133+ return errors
134+ }
135+
136+ // validateReleaseQualifiersConfig validates the contents of the file located at options.ReleaseQualifiersConfigPath
137+ func validateReleaseQualifiersConfig (configPath string ) []error {
138+ errors := []error {}
139+ raw , err := os .ReadFile (configPath )
140+ if err != nil {
141+ return errors
142+ }
143+ config := releasecontroller.ReleaseQualifiersConfig {}
144+ dec := yaml .NewDecoder (bytes .NewReader (raw ))
145+ dec .SetStrict (true )
146+ if err = dec .Decode (& config ); err != nil {
147+ errors = append (errors , fmt .Errorf ("failed to unmarshal release qualifier configuration file %s: %v" , configPath , err ))
148+ return errors
149+ }
150+ for qualifierId , overrides := range config .Qualifiers {
151+ errors = append (errors , validateQualifier (qualifierId , overrides ))
152+ }
153+ return errors
154+ }
155+
156+ func validateQualifier (name releasequalifiers.QualifierId , qualifier releasequalifiers.ReleaseQualifier ) error {
157+ err := qualifier .Validate ()
158+ if err != nil {
159+ return fmt .Errorf ("unable to validate qualifier %s: %v" , name , err )
160+ }
161+ return nil
162+ }
0 commit comments