Skip to content

Commit

Permalink
Check podGroup CRD for the volcano and the scheudler-plugins as a def…
Browse files Browse the repository at this point in the history
…ault.

Signed-off-by: Syulin7 <[email protected]>
  • Loading branch information
Syulin7 committed Oct 10, 2023
1 parent a4c0cec commit 2735a86
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/training-operator.v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"strings"

"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
Expand Down Expand Up @@ -165,8 +167,12 @@ func setupControllers(mgr ctrl.Manager, enabledSchemes controllerv1.EnabledSchem
cfg := mgr.GetConfig()
volcanoClientSet := volcanoclient.NewForConfigOrDie(cfg)
gangSchedulingSetupFunc = common.GenVolcanoSetupFunc(volcanoClientSet)
gvk := v1beta1.SchemeGroupVersion.WithKind("PodGroup")
validateCRD(mgr, gvk)
} else if gangSchedulerName != "" {
gangSchedulingSetupFunc = common.GenSchedulerPluginsSetupFunc(mgr.GetClient(), gangSchedulerName)
gvk := schedulerpluginsv1alpha1.SchemeGroupVersion.WithKind("PodGroup")
validateCRD(mgr, gvk)
}

// TODO: We need a general manager. all rest reconciler addsToManager
Expand All @@ -187,3 +193,15 @@ func setupControllers(mgr ctrl.Manager, enabledSchemes controllerv1.EnabledSchem
}
}
}

func validateCRD(mgr ctrl.Manager, gvk schema.GroupVersionKind) {
_, err := mgr.GetRESTMapper().RESTMapping(gvk.GroupKind(), gvk.Version)
if err != nil {
if meta.IsNoMatchError(err) {
setupLog.Error(err, "crd might be missing, please install crd", "gvk", gvk.String())
os.Exit(1)
}
setupLog.Error(err, "unable to get crd", "gvk", gvk.String())
os.Exit(1)
}
}

0 comments on commit 2735a86

Please sign in to comment.