Skip to content

Commit cb63023

Browse files
committed
remove unnecessary flag, optimize catalog watch handler
Signed-off-by: Joe Lanford <[email protected]>
1 parent f301f55 commit cb63023

File tree

2 files changed

+10
-50
lines changed

2 files changed

+10
-50
lines changed

cmd/manager/main.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ func podNamespace() string {
7474

7575
func main() {
7676
var (
77-
metricsAddr string
78-
enableLeaderElection bool
79-
probeAddr string
80-
cachePath string
81-
operatorControllerVersion bool
82-
systemNamespace string
83-
provisionerStorageDirectory string
84-
caCert string
77+
metricsAddr string
78+
enableLeaderElection bool
79+
probeAddr string
80+
cachePath string
81+
operatorControllerVersion bool
82+
systemNamespace string
83+
caCert string
8584
)
8685
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
8786
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -92,7 +91,6 @@ func main() {
9291
flag.StringVar(&cachePath, "cache-path", "/var/cache", "The local directory path used for filesystem based caching")
9392
flag.BoolVar(&operatorControllerVersion, "version", false, "Prints operator-controller version information")
9493
flag.StringVar(&systemNamespace, "system-namespace", "", "Configures the namespace that gets used to deploy system resources.")
95-
flag.StringVar(&provisionerStorageDirectory, "provisioner-storage-dir", storage.DefaultBundleCacheDir, "The directory that is used to store bundle contents.")
9694
opts := zap.Options{
9795
Development: true,
9896
}
@@ -189,7 +187,7 @@ func main() {
189187
}
190188

191189
localStorage := &storage.LocalDirectory{
192-
RootDirectory: provisionerStorageDirectory,
190+
RootDirectory: filepath.Join(cachePath, "bundles"),
193191
URL: url.URL{},
194192
}
195193

internal/controllers/clusterextension_controller.go

+2-40
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"helm.sh/helm/v3/pkg/postrender"
3737
"helm.sh/helm/v3/pkg/release"
3838
"helm.sh/helm/v3/pkg/storage/driver"
39-
corev1 "k8s.io/api/core/v1"
4039
"k8s.io/apimachinery/pkg/api/equality"
4140
apimeta "k8s.io/apimachinery/pkg/api/meta"
4241
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -48,7 +47,6 @@ import (
4847
ctrl "sigs.k8s.io/controller-runtime"
4948
"sigs.k8s.io/controller-runtime/pkg/cache"
5049
"sigs.k8s.io/controller-runtime/pkg/client"
51-
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
5250
crcontroller "sigs.k8s.io/controller-runtime/pkg/controller"
5351
"sigs.k8s.io/controller-runtime/pkg/event"
5452
crhandler "sigs.k8s.io/controller-runtime/pkg/handler"
@@ -574,7 +572,6 @@ func (r *ClusterExtensionReconciler) SetupWithManager(mgr ctrl.Manager) error {
574572
return true
575573
},
576574
}).
577-
Watches(&corev1.Pod{}, mapOwneeToOwnerHandler(mgr.GetClient(), mgr.GetLogger(), &ocv1alpha1.ClusterExtension{})).
578575
Build(r)
579576

580577
if err != nil {
@@ -587,47 +584,12 @@ func (r *ClusterExtensionReconciler) SetupWithManager(mgr ctrl.Manager) error {
587584
return nil
588585
}
589586

590-
func mapOwneeToOwnerHandler(cl client.Client, log logr.Logger, owner client.Object) crhandler.EventHandler {
591-
return crhandler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
592-
ownerGVK, err := apiutil.GVKForObject(owner, cl.Scheme())
593-
if err != nil {
594-
log.Error(err, "map ownee to owner: lookup GVK for owner")
595-
return nil
596-
}
597-
598-
type ownerInfo struct {
599-
key types.NamespacedName
600-
gvk schema.GroupVersionKind
601-
}
602-
var oi *ownerInfo
603-
604-
for _, ref := range obj.GetOwnerReferences() {
605-
gv, err := schema.ParseGroupVersion(ref.APIVersion)
606-
if err != nil {
607-
log.Error(err, fmt.Sprintf("map ownee to owner: parse ownee's owner reference group version %q", ref.APIVersion))
608-
return nil
609-
}
610-
refGVK := gv.WithKind(ref.Kind)
611-
if refGVK == ownerGVK && ref.Controller != nil && *ref.Controller {
612-
oi = &ownerInfo{
613-
key: types.NamespacedName{Name: ref.Name},
614-
gvk: ownerGVK,
615-
}
616-
break
617-
}
618-
}
619-
if oi == nil {
620-
return nil
621-
}
622-
return []reconcile.Request{{NamespacedName: oi.key}}
623-
})
624-
}
625-
626587
// Generate reconcile requests for all cluster extensions affected by a catalog change
627588
func clusterExtensionRequestsForCatalog(c client.Reader, logger logr.Logger) crhandler.MapFunc {
628589
return func(ctx context.Context, _ client.Object) []reconcile.Request {
629590
// no way of associating an extension to a catalog so create reconcile requests for everything
630-
clusterExtensions := ocv1alpha1.ClusterExtensionList{}
591+
clusterExtensions := metav1.PartialObjectMetadataList{}
592+
clusterExtensions.SetGroupVersionKind(ocv1alpha1.GroupVersion.WithKind("ClusterExtensionList"))
631593
err := c.List(ctx, &clusterExtensions)
632594
if err != nil {
633595
logger.Error(err, "unable to enqueue cluster extensions for catalog reconcile")

0 commit comments

Comments
 (0)