Skip to content

Commit 10dc312

Browse files
thetechnickPer Goncalves da Silva
authored andcommitted
Connect Boxcutter Applier with ClusterExtension
1 parent 5f895e4 commit 10dc312

File tree

8 files changed

+187
-70
lines changed

8 files changed

+187
-70
lines changed

api/v1/clusterextensionrevision_types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ type ClusterExtensionRevisionSpec struct {
2929
// Specifies the lifecycle state of the ClusterExtensionRevision.
3030
// +kubebuilder:default="Active"
3131
// +kubebuilder:validation:Enum=Active;Paused;Archived
32-
// +kubebuilder:validation:XValidation:rule="oldSelf == "Active" || oldSelf == "Paused" || oldSelf == 'Archived' && oldSelf == self", message="can not un-archive"
32+
// +kubebuilder:validation:XValidation:rule="oldSelf == 'Active' || oldSelf == 'Paused' || oldSelf == 'Archived' && oldSelf == self", message="can not un-archive"
3333
LifecycleState ClusterExtensionRevisionLifecycleState `json:"lifecycleState,omitempty"`
3434
// +kubebuilder:validation:Required
3535
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="revision is immutable"
3636
Revision int64 `json:"revision"`
3737
// +kubebuilder:validation:Required
38-
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="phases is immutable"
38+
// +kubebuilder:validation:XValidation:rule="self == oldSelf || oldSelf.size() == 0", message="phases is immutable"
3939
Phases []ClusterExtensionRevisionPhase `json:"phases"`
4040
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="previous is immutable"
41-
Previous []ClusterExtensionRevisionPrevious `json:"previous"`
41+
Previous []ClusterExtensionRevisionPrevious `json:"previous,omitempty"`
4242
}
4343

