Skip to content

Commit

Permalink
Fix createRuntimeClass() error path
Browse files Browse the repository at this point in the history
Errors from Client.Get() other than IsNotFound are silently ignored
instead of being propagated to the caller. Reorganize the code a bit
and add the missing error path.

Signed-off-by: Greg Kurz <groug@kaod.org>
  • Loading branch information
gkurz committed Jun 3, 2022
1 parent 173e7f8 commit 9b8f341
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions controllers/openshift_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,14 @@ func (r *KataConfigOpenShiftReconciler) createRuntimeClass() error {

foundRc := &nodeapi.RuntimeClass{}
err := r.Client.Get(context.TODO(), types.NamespacedName{Name: rc.Name}, foundRc)
if err != nil && k8serrors.IsNotFound(err) {
r.Log.Info("Creating a new RuntimeClass", "rc.Name", rc.Name)
err = r.Client.Create(context.TODO(), rc)
if err != nil {
return err
}
if err != nil && ! k8serrors.IsNotFound(err) {
return err
}

r.Log.Info("Creating a new RuntimeClass", "rc.Name", rc.Name)
err = r.Client.Create(context.TODO(), rc)
if err != nil {
return err
}

if r.kataConfig.Status.RuntimeClass == "" {
Expand Down

0 comments on commit 9b8f341

Please sign in to comment.