Skip to content

Commit ef4f9bd

Browse files
authored
Merge pull request #5595 from kaitoii11/docker-controller
🌱 Move docker controller to internal
2 parents 4bb1961 + d20822c commit ef4f9bd

File tree

9 files changed

+77
-7
lines changed

9 files changed

+77
-7
lines changed

docs/book/src/developer/providers/v1.0-to-v1.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ are kept in sync with the versions used by `sigs.k8s.io/controller-runtime`.
3030
* Some controllers have been moved to internal to reduce there API surface. We now only
3131
surface what is necessary, e.g. the reconciler and the `SetupWithManager` func:
3232
* [bootstrap/kubeadm](https://github.com/kubernetes-sigs/cluster-api/pull/5493)
33+
* [test/infrastructure/docker/controllers](https://github.com/kubernetes-sigs/cluster-api/pull/5595)
3334

3435
### Other
3536

test/infrastructure/docker/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
149149
paths=./$(EXP_DIR)/api/... \
150150
paths=./$(EXP_DIR)/controllers/... \
151151
paths=./controllers/... \
152+
paths=./internal/... \
152153
crd:crdVersions=v1 \
153154
rbac:roleName=manager-role \
154155
output:crd:dir=./config/crd/bases \
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controllers
18+
19+
import (
20+
"context"
21+
22+
dockercontrollers "sigs.k8s.io/cluster-api/test/infrastructure/docker/internal/controllers"
23+
ctrl "sigs.k8s.io/controller-runtime"
24+
"sigs.k8s.io/controller-runtime/pkg/client"
25+
"sigs.k8s.io/controller-runtime/pkg/controller"
26+
)
27+
28+
// Following types provides access to reconcilers implemented in internal/controllers, thus
29+
// allowing users to provide a single binary "batteries included" with Cluster API and providers of choice.
30+
31+
// DockerMachineReconciler reconciles a DockerMachine object.
32+
type DockerMachineReconciler struct {
33+
Client client.Client
34+
}
35+
36+
// SetupWithManager sets up the reconciler with the Manager.
37+
func (r *DockerMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
38+
return (&dockercontrollers.DockerMachineReconciler{
39+
Client: r.Client,
40+
}).SetupWithManager(ctx, mgr, options)
41+
}
42+
43+
// DockerClusterReconciler reconciles a DockerMachine object.
44+
type DockerClusterReconciler struct {
45+
Client client.Client
46+
}
47+
48+
// SetupWithManager sets up the reconciler with the Manager.
49+
func (r *DockerClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
50+
return (&dockercontrollers.DockerClusterReconciler{
51+
Client: r.Client,
52+
}).SetupWithManager(ctx, mgr, options)
53+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package controllers implements the Docker controllers.
18+
package controllers

test/infrastructure/docker/controllers/dockercluster_controller.go renamed to test/infrastructure/docker/internal/controllers/dockercluster_controller.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package controllers
2020
import (
2121
"context"
2222

23-
"github.com/go-logr/logr"
2423
"github.com/pkg/errors"
2524
apierrors "k8s.io/apimachinery/pkg/api/errors"
2625
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -41,7 +40,6 @@ import (
4140
// DockerClusterReconciler reconciles a DockerCluster object.
4241
type DockerClusterReconciler struct {
4342
client.Client
44-
Log logr.Logger
4543
}
4644

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

189187
// SetupWithManager will add watches for this controller.
190-
func (r *DockerClusterReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
188+
func (r *DockerClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
191189
c, err := ctrl.NewControllerManagedBy(mgr).
192190
For(&infrav1.DockerCluster{}).
193191
WithOptions(options).
194-
WithEventFilter(predicates.ResourceNotPaused(r.Log)).
192+
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))).
195193
Build(r)
196194
if err != nil {
197195
return err
198196
}
199197
return c.Watch(
200198
&source.Kind{Type: &clusterv1.Cluster{}},
201199
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("DockerCluster"))),
202-
predicates.ClusterUnpaused(r.Log),
200+
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
203201
)
204202
}

test/infrastructure/docker/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
163163

164164
if err := (&controllers.DockerClusterReconciler{
165165
Client: mgr.GetClient(),
166-
Log: ctrl.Log.WithName("controllers").WithName("DockerCluster"),
167-
}).SetupWithManager(mgr, controller.Options{}); err != nil {
166+
}).SetupWithManager(ctx, mgr, controller.Options{}); err != nil {
168167
setupLog.Error(err, "unable to create controller", "controller", "DockerCluster")
169168
os.Exit(1)
170169
}

0 commit comments

Comments
 (0)