Skip to content

Commit 3d642e6

Browse files
committed
02-deprecate-service-account
1 parent aa6e4e7 commit 3d642e6

File tree

70 files changed

+257
-2591
lines changed

Some content is hidden

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

70 files changed

+257
-2591
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{

applyconfigurations/api/v1/clusterextensionspec.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

applyconfigurations/api/v1/serviceaccountreference.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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"
@@ -630,9 +630,6 @@ func (c *boxcutterReconcilerConfigurator) Configure(ceReconciler *controllers.Cl
630630
}
631631
ceReconciler.ReconcileSteps = []controllers.ReconcileStepFunc{
632632
controllers.HandleFinalizers(c.finalizers),
633-
controllers.ValidateClusterExtension(
634-
controllers.ServiceAccountValidator(coreClient),
635-
),
636633
controllers.MigrateStorage(storageMigrator),
637634
controllers.RetrieveRevisionStates(revisionStatesGetter),
638635
controllers.ResolveBundle(c.resolver, c.mgr.GetClient()),
@@ -662,29 +659,19 @@ func (c *boxcutterReconcilerConfigurator) Configure(ceReconciler *controllers.Cl
662659
return fmt.Errorf("unable to add tracking cache to manager: %v", err)
663660
}
664661

665-
cerCoreClient, err := corev1client.NewForConfig(c.mgr.GetConfig())
666-
if err != nil {
667-
return fmt.Errorf("unable to create client for ClusterExtensionRevision controller: %w", err)
668-
}
669-
cerTokenGetter := authentication.NewTokenGetter(cerCoreClient, authentication.WithExpirationDuration(1*time.Hour))
670-
671-
revisionEngineFactory, err := controllers.NewDefaultRevisionEngineFactory(
662+
revisionEngine := controllers.NewRevisionEngine(
672663
c.mgr.GetScheme(),
673664
trackingCache,
674665
discoveryClient,
675666
c.mgr.GetRESTMapper(),
676667
fieldOwnerPrefix,
677-
c.mgr.GetConfig(),
678-
cerTokenGetter,
668+
c.mgr.GetClient(),
679669
)
680-
if err != nil {
681-
return fmt.Errorf("unable to create revision engine factory: %w", err)
682-
}
683670

684671
if err = (&controllers.ClusterExtensionRevisionReconciler{
685-
Client: c.mgr.GetClient(),
686-
RevisionEngineFactory: revisionEngineFactory,
687-
TrackingCache: trackingCache,
672+
Client: c.mgr.GetClient(),
673+
RevisionEngine: revisionEngine,
674+
TrackingCache: trackingCache,
688675
}).SetupWithManager(c.mgr); err != nil {
689676
return fmt.Errorf("unable to setup ClusterExtensionRevision controller: %w", err)
690677
}
@@ -696,19 +683,13 @@ func (c *helmReconcilerConfigurator) Configure(ceReconciler *controllers.Cluster
696683
if err != nil {
697684
return fmt.Errorf("unable to create core client: %w", err)
698685
}
699-
tokenGetter := authentication.NewTokenGetter(coreClient, authentication.WithExpirationDuration(1*time.Hour))
700-
clientRestConfigMapper := action.ServiceAccountRestConfigMapper(tokenGetter)
701-
if features.OperatorControllerFeatureGate.Enabled(features.SyntheticPermissions) {
702-
clientRestConfigMapper = action.SyntheticUserRestConfigMapper(clientRestConfigMapper)
703-
}
704686

705687
cfgGetter, err := helmclient.NewActionConfigGetter(c.mgr.GetConfig(), c.mgr.GetRESTMapper(),
706688
helmclient.StorageDriverMapper(action.ChunkedStorageDriverMapper(coreClient, c.mgr.GetAPIReader(), cfg.systemNamespace)),
707689
helmclient.ClientNamespaceMapper(func(obj client.Object) (string, error) {
708690
ext := obj.(*ocv1.ClusterExtension)
709691
return ext.Spec.Namespace, nil
710692
}),
711-
helmclient.ClientRestConfigMapper(clientRestConfigMapper),
712693
)
713694
if err != nil {
714695
return fmt.Errorf("unable to create helm action config getter: %w", err)
@@ -727,7 +708,9 @@ func (c *helmReconcilerConfigurator) Configure(ceReconciler *controllers.Cluster
727708
preAuth = authorization.NewRBACPreAuthorizer(c.mgr.GetClient())
728709
}
729710

730-
cm := contentmanager.NewManager(clientRestConfigMapper, c.mgr.GetConfig(), c.mgr.GetRESTMapper())
711+
cm := contentmanager.NewManager(func(_ context.Context, _ client.Object, cfg *rest.Config) (*rest.Config, error) {
712+
return cfg, nil
713+
}, c.mgr.GetConfig(), c.mgr.GetRESTMapper())
731714
err = c.finalizers.Register(controllers.ClusterExtensionCleanupContentManagerCacheFinalizer, finalizers.FinalizerFunc(func(ctx context.Context, obj client.Object) (crfinalizer.Result, error) {
732715
ext := obj.(*ocv1.ClusterExtension)
733716
err := cm.Delete(ext)
@@ -753,9 +736,6 @@ func (c *helmReconcilerConfigurator) Configure(ceReconciler *controllers.Cluster
753736
revisionStatesGetter := &controllers.HelmRevisionStatesGetter{ActionClientGetter: acg}
754737
ceReconciler.ReconcileSteps = []controllers.ReconcileStepFunc{
755738
controllers.HandleFinalizers(c.finalizers),
756-
controllers.ValidateClusterExtension(
757-
controllers.ServiceAccountValidator(coreClient),
758-
),
759739
controllers.RetrieveRevisionStates(revisionStatesGetter),
760740
controllers.ResolveBundle(c.resolver, c.mgr.GetClient()),
761741
controllers.UnpackBundle(c.imagePuller, c.imageCache),

0 commit comments

Comments
 (0)