4444
// ClusterExtensionRevisionLifecycleState specifies the lifecycle state of the ClusterExtensionRevision.
@@ -59,6 +59,7 @@ const (
5959
type ClusterExtensionRevisionPhase struct {
6060
Name string `json:"name"`
6161
Objects []ClusterExtensionRevisionObject `json:"objects"`
62+
Slices []string `json:"slices,omitempty"`
6263
}
6364

6465
type ClusterExtensionRevisionObject struct {

api/v1/zz_generated.deepcopy.go

Lines changed: 64 additions & 0 deletions
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: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/containers/image/v5/types"
3232
"github.com/spf13/cobra"
3333
rbacv1 "k8s.io/api/rbac/v1"
34-
apiextensionsv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
3534
"k8s.io/apimachinery/pkg/labels"
3635
k8slabels "k8s.io/apimachinery/pkg/labels"
3736
"k8s.io/apimachinery/pkg/selection"
@@ -60,19 +59,13 @@ import (
6059
"github.com/operator-framework/operator-controller/internal/operator-controller/action"
6160
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
6261
"github.com/operator-framework/operator-controller/internal/operator-controller/authentication"
63-
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
6462
"github.com/operator-framework/operator-controller/internal/operator-controller/catalogmetadata/cache"
6563
catalogclient "github.com/operator-framework/operator-controller/internal/operator-controller/catalogmetadata/client"
6664
"github.com/operator-framework/operator-controller/internal/operator-controller/contentmanager"
6765
"github.com/operator-framework/operator-controller/internal/operator-controller/controllers"
6866
"github.com/operator-framework/operator-controller/internal/operator-controller/features"
6967
"github.com/operator-framework/operator-controller/internal/operator-controller/finalizers"
7068
"github.com/operator-framework/operator-controller/internal/operator-controller/resolve"
71-
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
72-
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/preflights/crdupgradesafety"
73-
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
74-
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/certproviders"
75-
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1"
7669
"github.com/operator-framework/operator-controller/internal/operator-controller/scheme"
7770
sharedcontrollers "github.com/operator-framework/operator-controller/internal/shared/controllers"
7871
fsutil "github.com/operator-framework/operator-controller/internal/shared/util/fs"
@@ -417,45 +410,50 @@ func run() error {
417410
},
418411
}
419412

420-
aeClient, err := apiextensionsv1client.NewForConfig(mgr.GetConfig())
421-
if err != nil {
422-
setupLog.Error(err, "unable to create apiextensions client")
423-
return err
424-
}
413+
// aeClient, err := apiextensionsv1client.NewForConfig(mgr.GetConfig())
414+
// if err != nil {
415+
// setupLog.Error(err, "unable to create apiextensions client")
416+
// return err
417+
// }
425418

426-
preflights := []applier.Preflight{
427-
crdupgradesafety.NewPreflight(aeClient.CustomResourceDefinitions()),
428-
}
419+
// preflights := []applier.Preflight{
420+
// crdupgradesafety.NewPreflight(aeClient.CustomResourceDefinitions()),
421+
// }
429422

430-
// determine if PreAuthorizer should be enabled based on feature gate
431-
var preAuth authorization.PreAuthorizer
432-
if features.OperatorControllerFeatureGate.Enabled(features.PreflightPermissions) {
433-
preAuth = authorization.NewRBACPreAuthorizer(mgr.GetClient())
423+
// // determine if PreAuthorizer should be enabled based on feature gate
424+
// var preAuth authorization.PreAuthorizer
425+
// if features.OperatorControllerFeatureGate.Enabled(features.PreflightPermissions) {
426+
// preAuth = authorization.NewRBACPreAuthorizer(mgr.GetClient())
427+
// }
428+
429+
boxcutterApplier := &applier.Boxcutter{
430+
Client: mgr.GetClient(),
431+
Scheme: mgr.GetScheme(),
434432
}
435433

436434
// determine if a certificate provider should be set in the bundle renderer and feature support for the provider
437435
// based on the feature flag
438-
var certProvider render.CertificateProvider
439-
var isWebhookSupportEnabled bool
440-
if features.OperatorControllerFeatureGate.Enabled(features.WebhookProviderCertManager) {
441-
certProvider = certproviders.CertManagerCertificateProvider{}
442-
isWebhookSupportEnabled = true
443-
} else if features.OperatorControllerFeatureGate.Enabled(features.WebhookProviderOpenshiftServiceCA) {
444-
certProvider = certproviders.OpenshiftServiceCaCertificateProvider{}
445-
isWebhookSupportEnabled = true
446-
}
436+
// var certProvider render.CertificateProvider
437+
// var isWebhookSupportEnabled bool
438+
// if features.OperatorControllerFeatureGate.Enabled(features.WebhookProviderCertManager) {
439+
// certProvider = certproviders.CertManagerCertificateProvider{}
440+
// isWebhookSupportEnabled = true
441+
// } else if features.OperatorControllerFeatureGate.Enabled(features.WebhookProviderOpenshiftServiceCA) {
442+
// certProvider = certproviders.OpenshiftServiceCaCertificateProvider{}
443+
// isWebhookSupportEnabled = true
444+
// }
447445

448446
// now initialize the helmApplier, assigning the potentially nil preAuth
449-
helmApplier := &applier.Helm{
450-
ActionClientGetter: acg,
451-
Preflights: preflights,
452-
BundleToHelmChartConverter: &convert.BundleToHelmChartConverter{
453-
BundleRenderer: registryv1.Renderer,
454-
CertificateProvider: certProvider,
455-
IsWebhookSupportEnabled: isWebhookSupportEnabled,
456-
},
457-
PreAuthorizer: preAuth,
458-
}
447+
// helmApplier := &applier.Helm{
448+
// ActionClientGetter: acg,
449+
// Preflights: preflights,
450+
// BundleToHelmChartConverter: &convert.BundleToHelmChartConverter{
451+
// BundleRenderer: registryv1.Renderer,
452+
// CertificateProvider: certProvider,
453+
// IsWebhookSupportEnabled: isWebhookSupportEnabled,
454+
// },
455+
// PreAuthorizer: preAuth,
456+
// }
459457

460458
cm := contentmanager.NewManager(clientRestConfigMapper, mgr.GetConfig(), mgr.GetRESTMapper())
461459
err = clusterExtensionFinalizers.Register(controllers.ClusterExtensionCleanupContentManagerCacheFinalizer, finalizers.FinalizerFunc(func(ctx context.Context, obj client.Object) (crfinalizer.Result, error) {
@@ -475,7 +473,18 @@ func run() error {
475473
return err
476474
}
477475
mapFunc := func(ctx context.Context, ce *ocv1.ClusterExtension, c *rest.Config, o crcache.Options) (*rest.Config, crcache.Options, error) {
478-
// TODO: Rest Config Mapping / change ServiceAccount
476+
saKey := client.ObjectKey{
477+
Name: ce.Spec.ServiceAccount.Name,
478+
Namespace: ce.Spec.Namespace,
479+
}
480+
saConfig := rest.AnonymousClientConfig(c)
481+
saConfig.Wrap(func(rt http.RoundTripper) http.RoundTripper {
482+
return &authentication.TokenInjectingRoundTripper{
483+
Tripper: rt,
484+
TokenGetter: tokenGetter,
485+
Key: saKey,
486+
}
487+
})
479488

480489
// Cache scoping
481490
req1, err := labels.NewRequirement(
@@ -485,20 +494,25 @@ func run() error {
485494
}
486495
o.DefaultLabelSelector = labels.NewSelector().Add(*req1)
487496

488-
return c, o, nil
497+
return saConfig, o, nil
489498
}
490-
accessManager := managedcache.NewObjectBoundAccessManager[*ocv1.ClusterExtension](
499+
500+
accessManager := managedcache.NewObjectBoundAccessManager(
491501
ctrl.Log.WithName("accessmanager"), mapFunc, restConfig, crcache.Options{
492502
Scheme: mgr.GetScheme(), Mapper: mgr.GetRESTMapper(),
493503
})
504+
if err := mgr.Add(accessManager); err != nil {
505+
setupLog.Error(err, "unable to register AccessManager")
506+
return err
507+
}
494508
// Boxcutter
495509

496510
if err = (&controllers.ClusterExtensionReconciler{
497511
Client: cl,
498512
Resolver: resolver,
499513
ImageCache: imageCache,
500514
ImagePuller: imagePuller,
501-
Applier: helmApplier,
515+
Applier: boxcutterApplier,
502516
InstalledBundleGetter: &controllers.DefaultInstalledBundleGetter{ActionClientGetter: acg},
503517
Finalizers: clusterExtensionFinalizers,
504518
Manager: cm,

config/base/operator-controller/rbac/role.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ rules:
2727
- apiGroups:
2828
- olm.operatorframework.io
2929
resources:
30-
- clusterextensions
30+
- clusterextensionrevisions
3131
verbs:
32+
- create
33+
- delete
3234
- get
3335
- list
3436
- patch
@@ -37,16 +39,28 @@ rules:
3739
- apiGroups:
3840
- olm.operatorframework.io
3941
resources:
42+
- clusterextensionrevisions/finalizers
4043
- clusterextensions/finalizers
4144
verbs:
4245
- update
4346
- apiGroups:
4447
- olm.operatorframework.io
4548
resources:
49+
- clusterextensionrevisions/status
4650
- clusterextensions/status
4751
verbs:
4852
- patch
4953
- update
54+
- apiGroups:
55+
- olm.operatorframework.io
56+
resources:
57+
- clusterextensions
58+
verbs:
59+
- get
60+
- list
61+
- patch
62+
- update
63+
- watch
5064
- apiGroups:
5165
- rbac.authorization.k8s.io
5266
resources:

internal/operator-controller/applier/boxcutter.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
"github.com/davecgh/go-spew/spew"
1414
ocv1 "github.com/operator-framework/operator-controller/api/v1"
1515
"github.com/operator-framework/operator-controller/internal/operator-controller/controllers"
16-
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
16+
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
17+
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
1718
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1819
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1920
"k8s.io/apimachinery/pkg/runtime"
@@ -28,8 +29,9 @@ const (
2829
)
2930

3031
type Boxcutter struct {
31-
Client client.Client
32-
Scheme *runtime.Scheme
32+
Client client.Client
33+
Scheme *runtime.Scheme
34+
BundleRenderer render.BundleRenderer
3335
}
3436

3537
func (bc *Boxcutter) Apply(
@@ -46,7 +48,7 @@ func (bc *Boxcutter) apply(
4648
ext *ocv1.ClusterExtension,
4749
objectLabels, _ map[string]string,
4850
) ([]client.Object, error) {
49-
reg, err := convert.ParseFS(contentFS)
51+
reg, err := source.FromFS(contentFS).GetBundle()
5052
if err != nil {
5153
return nil, err
5254
}
@@ -56,14 +58,14 @@ func (bc *Boxcutter) apply(
5658
return nil, err
5759
}
5860

59-
plain, err := convert.PlainConverter.Convert(reg, ext.Spec.Namespace, []string{watchNamespace})
61+
plain, err := bc.BundleRenderer.Render(reg, ext.Spec.Namespace, render.WithTargetNamespaces(watchNamespace))
6062
if err != nil {
6163
return nil, err
6264
}
6365

6466
// objectLabels
65-
objs := make([]ocv1.ClusterExtensionRevisionObject, 0, len(plain.Objects))
66-
for _, obj := range plain.Objects {
67+
objs := make([]ocv1.ClusterExtensionRevisionObject, 0, len(plain))
68+
for _, obj := range plain {
6769
labels := obj.GetLabels()
6870
if labels == nil {
6971
labels = map[string]string{}
@@ -103,6 +105,7 @@ func (bc *Boxcutter) apply(
103105
// Build desired revision
104106
desiredRevision := &ocv1.ClusterExtensionRevision{
105107
ObjectMeta: metav1.ObjectMeta{
108+
Annotations: map[string]string{},
106109
Labels: map[string]string{
107110
controllers.ClusterExtensionRevisionOwnerLabel: ext.Name,
108111
},
@@ -144,8 +147,9 @@ func (bc *Boxcutter) apply(
144147
revisionNumber++
145148

146149
newRevision := desiredRevision
150+
newRevision.Name = fmt.Sprintf("%s-%d", ext.Name, revisionNumber)
151+
newRevision.Annotations[revisionHashAnnotation] = desiredHash
147152
newRevision.Spec.Revision = revisionNumber
148-
// newRevision.Spec.Previous
149153
for _, prevRevision := range prevRevisions {
150154
newRevision.Spec.Previous = append(newRevision.Spec.Previous, ocv1.ClusterExtensionRevisionPrevious{
151155
Name: prevRevision.Name,
@@ -178,7 +182,7 @@ func (bc *Boxcutter) apply(
178182

179183
// TODO: Read status from revision.
180184

181-
return plain.Objects, nil
185+
return plain, nil
182186
}
183187

184188
// computeSHA256Hash returns a sha236 hash value calculated from object.

internal/operator-controller/controllers/clusterextension_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ func (r *ClusterExtensionReconciler) SetupWithManager(mgr ctrl.Manager) error {
418418
controller, err := ctrl.NewControllerManagedBy(mgr).
419419
For(&ocv1.ClusterExtension{}).
420420
Named("controller-operator-cluster-extension-controller").
421+
Owns(&ocv1.ClusterExtensionRevision{}).
421422
Watches(&ocv1.ClusterCatalog{},
422423
crhandler.EnqueueRequestsFromMapFunc(clusterExtensionRequestsForCatalog(mgr.GetClient(), mgr.GetLogger())),
423424
builder.WithPredicates(predicate.Funcs{

0 commit comments

Comments
 (0)