Skip to content

Commit c9fc9b0

Browse files
authored
add predicates.ResourceIsNotExternallyManaged to cluster controller (#324)
* update cluster-api and use api/v1alpha4 * add predicates.ResourceIsNotExternallyManaged to cluster controller * new controller-runtime requires go 1.16 https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_cluster-api-provider-ibmcloud/324/pull-cluster-api-provider-ibmcloud-make/1402101602310950912#1:build-log.txt%3A471 Also this is what the other providers are using.
1 parent 0e80af9 commit c9fc9b0

File tree

10 files changed

+571
-178
lines changed

10 files changed

+571
-178
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.13 as builder
2+
FROM golang:1.16 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

api/v1alpha3/ibmvpccluster_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package v1alpha3
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21-
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
2222
)
2323

2424
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!

cloud/scope/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
infrav1 "github.com/kubernetes-sigs/cluster-api-provider-ibmcloud/api/v1alpha3"
1010
"github.com/pkg/errors"
1111
"k8s.io/klog/v2/klogr"
12-
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
12+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
1313
"sigs.k8s.io/cluster-api/util/patch"
1414
"sigs.k8s.io/controller-runtime/pkg/client"
1515
)

cloud/scope/machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
corev1 "k8s.io/api/core/v1"
1212
"k8s.io/apimachinery/pkg/types"
1313
"k8s.io/klog/v2/klogr"
14-
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
14+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
1515
"sigs.k8s.io/cluster-api/util/patch"
1616
"sigs.k8s.io/controller-runtime/pkg/client"
1717
)

controllers/ibmvpccluster_controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import (
2727
"github.com/pkg/errors"
2828
apierrors "k8s.io/apimachinery/pkg/api/errors"
2929
"k8s.io/apimachinery/pkg/runtime"
30-
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
30+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
3131
"sigs.k8s.io/cluster-api/util"
32+
"sigs.k8s.io/cluster-api/util/predicates"
3233
ctrl "sigs.k8s.io/controller-runtime"
3334
"sigs.k8s.io/controller-runtime/pkg/client"
3435
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -46,8 +47,7 @@ type IBMVPCClusterReconciler struct {
4647
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=ibmvpcclusters/status,verbs=get;update;patch
4748
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters;clusters/status,verbs=get;list;watch
4849

49-
func (r *IBMVPCClusterReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr error) {
50-
ctx := context.Background()
50+
func (r *IBMVPCClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
5151
log := r.Log.WithValues("ibmvpccluster", req.NamespacedName)
5252

5353
// your logic here
@@ -191,5 +191,6 @@ func (r *IBMVPCClusterReconciler) reconcileDelete(clusterScope *scope.ClusterSco
191191
func (r *IBMVPCClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
192192
return ctrl.NewControllerManagedBy(mgr).
193193
For(&infrastructurev1alpha3.IBMVPCCluster{}).
194+
WithEventFilter(predicates.ResourceIsNotExternallyManaged(ctrl.LoggerFrom(context.TODO()))).
194195
Complete(r)
195196
}

controllers/ibmvpcmachine_controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
apierrors "k8s.io/apimachinery/pkg/api/errors"
3232
"k8s.io/apimachinery/pkg/runtime"
3333
"k8s.io/utils/pointer"
34-
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
34+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
3535
"sigs.k8s.io/cluster-api/util"
3636
ctrl "sigs.k8s.io/controller-runtime"
3737
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -48,8 +48,7 @@ type IBMVPCMachineReconciler struct {
4848
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=ibmvpcmachines,verbs=get;list;watch;create;update;patch;delete
4949
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=ibmvpcmachines/status,verbs=get;update;patch
5050

51-
func (r *IBMVPCMachineReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr error) {
52-
ctx := context.Background()
51+
func (r *IBMVPCMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
5352
log := r.Log.WithValues("ibmvpcmachine", req.NamespacedName)
5453

5554
// your logic here

controllers/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
. "github.com/onsi/gomega"
2626
"k8s.io/client-go/kubernetes/scheme"
2727
"k8s.io/client-go/rest"
28-
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
28+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
2929
"sigs.k8s.io/controller-runtime/pkg/client"
3030
"sigs.k8s.io/controller-runtime/pkg/envtest"
3131
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"

go.mod

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
module github.com/kubernetes-sigs/cluster-api-provider-ibmcloud
22

3-
go 1.13
3+
go 1.16
44

55
require (
66
github.com/IBM/go-sdk-core v1.1.0
77
github.com/IBM/go-sdk-core/v4 v4.5.1 // indirect
88
github.com/IBM/vpc-go-sdk v0.1.1
9-
github.com/go-logr/logr v0.1.0
10-
github.com/onsi/ginkgo v1.13.0
11-
github.com/onsi/gomega v1.10.1
9+
github.com/go-logr/logr v0.4.0
10+
github.com/onsi/ginkgo v1.16.1
11+
github.com/onsi/gomega v1.11.0
1212
github.com/pkg/errors v0.9.1
13-
github.com/prometheus/common v0.9.1
14-
k8s.io/api v0.17.9
15-
k8s.io/apimachinery v0.17.9
16-
k8s.io/client-go v0.17.9
17-
k8s.io/klog/v2 v2.0.0
18-
k8s.io/utils v0.0.0-20200619165400-6e3d28b6ed19
19-
sigs.k8s.io/cluster-api v0.3.9
20-
sigs.k8s.io/controller-runtime v0.5.10
13+
github.com/prometheus/common v0.15.0
14+
k8s.io/api v0.21.1
15+
k8s.io/apimachinery v0.21.1
16+
k8s.io/client-go v0.21.1
17+
k8s.io/klog/v2 v2.8.0
18+
k8s.io/utils v0.0.0-20210305010621-2afb4311ab10
19+
sigs.k8s.io/cluster-api v0.0.0-20210526191338-0e1629b75111
20+
sigs.k8s.io/controller-runtime v0.9.0-beta.5
2121
)

0 commit comments

Comments
 (0)