forked from red-hat-storage/ocs-client-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
controllers: available CRDs check feature
Reasons for this enhancement: - A controller cannot set up a watch for a CRD that is not installed on the cluster, trying to set up a watch will panic the operator - There is no known way, that we are aware of, to add a watch later without client cache issue How does the enhancement work around the issue: - On start of the operator(main), detect which CRDs are avail - At the start each reconcile of controller, we fetch the CRD of interest and compare it with CRDs fetched in previous step, If there is any change, we panic the op Signed-off-by: Rewant Soni <[email protected]> Signed-off-by: raaizik <[email protected]>
- Loading branch information
1 parent
037e1ed
commit 63a30c0
Showing
33 changed files
with
4,154 additions
and
6 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
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,39 @@ | ||
package utils | ||
|
||
import ( | ||
"github.com/go-logr/logr" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/controller-runtime/pkg/predicate" | ||
) | ||
|
||
// Name Predicate return a predicate the filter events produced | ||
// by resources that matches the given name | ||
func NamePredicate(name string) predicate.Predicate { | ||
return predicate.NewPredicateFuncs(func(obj client.Object) bool { | ||
return obj.GetName() == name | ||
}) | ||
} | ||
|
||
func CrdCreateAndDeletePredicate(log *logr.Logger, crdName string, crdExists bool) predicate.Predicate { | ||
return predicate.Funcs{ | ||
CreateFunc: func(_ event.CreateEvent) bool { | ||
if !crdExists { | ||
log.Info("CustomResourceDefinition %s was Created.", crdName) | ||
} | ||
return !crdExists | ||
}, | ||
DeleteFunc: func(_ event.DeleteEvent) bool { | ||
if crdExists { | ||
log.Info("CustomResourceDefinition %s was Deleted.", crdName) | ||
} | ||
return crdExists | ||
}, | ||
UpdateFunc: func(_ event.UpdateEvent) bool { | ||
return false | ||
}, | ||
GenericFunc: func(_ event.GenericEvent) bool { | ||
return false | ||
}, | ||
} | ||
} |
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
Oops, something went wrong.