Skip to content

Commit

Permalink
Add sample dynamic reconciler
Browse files Browse the repository at this point in the history
Signed-off-by: SK Ali Arman <[email protected]>
  • Loading branch information
sheikh-arman committed Dec 15, 2023
1 parent 3359bba commit 89b9760
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 111 deletions.
4 changes: 2 additions & 2 deletions cmd/dynamic-controller/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func (sg *ProviderGenerator) generate(group string, versionPkgList []string, sho
importData += rmDot[0] + " " + "\"" + pkgPath + "\"\n"

if group == "azure" {
kindMapData += "schema.GroupKind{\"" + kind + "." + group + ".kubedb.com\", "
kindMapData += "schema.GroupKind{\"" + group + ".kubedb.com\", "
} else {
kindMapData += "schema.GroupKind{\"" + kind + "." + group + ".azure.kubedb.com\", "
kindMapData += "schema.GroupKind{\"" + group + ".azure.kubedb.com\", "
}
kindMapData += "\"" + groupKind[kind] + "\"}: " + aliases[i] + "Setup,\n"
}
Expand Down
22 changes: 0 additions & 22 deletions internal/controller/crd_controller.go.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1,27 @@
//package controller



/*
var(
gk2 = schema.GroupKind{"azure.kubedb.com", "ResourceGroup"}
gk3 = schema.GroupKind{"azure.kubedb.com", "ProviderConfig"}
setupFns = map[schema.GroupKind]func(ctrl.Manager, controller.Options) error{
gk2: resourcegroup.Setup,
gk3: providerregistration.Setup,
}
)
*/

var (

setupDone = map[schema.GroupKind]bool{}
mu sync.RWMutex
)

//func SetupControllerList(mgr ctrl.Manager, o controller.Options) error {
//
//}

type CustomResourceReconciler struct {
mgr ctrl.Manager
o controller.Options
}

func NewCustomResourceReconciler(mgr ctrl.Manager, o controller.Options) *CustomResourceReconciler {
//if err := SetupControllerList(mgr, o); err != nil {
// log.Error(err, "unable to fetch CustomResourceDefinition")
//}
return &CustomResourceReconciler{mgr: mgr, o: o}
}

func (r *CustomResourceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)

var crd apiextensions.CustomResourceDefinition
if err := r.mgr.GetClient().Get(ctx, req.NamespacedName, &crd); err != nil {
log.Error(err, "unable to fetch CustomResourceDefinition")
return ctrl.Result{}, client.IgnoreNotFound(err)
}

gk := schema.GroupKind{
Group: crd.Spec.Group,
Kind: crd.Spec.Names.Kind,
Expand Down
Loading

0 comments on commit 89b9760

Please sign in to comment.