Wednesday, August 14, 2019

Error:no kind is registered in scheme pkg/runtime/scheme.go:101

Symptom:

  When we create controller operator via kubebuilder 2.0  we add deployment type in our controller. But it error out when we "make run"
"no kind is registered for the type v1.Deployment in scheme \"pkg/runtime/scheme.go:101\"

Solution:

   Per kubebuilder 2.0 , "Every set of controllers needs a Scheme, which provides mappings between Kinds and their corresponding Go types."
   We need to add deployment type and all other related to scheme.  Then we can use those objects in our controller.
sample codes :

import (
"flag"
"os"
theapexordsv1 "apexords-operator/api/v1"
"apexords-operator/controllers"
appsv1beta1 "k8s.io/api/apps/v1beta1"
corev1 "k8s.io/api/core/v1"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/runtime"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

)
var (
scheme   = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)
func init() {
appsv1beta1.AddToScheme(scheme)
appsv1.AddToScheme(scheme)
corev1.AddToScheme(scheme)
theapexordsv1.AddToScheme(scheme)

}

2 comments:

Denis Trofimov said...

Hey Henry!
Thank you for a useful advice!

Nony said...

THANK YOU!!