Skip to content

Commit f682e53

Browse files
committed
Ensure ExtensionConfig controller can be used outside of the core provider
1 parent 9c2eb0a commit f682e53

File tree

8 files changed

+517
-135
lines changed

8 files changed

+517
-135
lines changed

controllers/alias.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,23 @@ func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
303303

304304
// ExtensionConfigReconciler reconciles an ExtensionConfig object.
305305
type ExtensionConfigReconciler struct {
306-
Client client.Client
307-
APIReader client.Reader
308-
RuntimeClient runtimeclient.Client
306+
Client client.Client
307+
APIReader client.Reader
308+
RuntimeClient runtimeclient.Client
309+
PartialSecretCache cache.Cache
310+
ReadOnly bool
309311

310312
// WatchFilterValue is the label value used to filter events prior to reconciliation.
311313
WatchFilterValue string
312314
}
313315

314-
func (r *ExtensionConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options, partialSecretCache cache.Cache) error {
316+
func (r *ExtensionConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
315317
return (&extensionconfigcontroller.Reconciler{
316-
Client: r.Client,
317-
APIReader: r.APIReader,
318-
RuntimeClient: r.RuntimeClient,
319-
WatchFilterValue: r.WatchFilterValue,
320-
}).SetupWithManager(ctx, mgr, options, partialSecretCache)
318+
Client: r.Client,
319+
APIReader: r.APIReader,
320+
RuntimeClient: r.RuntimeClient,
321+
PartialSecretCache: r.PartialSecretCache,
322+
ReadOnly: r.ReadOnly,
323+
WatchFilterValue: r.WatchFilterValue,
324+
}).SetupWithManager(ctx, mgr, options)
321325
}

controlplane/kubeadm/config/rbac/role.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ rules:
1111
verbs:
1212
- create
1313
- patch
14+
- apiGroups:
15+
- ""
16+
resources:
17+
- namespaces
18+
verbs:
19+
- get
20+
- list
21+
- watch
1422
- apiGroups:
1523
- ""
1624
resources:
@@ -90,3 +98,11 @@ rules:
9098
- patch
9199
- update
92100
- watch
101+
- apiGroups:
102+
- runtime.cluster.x-k8s.io
103+
resources:
104+
- extensionconfigs
105+
verbs:
106+
- get
107+
- list
108+
- watch

controlplane/kubeadm/main.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,30 @@ import (
5656
controlplanev1beta1 "sigs.k8s.io/cluster-api/api/controlplane/kubeadm/v1beta1"
5757
controlplanev1 "sigs.k8s.io/cluster-api/api/controlplane/kubeadm/v1beta2"
5858
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
59+
runtimehooksv1 "sigs.k8s.io/cluster-api/api/runtime/hooks/v1alpha1"
60+
runtimev1 "sigs.k8s.io/cluster-api/api/runtime/v1beta2"
61+
"sigs.k8s.io/cluster-api/controllers"
5962
"sigs.k8s.io/cluster-api/controllers/clustercache"
6063
"sigs.k8s.io/cluster-api/controllers/crdmigrator"
6164
"sigs.k8s.io/cluster-api/controllers/remote"
6265
kubeadmcontrolplanecontrollers "sigs.k8s.io/cluster-api/controlplane/kubeadm/controllers"
6366
"sigs.k8s.io/cluster-api/controlplane/kubeadm/internal/etcd"
6467
kcpwebhooks "sigs.k8s.io/cluster-api/controlplane/kubeadm/webhooks"
68+
runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog"
69+
runtimeclient "sigs.k8s.io/cluster-api/exp/runtime/client"
6570
"sigs.k8s.io/cluster-api/feature"
6671
controlplanev1alpha3 "sigs.k8s.io/cluster-api/internal/api/controlplane/kubeadm/v1alpha3"
6772
controlplanev1alpha4 "sigs.k8s.io/cluster-api/internal/api/controlplane/kubeadm/v1alpha4"
6873
"sigs.k8s.io/cluster-api/internal/contract"
74+
internalruntimeclient "sigs.k8s.io/cluster-api/internal/runtime/client"
75+
runtimeregistry "sigs.k8s.io/cluster-api/internal/runtime/registry"
6976
"sigs.k8s.io/cluster-api/util/apiwarnings"
7077
"sigs.k8s.io/cluster-api/util/flags"
7178
"sigs.k8s.io/cluster-api/version"
7279
)
7380

