Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] 4.16 client updates #4112

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 0 additions & 2 deletions cmd/aro/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ func operator(ctx context.Context, log *logrus.Entry) error {

mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
HealthProbeBindAddress: ":8080",
MetricsBindAddress: "0", // disabled
Port: 8443,
})
if err != nil {
return err
Expand Down
707 changes: 90 additions & 617 deletions go.mod

Large diffs are not rendered by default.

333 changes: 212 additions & 121 deletions go.sum

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions pkg/cluster/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

configclient "github.com/openshift/client-go/config/clientset/versioned"
imageregistryclient "github.com/openshift/client-go/imageregistry/clientset/versioned"
Expand Down Expand Up @@ -632,14 +631,7 @@ func (m *manager) initializeKubernetesClients(ctx context.Context) error {
return err
}

mapper, err := apiutil.NewDynamicRESTMapper(restConfig, apiutil.WithLazyDiscovery)
if err != nil {
return err
}

client, err := client.New(restConfig, client.Options{
Mapper: mapper,
})
client, err := client.New(restConfig, client.Options{})

m.ch = clienthelper.NewWithClient(m.log, client)
return err
Expand Down
8 changes: 7 additions & 1 deletion pkg/frontend/adminactions/kubeactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

"github.com/Azure/ARO-RP/pkg/api"
Expand Down Expand Up @@ -59,7 +60,12 @@ func NewKubeActions(log *logrus.Entry, env env.Interface, oc *api.OpenShiftClust
return nil, err
}

mapper, err := apiutil.NewDynamicRESTMapper(restConfig, apiutil.WithLazyDiscovery)
httpClient, err := rest.HTTPClientFor(restConfig)
if err != nil {
return nil, err
}

mapper, err := apiutil.NewDynamicRESTMapper(restConfig, httpClient)
if err != nil {
return nil, err
}
Expand Down
11 changes: 1 addition & 10 deletions pkg/mimo/actuator/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/sirupsen/logrus"

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

"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/env"
Expand Down Expand Up @@ -88,15 +87,7 @@ func (t *th) ClientHelper() (clienthelper.Interface, error) {
if err != nil {
return nil, err
}

mapper, err := apiutil.NewDynamicRESTMapper(restConfig, apiutil.WithLazyDiscovery)
if err != nil {
return nil, err
}

client, err := client.New(restConfig, client.Options{
Mapper: mapper,
})
client, err := client.New(restConfig, client.Options{})
if err != nil {
return nil, err
}
Expand Down
21 changes: 2 additions & 19 deletions pkg/monitor/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"

configv1 "github.com/openshift/api/config/v1"
configclient "github.com/openshift/client-go/config/clientset/versioned"
Expand Down Expand Up @@ -115,15 +114,7 @@ func NewMonitor(log *logrus.Entry, restConfig *rest.Config, oc *api.OpenShiftClu
return nil, err
}

// lazy discovery will not attempt to reach out to the apiserver immediately
mapper, err := apiutil.NewDynamicRESTMapper(restConfig, apiutil.WithLazyDiscovery)
if err != nil {
return nil, err
}

ocpclientset, err := client.New(restConfig, client.Options{
Mapper: mapper,
})
ocpclientset, err := client.New(restConfig, client.Options{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -163,15 +154,7 @@ func getHiveClientSet(hiveRestConfig *rest.Config) (client.Client, error) {
return nil, nil
}

// lazy discovery will not attempt to reach out to the apiserver immediately
mapper, err := apiutil.NewDynamicRESTMapper(hiveRestConfig, apiutil.WithLazyDiscovery)
if err != nil {
return nil, err
}

hiveclientset, err := client.New(hiveRestConfig, client.Options{
Mapper: mapper,
})
hiveclientset, err := client.New(hiveRestConfig, client.Options{})
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/operator/controllers/banner/banner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

consolev1 "github.com/openshift/api/console/v1"

Expand Down Expand Up @@ -69,7 +68,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
// watching ConsoleNotifications in case a user edits it
Watches(&source.Kind{Type: &consolev1.ConsoleNotification{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(aroBannerPredicate)).
Watches(&consolev1.ConsoleNotification{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(aroBannerPredicate)).
Named(ControllerName).
Complete(r)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

operatorv1 "github.com/openshift/api/operator/v1"

Expand Down Expand Up @@ -127,7 +126,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
builder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &operatorv1.DNS{}},
&operatorv1.DNS{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(defaultClusterDNSPredicate),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

configv1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
Expand Down Expand Up @@ -128,12 +127,12 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
builder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &operatorv1.IngressController{}},
&operatorv1.IngressController{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(defaultIngressControllerPredicate),
).
Watches(
&source.Kind{Type: &configv1.ClusterVersion{}},
&configv1.ClusterVersion{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicates.ClusterVersion),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

operatorv1 "github.com/openshift/api/operator/v1"

Expand Down Expand Up @@ -124,7 +123,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
builder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(clusterSPPredicate),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
Expand Down Expand Up @@ -173,7 +172,7 @@ func (r *CloudProviderConfigReconciler) SetupWithManager(mgr ctrl.Manager) error
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &corev1.ConfigMap{}},
&corev1.ConfigMap{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(cloudProviderConfigPredicate),
).
Expand Down
3 changes: 1 addition & 2 deletions pkg/operator/controllers/cpms/cpms_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

machinev1 "github.com/openshift/api/machine/v1"

Expand Down Expand Up @@ -93,7 +92,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(aroClusterPredicate, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &machinev1.ControlPlaneMachineSet{}},
&machinev1.ControlPlaneMachineSet{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicate.GenerationChangedPredicate{}), // only watch for spec changes
).
Expand Down
3 changes: 1 addition & 2 deletions pkg/operator/controllers/dnsmasq/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

configv1 "github.com/openshift/api/config/v1"
mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
Expand Down Expand Up @@ -105,7 +104,7 @@ func (r *ClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Named(ClusterControllerName).
Watches(
&source.Kind{Type: &configv1.ClusterVersion{}},
&configv1.ClusterVersion{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(clusterVersionPredicate),
).
Expand Down
5 changes: 2 additions & 3 deletions pkg/operator/controllers/etchosts/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"

Expand Down Expand Up @@ -199,10 +198,10 @@ func (r *EtcHostsClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {

etcHostsBuilder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(&source.Kind{Type: &mcv1.MachineConfigPool{}},
Watches(&mcv1.MachineConfigPool{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&source.Kind{Type: &mcv1.MachineConfig{}},
Watches(&mcv1.MachineConfig{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicate.GenerationChangedPredicate{}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"

Expand Down Expand Up @@ -145,10 +144,10 @@ func (r *EtcHostsMachineConfigReconciler) SetupWithManager(mgr ctrl.Manager) err

etcHostsBuilder := ctrl.NewControllerManagedBy(mgr).
For(&mcv1.MachineConfig{}).
Watches(&source.Kind{Type: &mcv1.MachineConfigPool{}},
Watches(&mcv1.MachineConfigPool{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Watches(&source.Kind{Type: &arov1alpha1.Cluster{}},
Watches(&arov1alpha1.Cluster{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{})))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

configv1 "github.com/openshift/api/config/v1"
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
Expand Down Expand Up @@ -174,7 +173,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&machinev1beta1.MachineHealthCheck{}).
Owns(&monitoringv1.PrometheusRule{}).
Watches(
&source.Kind{Type: &configv1.ClusterVersion{}},
&configv1.ClusterVersion{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicates.ClusterVersion),
).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
"sigs.k8s.io/yaml"

"github.com/Azure/ARO-RP/pkg/api"
Expand Down Expand Up @@ -216,7 +215,7 @@ func (r *MonitoringReconciler) SetupWithManager(mgr ctrl.Manager) error {
// https://github.com/kubernetes-sigs/controller-runtime/issues/1173
// equivalent to For(&v1.ConfigMap{}, ...)., but can't call For multiple times on one builder
Watches(
&source.Kind{Type: &corev1.ConfigMap{}},
&corev1.ConfigMap{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(monitoringConfigMapPredicate),
).
Expand Down
3 changes: 1 addition & 2 deletions pkg/operator/controllers/muo/muo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
Expand Down Expand Up @@ -175,7 +174,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
muoBuilder := ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicates.PullSecret),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/Azure/ARO-RP/pkg/operator"
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
Expand Down Expand Up @@ -130,7 +129,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
// https://github.com/kubernetes-sigs/controller-runtime/issues/1173
// equivalent to For(&v1.Secret{})., but can't call For multiple times on one builder
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(predicate.Or(predicates.PullSecret, predicates.BackupPullSecret)),
).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

machinev1beta1 "github.com/openshift/api/machine/v1beta1"

Expand Down Expand Up @@ -116,8 +115,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(&source.Kind{Type: &machinev1beta1.Machine{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleMaster)). // to reconcile on master machine replacement
Watches(&source.Kind{Type: &machinev1beta1.MachineSet{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleWorker)). // to reconcile on worker machines
Watches(&machinev1beta1.Machine{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleMaster)). // to reconcile on master machine replacement
Watches(&machinev1beta1.MachineSet{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleWorker)). // to reconcile on worker machines
Named(ControllerName).
Complete(r)
}
5 changes: 2 additions & 3 deletions pkg/operator/controllers/subnets/subnets_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

machinev1beta1 "github.com/openshift/api/machine/v1beta1"

Expand Down Expand Up @@ -154,8 +153,8 @@ func (r *reconcileManager) reconcileSubnets(ctx context.Context) error {
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&arov1alpha1.Cluster{}, builder.WithPredicates(predicate.And(predicates.AROCluster, predicate.GenerationChangedPredicate{}))).
Watches(&source.Kind{Type: &machinev1beta1.Machine{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleMaster)). // to reconcile on master machine replacement
Watches(&source.Kind{Type: &machinev1beta1.MachineSet{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleWorker)). // to reconcile on worker machines
Watches(&machinev1beta1.Machine{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleMaster)). // to reconcile on master machine replacement
Watches(&machinev1beta1.MachineSet{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(predicates.MachineRoleWorker)). // to reconcile on worker machines
Named(ControllerName).
Complete(r)
}
Loading
Loading