@@ -171,16 +171,16 @@ func (k *Auth) processNextItem() bool {
171171 return true
172172}
173173
174- func (k * Auth ) updatePolicies (cm * apiv1.ConfigMap , key string ) {
174+ func (k * Auth ) updatePolicies (cm * apiv1.ConfigMap , key string ) error {
175175 klog .Info ("ConfigMap created or updated, will update the authorization policy." )
176176
177177 var policy policyList
178178 if err := json .Unmarshal ([]byte (cm .Data ["policies" ]), & policy ); err != nil {
179- runtimeutil . HandleError ( fmt .Errorf ("failed to parse policies defined in the configmap %s: %v " , key , err ) )
179+ return fmt .Errorf ("failed to parse policies defined in the configmap %s: %w " , key , err )
180180 }
181181 if len (policy ) > 0 {
182182 if _ , err := json .MarshalIndent (policy , "" , " " ); err != nil {
183- runtimeutil . HandleError ( fmt .Errorf ("failed to parse policies defined in the configmap %s: %v " , key , err ) )
183+ return fmt .Errorf ("failed to parse policies defined in the configmap %s: %w " , key , err )
184184 }
185185 }
186186
@@ -189,23 +189,26 @@ func (k *Auth) updatePolicies(cm *apiv1.ConfigMap, key string) {
189189 k .authz .mu .Unlock ()
190190
191191 klog .Infof ("Authorization policy updated." )
192+ return nil
192193}
193194
194- func (k * Auth ) updateSyncConfig (cm * apiv1.ConfigMap , key string ) {
195+ func (k * Auth ) updateSyncConfig (cm * apiv1.ConfigMap , key string ) error {
195196 klog .Info ("ConfigMap created or updated, will update the sync configuration." )
196197
197- var sc * syncConfig
198- newConfig := newSyncConfig ()
199- sc = & newConfig
200- if err := yaml .Unmarshal ([]byte (cm .Data ["syncConfig" ]), sc ); err != nil {
201- runtimeutil .HandleError (fmt .Errorf ("failed to parse sync config defined in the configmap %s: %v" , key , err ))
198+ sc := newSyncConfig ()
199+ if err := yaml .Unmarshal ([]byte (cm .Data ["syncConfig" ]), & sc ); err != nil {
200+ return fmt .Errorf ("failed to parse sync config defined in the configmap %s: %w" , key , err )
201+ }
202+ if err := sc .validate (); err != nil {
203+ return fmt .Errorf ("sync config defined in the configmap %s is invalid: %w" , key , err )
202204 }
203205
204206 k .syncer .mu .Lock ()
205- k .syncer .syncConfig = sc
207+ k .syncer .syncConfig = & sc
206208 k .syncer .mu .Unlock ()
207209
208210 klog .Infof ("Sync configuration updated." )
211+ return nil
209212}
210213
211214func (k * Auth ) processItem (key string ) error {
@@ -234,10 +237,14 @@ func (k *Auth) processItem(key string) error {
234237 return fmt .Errorf ("error fetching object with key %s: %v" , key , err )
235238 default :
236239 if name == k .config .PolicyConfigMapName {
237- k .updatePolicies (cm , key )
240+ if err := k .updatePolicies (cm , key ); err != nil {
241+ return err
242+ }
238243 }
239244 if name == k .config .SyncConfigMapName {
240- k .updateSyncConfig (cm , key )
245+ if err := k .updateSyncConfig (cm , key ); err != nil {
246+ return err
247+ }
241248 }
242249 }
243250
0 commit comments