7481
var (
82+
catalog = runtimecatalog.New()
7583
scheme = runtime.NewScheme()
7684
setupLog = ctrl.Log.WithName("setup")
7785
controllerName = "cluster-api-kubeadm-control-plane-manager"
@@ -94,6 +102,8 @@ var (
94102
webhookCertDir string
95103
webhookCertName string
96104
webhookKeyName string
105+
runtimeExtensionCertFile string
106+
runtimeExtensionKeyFile string
97107
healthAddr string
98108
managerOptions = flags.ManagerOptions{}
99109
logOptions = logs.NewOptions()
@@ -116,6 +126,10 @@ func init() {
116126
_ = controlplanev1.AddToScheme(scheme)
117127
_ = bootstrapv1.AddToScheme(scheme)
118128
_ = apiextensionsv1.AddToScheme(scheme)
129+
_ = runtimev1.AddToScheme(scheme)
130+
131+
// Register the RuntimeHook types into the catalog.
132+
_ = runtimehooksv1.AddToCatalog(catalog)
119133
}
120134

121135
// InitFlags initializes the flags.
@@ -186,6 +200,12 @@ func InitFlags(fs *pflag.FlagSet) {
186200
fs.StringVar(&webhookKeyName, "webhook-key-name", "tls.key",
187201
"Webhook key name.")
188202

203+
fs.StringVar(&runtimeExtensionCertFile, "runtime-extension-client-cert-file", "",
204+
"Path of the PEM-encoded client certificate to be used when calling runtime extensions.")
205+
206+
fs.StringVar(&runtimeExtensionKeyFile, "runtime-extension-client-key-file", "",
207+
"Path of the PEM-encoded client key to be used when calling runtime extensions.")
208+
189209
fs.StringVar(&healthAddr, "health-addr", ":9440",
190210
"The address the health endpoint binds to.")
191211

@@ -209,6 +229,9 @@ func InitFlags(fs *pflag.FlagSet) {
209229
// ADD CRD RBAC for CRD Migrator.
210230
// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get;list;watch
211231
// +kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions;customresourcedefinitions/status,verbs=update;patch,resourceNames=kubeadmcontrolplanes.controlplane.cluster.x-k8s.io;kubeadmcontrolplanetemplates.controlplane.cluster.x-k8s.io
232+
// Add RBAC for ExtensionConfig controller and runtime client (intentionally does not include write permissions)
233+
// +kubebuilder:rbac:groups=runtime.cluster.x-k8s.io,resources=extensionconfigs,verbs=get;list;watch
234+
// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch
212235

213236
func main() {
214237
InitFlags(pflag.CommandLine)
@@ -437,6 +460,30 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
437460
setupLog.Error(err, "unable to create etcd logger")
438461
os.Exit(1)
439462
}
463+
464+
var runtimeClient runtimeclient.Client
465+
if feature.Gates.Enabled(feature.InPlaceUpdates) {
466+
// This is the creation of the runtimeClient for the controllers, embedding a shared catalog and registry instance.
467+
runtimeClient = internalruntimeclient.New(internalruntimeclient.Options{
468+
CertFile: runtimeExtensionCertFile,
469+
KeyFile: runtimeExtensionKeyFile,
470+
Catalog: catalog,
471+
Registry: runtimeregistry.New(),
472+
Client: mgr.GetClient(),
473+
})
474+
475+
if err = (&controllers.ExtensionConfigReconciler{
476+
Client: mgr.GetClient(),
477+
APIReader: mgr.GetAPIReader(),
478+
RuntimeClient: runtimeClient,
479+
ReadOnly: true,
480+
WatchFilterValue: watchFilterValue,
481+
}).SetupWithManager(ctx, mgr, concurrency(10)); err != nil {
482+
setupLog.Error(err, "Unable to create controller", "controller", "ExtensionConfig")
483+
os.Exit(1)
484+
}
485+
}
486+
440487
if err := (&kubeadmcontrolplanecontrollers.KubeadmControlPlaneReconciler{
441488
Client: mgr.GetClient(),
442489
SecretCachingClient: secretCachingClient,
@@ -446,6 +493,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
446493
EtcdCallTimeout: etcdCallTimeout,
447494
EtcdLogger: etcdLogger,
448495
RemoteConditionsGracePeriod: remoteConditionsGracePeriod,
496+
//RuntimeClient: runtimeClient, // TODO(in-place): enable once we want to use it, also validate in SetupWithManager that RuntimeClient is set if feature gate is enabled.
449497
}).SetupWithManager(ctx, mgr, concurrency(kubeadmControlPlaneConcurrency)); err != nil {
450498
setupLog.Error(err, "unable to create controller", "controller", "KubeadmControlPlane")
451499
os.Exit(1)

0 commit comments

Comments
 (0)