Skip to content

Commit c2a72b8

Browse files
committed
02-deprecate-service-account
1 parent 16996b9 commit c2a72b8

File tree

68 files changed

+245
-2707
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+245
-2707
lines changed

api/v1/clusterextension_types.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ type ClusterExtensionSpec struct {
6666
// +required
6767
Namespace string `json:"namespace"`
6868

69-
// serviceAccount specifies a ServiceAccount used to perform all interactions with the cluster
70-
// that are required to manage the extension.
71-
// The ServiceAccount must be configured with the necessary permissions to perform these interactions.
72-
// The ServiceAccount must exist in the namespace referenced in the spec.
73-
// The serviceAccount field is required.
69+
// serviceAccount was previously used to specify a ServiceAccount for managing the extension.
70+
// This field is now deprecated and ignored. operator-controller uses its own ServiceAccount
71+
// for all Kubernetes API interactions.
7472
//
75-
// +required
76-
ServiceAccount ServiceAccountReference `json:"serviceAccount"`
73+
// Deprecated: This field is ignored. It will be removed in a future API version.
74+
//
75+
// +optional
76+
ServiceAccount ServiceAccountReference `json:"serviceAccount,omitzero"`
7777

7878
// source is required and selects the installation source of content for this ClusterExtension.
7979
// Set the sourceType field to perform the selection.
@@ -376,7 +376,10 @@ type CatalogFilter struct {
376376
UpgradeConstraintPolicy UpgradeConstraintPolicy `json:"upgradeConstraintPolicy,omitempty"`
377377
}
378378

379-
// ServiceAccountReference identifies the serviceAccount used fo install a ClusterExtension.
379+
// ServiceAccountReference identifies the serviceAccount used to install a ClusterExtension.
380+
//
381+
// Deprecated: This type is deprecated and will be removed in a future API version.
382+
// operator-controller now uses its own ServiceAccount for all operations.
380383
type ServiceAccountReference struct {
381384
// name is a required, immutable reference to the name of the ServiceAccount used for installation
382385
// and management of the content for the package specified in the packageName field.

api/v1/validation_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ func TestValidate(t *testing.T) {
2323
}
2424
defaultExtensionSpec := func(s *ClusterExtensionSpec) *ClusterExtensionSpec {
2525
s.Namespace = "ns"
26-
s.ServiceAccount = ServiceAccountReference{
27-
Name: "sa",
28-
}
2926
s.Source = SourceConfig{
3027
SourceType: SourceTypeCatalog,
3128
Catalog: &CatalogFilter{

cmd/operator-controller/main.go

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"k8s.io/client-go/discovery/cached/memory"
4141
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
4242
_ "k8s.io/client-go/plugin/pkg/client/auth"
43+
"k8s.io/client-go/rest"
4344
"k8s.io/klog/v2"
4445
"k8s.io/utils/ptr"
4546
"pkg.package-operator.run/boxcutter/managedcache"
@@ -59,7 +60,6 @@ import (
5960
ocv1 "github.com/operator-framework/operator-controller/api/v1"
6061
"github.com/operator-framework/operator-controller/internal/operator-controller/action"
6162
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
62-
"github.com/operator-framework/operator-controller/internal/operator-controller/authentication"
6363
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
6464
"github.com/operator-framework/operator-controller/internal/operator-controller/catalogmetadata/cache"
6565
catalogclient "github.com/operator-framework/operator-controller/internal/operator-controller/catalogmetadata/client"
@@ -627,9 +627,6 @@ func (c *boxcutterReconcilerConfigurator) Configure(ceReconciler *controllers.Cl
627627
}
628628
ceReconciler.ReconcileSteps = []controllers.ReconcileStepFunc{
629629
controllers.HandleFinalizers(c.finalizers),
630-
controllers.ValidateClusterExtension(
631-
controllers.ServiceAccountValidator(coreClient),
632-
),
633630
controllers.MigrateStorage(storageMigrator),
634631
controllers.RetrieveRevisionStates(revisionStatesGetter),
635632
controllers.ResolveBundle(c.resolver, c.mgr.GetClient()),
@@ -659,29 +656,19 @@ func (c *boxcutterReconcilerConfigurator) Configure(ceReconciler *controllers.Cl
659656
return fmt.Errorf("unable to add tracking cache to manager: %v", err)
660657
}
661658

662-
cerCoreClient, err := corev1client.NewForConfig(c.mgr.GetConfig())
663-
if err != nil {
664-
return fmt.Errorf("unable to create client for ClusterExtensionRevision controller: %w", err)
665-
}
666-
cerTokenGetter := authentication.NewTokenGetter(cerCoreClient, authentication.WithExpirationDuration(1*time.Hour))
667-
668-
revisionEngineFactory, err := controllers.NewDefaultRevisionEngineFactory(
659+
revisionEngine := controllers.NewRevisionEngine(
669660
c.mgr.GetScheme(),
670661
trackingCache,
671662
discoveryClient,
672663
c.mgr.GetRESTMapper(),
673664
fieldOwnerPrefix,
674-
c.mgr.GetConfig(),
675-
cerTokenGetter,
665+
c.mgr.GetClient(),
676666
)
677-
if err != nil {
678-
return fmt.Errorf("unable to create revision engine factory: %w", err)
679-
}
680667

681668
if err = (&controllers.ClusterExtensionRevisionReconciler{
682-
Client: c.mgr.GetClient(),
683-
RevisionEngineFactory: revisionEngineFactory,
684-
TrackingCache: trackingCache,
669+
Client: c.mgr.GetClient(),
670+
RevisionEngine: revisionEngine,
671+
TrackingCache: trackingCache,
685672
}).SetupWithManager(c.mgr); err != nil {
686673
return fmt.Errorf("unable to setup ClusterExtensionRevision controller: %w", err)
687674
}
@@ -693,19 +680,13 @@ func (c *helmReconcilerConfigurator) Configure(ceReconciler *controllers.Cluster
693680
if err != nil {
694681
return fmt.Errorf("unable to create core client: %w", err)
695682
}
696-
tokenGetter := authentication.NewTokenGetter(coreClient, authentication.WithExpirationDuration(1*time.Hour))
697-
clientRestConfigMapper := action.ServiceAccountRestConfigMapper(tokenGetter)
698-
if features.OperatorControllerFeatureGate.Enabled(features.SyntheticPermissions) {
699-
clientRestConfigMapper = action.SyntheticUserRestConfigMapper(clientRestConfigMapper)
700-
}
701683

702684
cfgGetter, err := helmclient.NewActionConfigGetter(c.mgr.GetConfig(), c.mgr.GetRESTMapper(),
703685
helmclient.StorageDriverMapper(action.ChunkedStorageDriverMapper(coreClient, c.mgr.GetAPIReader(), cfg.systemNamespace)),
704686
helmclient.ClientNamespaceMapper(func(obj client.Object) (string, error) {
705687
ext := obj.(*ocv1.ClusterExtension)
706688
return ext.Spec.Namespace, nil
707689
}),
708-
helmclient.ClientRestConfigMapper(clientRestConfigMapper),
709690
)
710691
if err != nil {
711692
return fmt.Errorf("unable to create helm action config getter: %w", err)
@@ -724,7 +705,9 @@ func (c *helmReconcilerConfigurator) Configure(ceReconciler *controllers.Cluster
724705
preAuth = authorization.NewRBACPreAuthorizer(c.mgr.GetClient())
725706
}
726707

727-
cm := contentmanager.NewManager(clientRestConfigMapper, c.mgr.GetConfig(), c.mgr.GetRESTMapper())
708+
cm := contentmanager.NewManager(func(_ context.Context, _ client.Object, cfg *rest.Config) (*rest.Config, error) {
709+
return cfg, nil
710+
}, c.mgr.GetConfig(), c.mgr.GetRESTMapper())
728711
err = c.finalizers.Register(controllers.ClusterExtensionCleanupContentManagerCacheFinalizer, finalizers.FinalizerFunc(func(ctx context.Context, obj client.Object) (crfinalizer.Result, error) {
729712
ext := obj.(*ocv1.ClusterExtension)
730713
err := cm.Delete(ext)
@@ -750,9 +733,6 @@ func (c *helmReconcilerConfigurator) Configure(ceReconciler *controllers.Cluster
750733
revisionStatesGetter := &controllers.HelmRevisionStatesGetter{ActionClientGetter: acg}
751734
ceReconciler.ReconcileSteps = []controllers.ReconcileStepFunc{
752735
controllers.HandleFinalizers(c.finalizers),
753-
controllers.ValidateClusterExtension(
754-
controllers.ServiceAccountValidator(coreClient),
755-
),
756736
controllers.RetrieveRevisionStates(revisionStatesGetter),
757737
controllers.ResolveBundle(c.resolver, c.mgr.GetClient()),
758738
controllers.UnpackBundle(c.imagePuller, c.imageCache),

0 commit comments

Comments
 (0)