Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 83
✨ wire up ServiceAccount based caching layer#1074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package authentication | ||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| utilnet "k8s.io/apimachinery/pkg/util/net" | ||
| ) | ||
| var _ http.RoundTripper = (*TokenInjectingRoundTripper)(nil) | ||
| type TokenInjectingRoundTripper struct { | ||
| Tripper http.RoundTripper | ||
| TokenGetter *TokenGetter | ||
| Key types.NamespacedName | ||
| } | ||
| func (tt *TokenInjectingRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { | ||
| resp, err := tt.do(req) | ||
| if resp != nil && resp.StatusCode == http.StatusUnauthorized { | ||
| tt.TokenGetter.Delete(tt.Key) | ||
| resp, err = tt.do(req) | ||
| } | ||
| return resp, err | ||
| } | ||
| func (tt *TokenInjectingRoundTripper) do(req *http.Request) (*http.Response, error) { | ||
| reqClone := utilnet.CloneRequest(req) | ||
| token, err := tt.TokenGetter.Get(reqClone.Context(), tt.Key) | ||
| if err != nil { | ||
| return nil, err | ||
everettraven marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| // Always set the Authorization header to our retrieved token | ||
| reqClone.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) | ||
| return tt.Tripper.RoundTrip(reqClone) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -24,7 +24,6 @@ import ( | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
| "github.com/go-logr/logr" | ||
| @@ -39,7 +38,6 @@ import ( | ||
| apimeta "k8s.io/apimachinery/pkg/api/meta" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/apimachinery/pkg/util/sets" | ||
| apimachyaml "k8s.io/apimachinery/pkg/util/yaml" | ||
| @@ -54,7 +52,6 @@ import ( | ||
| "sigs.k8s.io/controller-runtime/pkg/log" | ||
| "sigs.k8s.io/controller-runtime/pkg/predicate" | ||
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
| "sigs.k8s.io/controller-runtime/pkg/source" | ||
| "github.com/operator-framework/api/pkg/operators/v1alpha1" | ||
| catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1" | ||
| @@ -65,6 +62,7 @@ import ( | ||
| ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" | ||
| "github.com/operator-framework/operator-controller/internal/bundleutil" | ||
| "github.com/operator-framework/operator-controller/internal/conditionsets" | ||
| "github.com/operator-framework/operator-controller/internal/contentmanager" | ||
| "github.com/operator-framework/operator-controller/internal/labels" | ||
| "github.com/operator-framework/operator-controller/internal/resolve" | ||
| "github.com/operator-framework/operator-controller/internal/rukpak/convert" | ||
| @@ -83,8 +81,7 @@ type ClusterExtensionReconciler struct { | ||
| Resolver resolve.Resolver | ||
| Unpacker rukpaksource.Unpacker | ||
| ActionClientGetter helmclient.ActionClientGetter | ||
| dynamicWatchMutex sync.RWMutex | ||
| dynamicWatchGVKs sets.Set[schema.GroupVersionKind] | ||
| Watcher contentmanager.Watcher | ||
| controller crcontroller.Controller | ||
| cache cache.Cache | ||
| InstalledBundleGetter InstalledBundleGetter | ||
| @@ -119,9 +116,6 @@ type Preflight interface { | ||
| //+kubebuilder:rbac:groups=core,resources=serviceaccounts/token,verbs=create | ||
| //+kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get | ||
| // TODO: Remove these permissions as part of resolving https://github.com/operator-framework/operator-controller/issues/975 | ||
| //+kubebuilder:rbac:groups=*,resources=*,verbs=* | ||
| //+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=clustercatalogs,verbs=list;watch | ||
| //+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=catalogmetadata,verbs=list;watch | ||
| @@ -134,7 +128,7 @@ func (r *ClusterExtensionReconciler) Reconcile(ctx context.Context, req ctrl.Req | ||
| l.V(1).Info("reconcile starting") | ||
| defer l.V(1).Info("reconcile ending") | ||
| var existingExt = &ocv1alpha1.ClusterExtension{} | ||
| existingExt := &ocv1alpha1.ClusterExtension{} | ||
| if err := r.Client.Get(ctx, req.NamespacedName, existingExt); err != nil { | ||
| return ctrl.Result{}, client.IgnoreNotFound(err) | ||
| } | ||
| @@ -403,36 +397,17 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp | ||
| return ctrl.Result{}, err | ||
| } | ||
| for _, obj := range relObjects { | ||
| if err := func() error { | ||
| r.dynamicWatchMutex.Lock() | ||
| defer r.dynamicWatchMutex.Unlock() | ||
| _, isWatched := r.dynamicWatchGVKs[obj.GetObjectKind().GroupVersionKind()] | ||
| if !isWatched { | ||
| if err := r.controller.Watch( | ||
| source.Kind(r.cache, | ||
| obj, | ||
| crhandler.EnqueueRequestForOwner(r.Scheme(), r.RESTMapper(), ext, crhandler.OnlyControllerOwner()), | ||
| predicate.Funcs{ | ||
| CreateFunc: func(ce event.CreateEvent) bool { return false }, | ||
| UpdateFunc: func(ue event.UpdateEvent) bool { return true }, | ||
| DeleteFunc: func(de event.DeleteEvent) bool { return true }, | ||
| GenericFunc: func(ge event.GenericEvent) bool { return true }, | ||
| }, | ||
| ), | ||
| ); err != nil { | ||
| return err | ||
| } | ||
| r.dynamicWatchGVKs[obj.GetObjectKind().GroupVersionKind()] = sets.Empty{} | ||
| } | ||
| return nil | ||
| }(); err != nil { | ||
| // Only attempt to watch resources if we are | ||
| // installing / upgrading. Otherwise we may restart | ||
| // watches that have already been established | ||
| if state != stateUnchanged { | ||
| if err := r.Watcher.Watch(ctx, r.controller, ext, relObjects); err != nil { | ||
| ext.Status.InstalledBundle = nil | ||
| setInstalledStatusConditionFailed(ext, fmt.Sprintf("%s:%v", ocv1alpha1.ReasonInstallationFailed, err)) | ||
| return ctrl.Result{}, err | ||
| } | ||
| } | ||
| ext.Status.InstalledBundle = bundleutil.MetadataFor(resolvedBundle.Name, *resolvedBundleVersion) | ||
| setInstalledStatusConditionSuccess(ext, fmt.Sprintf("Installed bundle %s successfully", resolvedBundle.Image)) | ||
| @@ -533,13 +508,11 @@ func (r *ClusterExtensionReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
| }, | ||
| })). | ||
| Build(r) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: whitespace-only change | ||
| if err != nil { | ||
| return err | ||
| } | ||
| r.controller = controller | ||
| r.cache = mgr.GetCache() | ||
| r.dynamicWatchGVKs = sets.New[schema.GroupVersionKind]() | ||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: change in whitespace