Skip to content

Commit

Permalink
Merge pull request #6411 from killianmuldoon/runtimeSDK/add-extension…
Browse files Browse the repository at this point in the history
…ConfigController

✨ RuntimeSDK: Add extension config controller skeleton
  • Loading branch information
k8s-ci-robot committed Apr 29, 2022
2 parents a070fce + e899618 commit 2982a32
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ generate-manifests-core: $(CONTROLLER_GEN) $(KUSTOMIZE) ## Generate manifests e.
paths=./$(EXP_DIR)/addons/api/... \
paths=./$(EXP_DIR)/addons/internal/controllers/... \
paths=./$(EXP_DIR)/runtime/api/... \
paths=./$(EXP_DIR)/runtime/internal/controllers/... \
crd:crdVersions=v1 \
rbac:roleName=manager-role \
output:crd:dir=./config/crd/bases \
Expand Down
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,15 @@ rules:
- list
- patch
- watch
- apiGroups:
- runtime.cluster.x-k8s.io
resources:
- extensionconfigs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
44 changes: 44 additions & 0 deletions exp/runtime/controllers/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers

import (
"context"

ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

extensionconfigs "sigs.k8s.io/cluster-api/exp/runtime/internal/controllers"
)

// ExtensionConfigReconciler reconciles an ExtensionConfig object.
type ExtensionConfigReconciler struct {
Client client.Client
APIReader client.Reader

// WatchFilterValue is the label value used to filter events prior to reconciliation.
WatchFilterValue string
}

func (r *ExtensionConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
return (&extensionconfigs.Reconciler{
Client: r.Client,
APIReader: r.APIReader,
WatchFilterValue: r.WatchFilterValue,
}).SetupWithManager(ctx, mgr, options)
}
18 changes: 18 additions & 0 deletions exp/runtime/controllers/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package controllers implements the exp/runtime controllers.
package controllers
18 changes: 18 additions & 0 deletions exp/runtime/internal/controllers/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package controllers implements the exp/runtime controllers.
package controllers
65 changes: 65 additions & 0 deletions exp/runtime/internal/controllers/extensionconfig_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers

import (
"context"

"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1"
"sigs.k8s.io/cluster-api/util/predicates"
)

// +kubebuilder:rbac:groups=runtime.cluster.x-k8s.io,resources=extensionconfigs,verbs=get;list;watch;create;update;patch;delete

// Reconciler reconciles an Extension object.
type Reconciler struct {
Client client.Client
APIReader client.Reader
// WatchFilterValue is the label value used to filter events prior to reconciliation.
WatchFilterValue string
}

func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
err := ctrl.NewControllerManagedBy(mgr).
For(&runtimev1.ExtensionConfig{}).
WithOptions(options).
WithEventFilter(predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
Complete(r)
if err != nil {
return errors.Wrap(err, "failed setting up with a controller manager")
}
return nil
}

func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
extension := &runtimev1.ExtensionConfig{}
err := r.Client.Get(ctx, req.NamespacedName, extension)
if err != nil {
if apierrors.IsNotFound(err) {
return ctrl.Result{}, nil
}
// Error reading the object - requeue the request.
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import (
expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
expcontrollers "sigs.k8s.io/cluster-api/exp/controllers"
runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1"
runtimev1controllers "sigs.k8s.io/cluster-api/exp/runtime/controllers"
"sigs.k8s.io/cluster-api/feature"
runtimev1webhooks "sigs.k8s.io/cluster-api/internal/webhooks/runtime"
"sigs.k8s.io/cluster-api/version"
Expand All @@ -78,6 +79,7 @@ var (
clusterTopologyConcurrency int
clusterClassConcurrency int
clusterConcurrency int
extensionConfigConcurrency int
machineConcurrency int
machineSetConcurrency int
machineDeploymentConcurrency int
Expand Down Expand Up @@ -150,6 +152,9 @@ func InitFlags(fs *pflag.FlagSet) {
fs.IntVar(&clusterConcurrency, "cluster-concurrency", 10,
"Number of clusters to process simultaneously")

fs.IntVar(&extensionConfigConcurrency, "extensionconfig-concurrency", 10,
"Number of extension configs to process simultaneously")

fs.IntVar(&machineConcurrency, "machine-concurrency", 10,
"Number of machines to process simultaneously")

Expand Down Expand Up @@ -348,6 +353,18 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
os.Exit(1)
}
}

if feature.Gates.Enabled(feature.RuntimeSDK) {
if err = (&runtimev1controllers.ExtensionConfigReconciler{
Client: mgr.GetClient(),
APIReader: mgr.GetAPIReader(),
WatchFilterValue: watchFilterValue,
}).SetupWithManager(ctx, mgr, concurrency(extensionConfigConcurrency)); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ExtensionConfig")
os.Exit(1)
}
}

if err := (&controllers.ClusterReconciler{
Client: mgr.GetClient(),
APIReader: mgr.GetAPIReader(),
Expand Down

0 comments on commit 2982a32

Please sign in to comment.