-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: raaizik <[email protected]> Co-Authored-By: Rewant Soni <[email protected]>
- Loading branch information
1 parent
bb238df
commit df31699
Showing
8 changed files
with
104 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package crd | ||
|
||
import ( | ||
"context" | ||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
"k8s.io/klog/v2" | ||
"os" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/builder" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
"slices" | ||
) | ||
|
||
// CustomResourceDefinitionReconciler reconciles a CustomResourceDefinition object | ||
// nolint:revive | ||
type CustomResourceDefinitionReconciler struct { | ||
} | ||
|
||
// Reconcile exits immediately following either a Create or Delete event | ||
func (r *CustomResourceDefinitionReconciler) Reconcile(_ context.Context, _ reconcile.Request) (reconcile.Result, error) { | ||
os.Exit(42) | ||
return reconcile.Result{}, nil | ||
} | ||
|
||
// SetupWithManager sets up a controller with a manager | ||
func (r *CustomResourceDefinitionReconciler) SetupWithManager(crds []string, mgr ctrl.Manager) error { | ||
crdPredicate := predicate.Funcs{ | ||
CreateFunc: func(e event.TypedCreateEvent[client.Object]) bool { | ||
name := string(e.Object.GetName()) | ||
if slices.Contains(crds, name) { | ||
klog.Errorf("CustomResourceDefinition %s was Created. Restarting process.", name) | ||
return true | ||
} | ||
return false | ||
}, | ||
DeleteFunc: func(e event.TypedDeleteEvent[client.Object]) bool { | ||
name := string(e.Object.GetName()) | ||
if slices.Contains(crds, name) { | ||
klog.Errorf("CustomResourceDefinition %s was Deleted. Restarting process.", name) | ||
return true | ||
} | ||
return false | ||
}, | ||
UpdateFunc: func(e event.TypedUpdateEvent[client.Object]) bool { | ||
return false | ||
}, | ||
GenericFunc: func(e event.TypedGenericEvent[client.Object]) bool { | ||
return false | ||
}, | ||
} | ||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&apiextensionsv1.CustomResourceDefinition{}, builder.WithPredicates(crdPredicate)). | ||
Complete(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
RESTART_EXIT_CODE=42 | ||
|
||
while true; do | ||
./usr/local/bin/ocs-operator --enable-leader-election --health-probe-bind-address=:8081 | ||
EXIT_CODE=$? | ||
if [ $EXIT_CODE -ne $RESTART_EXIT_CODE ]; then | ||
exit $EXIT_CODE | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters