From 1eace71a26824921b1fb0ad7323de44edf2cd6d2 Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Mon, 4 Feb 2019 15:37:14 -0800 Subject: [PATCH] Remove client.ListOptions.Raw hack Signed-off-by: Vince Prignano --- config/crds/cluster_v1alpha1_machine.yaml | 16 +++++++++++++ .../cluster_v1alpha1_machinedeployment.yaml | 18 ++++++++++++++ config/crds/cluster_v1alpha1_machineset.yaml | 18 ++++++++++++++ pkg/controller/machine/BUILD.bazel | 1 - pkg/controller/machine/controller.go | 10 +------- .../machinedeployment/controller.go | 24 ------------------- pkg/controller/machineset/machine.go | 8 ------- 7 files changed, 53 insertions(+), 42 deletions(-) diff --git a/config/crds/cluster_v1alpha1_machine.yaml b/config/crds/cluster_v1alpha1_machine.yaml index f24e69f338e6..d513c9c1a0d7 100644 --- a/config/crds/cluster_v1alpha1_machine.yaml +++ b/config/crds/cluster_v1alpha1_machine.yaml @@ -42,6 +42,22 @@ spec: to indicate what labels, annotations, name prefix, etc., should be used when creating the Node. type: object + providerID: + description: ProviderID is the identification ID of the machine provided + by the provider. This field must match the provider ID as seen on + the node object corresponding to this machine. This field is required + by higher level consumers of cluster-api. Example use case is cluster + autoscaler with cluster-api as provider. Clean-up login in the autoscaler + compares machines v/s nodes to find out machines at provider which + could not get registered as Kubernetes nodes. With cluster-api as + a generic out-of-tree provider for autoscaler, this field is required + by autoscaler to be able to have a provider view of the list of machines. + Another list of nodes is queries from the k8s apiserver and then comparison + is done to find out unregistered machines and are marked for delete. + This field will be set by the actuators and consumed by higher level + entities like autoscaler who will be interfacing with cluster-api + as generic provider. + type: string providerSpec: description: ProviderSpec details Provider-specific configuration to use during node creation. diff --git a/config/crds/cluster_v1alpha1_machinedeployment.yaml b/config/crds/cluster_v1alpha1_machinedeployment.yaml index 40bbc3036ca2..f0d5bf730911 100644 --- a/config/crds/cluster_v1alpha1_machinedeployment.yaml +++ b/config/crds/cluster_v1alpha1_machinedeployment.yaml @@ -136,6 +136,24 @@ spec: Use this to indicate what labels, annotations, name prefix, etc., should be used when creating the Node. type: object + providerID: + description: ProviderID is the identification ID of the machine + provided by the provider. This field must match the provider + ID as seen on the node object corresponding to this machine. + This field is required by higher level consumers of cluster-api. + Example use case is cluster autoscaler with cluster-api as + provider. Clean-up login in the autoscaler compares machines + v/s nodes to find out machines at provider which could not + get registered as Kubernetes nodes. With cluster-api as a + generic out-of-tree provider for autoscaler, this field is + required by autoscaler to be able to have a provider view + of the list of machines. Another list of nodes is queries + from the k8s apiserver and then comparison is done to find + out unregistered machines and are marked for delete. This + field will be set by the actuators and consumed by higher + level entities like autoscaler who will be interfacing with + cluster-api as generic provider. + type: string providerSpec: description: ProviderSpec details Provider-specific configuration to use during node creation. diff --git a/config/crds/cluster_v1alpha1_machineset.yaml b/config/crds/cluster_v1alpha1_machineset.yaml index 4df91b3de86b..dcc20f00dea7 100644 --- a/config/crds/cluster_v1alpha1_machineset.yaml +++ b/config/crds/cluster_v1alpha1_machineset.yaml @@ -76,6 +76,24 @@ spec: Use this to indicate what labels, annotations, name prefix, etc., should be used when creating the Node. type: object + providerID: + description: ProviderID is the identification ID of the machine + provided by the provider. This field must match the provider + ID as seen on the node object corresponding to this machine. + This field is required by higher level consumers of cluster-api. + Example use case is cluster autoscaler with cluster-api as + provider. Clean-up login in the autoscaler compares machines + v/s nodes to find out machines at provider which could not + get registered as Kubernetes nodes. With cluster-api as a + generic out-of-tree provider for autoscaler, this field is + required by autoscaler to be able to have a provider view + of the list of machines. Another list of nodes is queries + from the k8s apiserver and then comparison is done to find + out unregistered machines and are marked for delete. This + field will be set by the actuators and consumed by higher + level entities like autoscaler who will be interfacing with + cluster-api as generic provider. + type: string providerSpec: description: ProviderSpec details Provider-specific configuration to use during node creation. diff --git a/pkg/controller/machine/BUILD.bazel b/pkg/controller/machine/BUILD.bazel index 604b374af819..2266261c0d27 100644 --- a/pkg/controller/machine/BUILD.bazel +++ b/pkg/controller/machine/BUILD.bazel @@ -15,7 +15,6 @@ go_library( "//pkg/util:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", - "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/klog:go_default_library", "//vendor/sigs.k8s.io/controller-runtime/pkg/client:go_default_library", diff --git a/pkg/controller/machine/controller.go b/pkg/controller/machine/controller.go index 00b9c77f3dc9..f748359b8590 100644 --- a/pkg/controller/machine/controller.go +++ b/pkg/controller/machine/controller.go @@ -23,7 +23,6 @@ import ( corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/klog" clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" @@ -197,15 +196,8 @@ func (r *ReconcileMachine) getCluster(ctx context.Context, machine *clusterv1.Ma clusterList := clusterv1.ClusterList{} listOptions := &client.ListOptions{ Namespace: machine.Namespace, - // This is set so the fake client can be used for unit test. See: - // https://github.com/kubernetes-sigs/controller-runtime/issues/168 - Raw: &metav1.ListOptions{ - TypeMeta: metav1.TypeMeta{ - APIVersion: clusterv1.SchemeGroupVersion.String(), - Kind: "Cluster", - }, - }, } + if err := r.Client.List(ctx, listOptions, &clusterList); err != nil { return nil, err } diff --git a/pkg/controller/machinedeployment/controller.go b/pkg/controller/machinedeployment/controller.go index 1109b8ad1468..503d902204fb 100644 --- a/pkg/controller/machinedeployment/controller.go +++ b/pkg/controller/machinedeployment/controller.go @@ -97,14 +97,6 @@ func (r *ReconcileMachineDeployment) getMachineSetsForDeployment(d *v1alpha1.Mac machineSets := &v1alpha1.MachineSetList{} listOptions := &client.ListOptions{ Namespace: d.Namespace, - // This is set so the fake client can be used for unit test. See: - // https://github.com/kubernetes-sigs/controller-runtime/issues/168 - Raw: &metav1.ListOptions{ - TypeMeta: metav1.TypeMeta{ - APIVersion: v1alpha1.SchemeGroupVersion.String(), - Kind: "MachineSet", - }, - }, } if err := r.Client.List(context.Background(), listOptions, machineSets); err != nil { return nil, err @@ -206,14 +198,6 @@ func (r *ReconcileMachineDeployment) getMachineDeploymentsForMachineSet(ms *v1al dList := &v1alpha1.MachineDeploymentList{} listOptions := &client.ListOptions{ Namespace: ms.Namespace, - // This is set so the fake client can be used for unit test. See: - // https://github.com/kubernetes-sigs/controller-runtime/issues/168 - Raw: &metav1.ListOptions{ - TypeMeta: metav1.TypeMeta{ - APIVersion: v1alpha1.SchemeGroupVersion.String(), - Kind: "MachineDeployment", - }, - }, } if err := r.Client.List(context.Background(), listOptions, dList); err != nil { klog.Warningf("failed to list machine deployments, %v", err) @@ -252,14 +236,6 @@ func (r *ReconcileMachineDeployment) getMachineMapForDeployment(d *v1alpha1.Mach machines := &v1alpha1.MachineList{} listOptions := &client.ListOptions{ Namespace: d.Namespace, - // This is set so the fake client can be used for unit test. See: - // https://github.com/kubernetes-sigs/controller-runtime/issues/168 - Raw: &metav1.ListOptions{ - TypeMeta: metav1.TypeMeta{ - APIVersion: v1alpha1.SchemeGroupVersion.String(), - Kind: "Machine", - }, - }, } if err = r.Client.List(context.Background(), listOptions.MatchingLabels(selector), machines); err != nil { return nil, err diff --git a/pkg/controller/machineset/machine.go b/pkg/controller/machineset/machine.go index ea7ab1e4ed85..7776a7a86132 100644 --- a/pkg/controller/machineset/machine.go +++ b/pkg/controller/machineset/machine.go @@ -35,14 +35,6 @@ func (c *ReconcileMachineSet) getMachineSetsForMachine(m *v1alpha1.Machine) []*v msList := &v1alpha1.MachineSetList{} listOptions := &client.ListOptions{ Namespace: m.Namespace, - // This is set so the fake client can be used for unit test. See: - // https://github.com/kubernetes-sigs/controller-runtime/issues/168 - Raw: &metav1.ListOptions{ - TypeMeta: metav1.TypeMeta{ - APIVersion: v1alpha1.SchemeGroupVersion.String(), - Kind: "MachineSet", - }, - }, } err := c.Client.List(context.Background(), listOptions, msList)