Skip to content

Commit

Permalink
Merge pull request #5595 from kaitoii11/docker-controller
Browse files Browse the repository at this point in the history
🌱  Move docker controller to internal
  • Loading branch information
k8s-ci-robot authored Nov 12, 2021
2 parents 4bb1961 + d20822c commit ef4f9bd
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/book/src/developer/providers/v1.0-to-v1.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ are kept in sync with the versions used by `sigs.k8s.io/controller-runtime`.
* Some controllers have been moved to internal to reduce there API surface. We now only
surface what is necessary, e.g. the reconciler and the `SetupWithManager` func:
* [bootstrap/kubeadm](https://github.com/kubernetes-sigs/cluster-api/pull/5493)
* [test/infrastructure/docker/controllers](https://github.com/kubernetes-sigs/cluster-api/pull/5595)

### Other

Expand Down
1 change: 1 addition & 0 deletions test/infrastructure/docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
paths=./$(EXP_DIR)/api/... \
paths=./$(EXP_DIR)/controllers/... \
paths=./controllers/... \
paths=./internal/... \
crd:crdVersions=v1 \
rbac:roleName=manager-role \
output:crd:dir=./config/crd/bases \
Expand Down
53 changes: 53 additions & 0 deletions test/infrastructure/docker/controllers/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2021 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"

dockercontrollers "sigs.k8s.io/cluster-api/test/infrastructure/docker/internal/controllers"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
)

// Following types provides access to reconcilers implemented in internal/controllers, thus
// allowing users to provide a single binary "batteries included" with Cluster API and providers of choice.

// DockerMachineReconciler reconciles a DockerMachine object.
type DockerMachineReconciler struct {
Client client.Client
}

// SetupWithManager sets up the reconciler with the Manager.
func (r *DockerMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
return (&dockercontrollers.DockerMachineReconciler{
Client: r.Client,
}).SetupWithManager(ctx, mgr, options)
}

// DockerClusterReconciler reconciles a DockerMachine object.
type DockerClusterReconciler struct {
Client client.Client
}

// SetupWithManager sets up the reconciler with the Manager.
func (r *DockerClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
return (&dockercontrollers.DockerClusterReconciler{
Client: r.Client,
}).SetupWithManager(ctx, mgr, options)
}
18 changes: 18 additions & 0 deletions test/infrastructure/docker/internal/controllers/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2021 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 Docker controllers.
package controllers
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package controllers
import (
"context"

"github.com/go-logr/logr"
"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand All @@ -41,7 +40,6 @@ import (
// DockerClusterReconciler reconciles a DockerCluster object.
type DockerClusterReconciler struct {
client.Client
Log logr.Logger
}

// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=dockerclusters,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -187,18 +185,18 @@ func (r *DockerClusterReconciler) reconcileDelete(ctx context.Context, dockerClu
}

// SetupWithManager will add watches for this controller.
func (r *DockerClusterReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
func (r *DockerClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
c, err := ctrl.NewControllerManagedBy(mgr).
For(&infrav1.DockerCluster{}).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPaused(r.Log)).
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
Build(r)
if err != nil {
return err
}
return c.Watch(
&source.Kind{Type: &clusterv1.Cluster{}},
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("DockerCluster"))),
predicates.ClusterUnpaused(r.Log),
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
)
}
3 changes: 1 addition & 2 deletions test/infrastructure/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {

if err := (&controllers.DockerClusterReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("DockerCluster"),
}).SetupWithManager(mgr, controller.Options{}); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "DockerCluster")
os.Exit(1)
}
Expand Down

0 comments on commit ef4f9bd

Please sign in to comment.