Skip to content

Commit

Permalink
support multiple RuntimeClasses in KataConfig.status.runtimeClass
Browse files Browse the repository at this point in the history
This controller can now create multiple RuntimeClasses, for plain kata
and for peer pods.  However only the original kata RuntimeClass has ever
been accounted for in KataConfig.status.runtimeClass so far.

This is not merely a cosmetic problem.  The controller uses
KataConfig.status.runtimeClass to find out whether there are any pods
using the kata runtime before it removes the runtime from a cluster on
uninstallation.  Since the peer pods RuntimeClass was never represented
in the field so far, running peer pods were ignored on uninstallation.

As for implementation, KataConfig.status.runtimeClass is now optional,
not required.  This doesn't really have to do with the core idea of this
commit, it's more to work around the fact that kubebuilder doesn't seem
to support array fields with an empty array as the default value.

The removal of KataConfig resource immediate Update() after modifying the
runtimeClass field is also not strictly necessary but still included since
such Update()s in the middle of reconciliation can cause problems on a
subsequent Update() ("object has been modified").

Signed-off-by: Pavel Mores <pmores@redhat.com>
  • Loading branch information
pmores committed Sep 22, 2023
1 parent e8c710a commit 0b7aa34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
5 changes: 3 additions & 2 deletions api/v1/kataconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ type KataConfigSpec struct {

// KataConfigStatus defines the observed state of KataConfig
type KataConfigStatus struct {
// RuntimeClass is the name of the runtime class used in CRIO configuration
RuntimeClass string `json:"runtimeClass"`
// RuntimeClass is the names of the RuntimeClasses created by this controller
// +optional
RuntimeClass []string `json:"runtimeClass"`

// +optional
KataNodes KataNodesStatus `json:"kataNodes,omitempty"`
Expand Down
12 changes: 4 additions & 8 deletions controllers/openshift_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ func (r *KataConfigOpenShiftReconciler) listKataPods() error {
}
for _, pod := range podList.Items {
if pod.Spec.RuntimeClassName != nil {
if *pod.Spec.RuntimeClassName == r.kataConfig.Status.RuntimeClass {
return fmt.Errorf("Existing pods using Kata Runtime found. Please delete the pods manually for KataConfig deletion to proceed")
if contains(r.kataConfig.Status.RuntimeClass, *pod.Spec.RuntimeClassName) {
return fmt.Errorf("Existing pods using \"%v\" RuntimeClass found. Please delete the pods manually for KataConfig deletion to proceed", *pod.Spec.RuntimeClassName)
}
}
}
Expand Down Expand Up @@ -751,12 +751,8 @@ func (r *KataConfigOpenShiftReconciler) createRuntimeClass(runtimeClassName stri
}
}

if r.kataConfig.Status.RuntimeClass == "" {
r.kataConfig.Status.RuntimeClass = runtimeClassName
err = r.Client.Status().Update(context.TODO(), r.kataConfig)
if err != nil {
return err
}
if !contains(r.kataConfig.Status.RuntimeClass, runtimeClassName) {
r.kataConfig.Status.RuntimeClass = append(r.kataConfig.Status.RuntimeClass, runtimeClassName)
}

return nil
Expand Down

0 comments on commit 0b7aa34

Please sign in to comment.