зеркало из https://github.com/Azure/ARO-RP.git
Removes dependency on a versioned ARO client
Operator is not longer dependant on a version client for ARO objects and is now using a split client.
This commit is contained in:
Родитель
8080049aa6
Коммит
ec7cb16295
|
@ -22,7 +22,6 @@ import (
|
||||||
|
|
||||||
"github.com/Azure/ARO-RP/pkg/env"
|
"github.com/Azure/ARO-RP/pkg/env"
|
||||||
pkgoperator "github.com/Azure/ARO-RP/pkg/operator"
|
pkgoperator "github.com/Azure/ARO-RP/pkg/operator"
|
||||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
|
|
||||||
"github.com/Azure/ARO-RP/pkg/operator/controllers/alertwebhook"
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/alertwebhook"
|
||||||
"github.com/Azure/ARO-RP/pkg/operator/controllers/autosizednodes"
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/autosizednodes"
|
||||||
"github.com/Azure/ARO-RP/pkg/operator/controllers/banner"
|
"github.com/Azure/ARO-RP/pkg/operator/controllers/banner"
|
||||||
|
@ -81,10 +80,6 @@ func operator(ctx context.Context, log *logrus.Entry) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
arocli, err := aroclient.NewForConfig(restConfig)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
configcli, err := configclient.NewForConfig(restConfig)
|
configcli, err := configclient.NewForConfig(restConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -188,7 +183,7 @@ func operator(ctx context.Context, log *logrus.Entry) error {
|
||||||
}
|
}
|
||||||
if err = (machine.NewReconciler(
|
if err = (machine.NewReconciler(
|
||||||
log.WithField("controller", machine.ControllerName),
|
log.WithField("controller", machine.ControllerName),
|
||||||
arocli, maocli, isLocalDevelopmentMode, role)).SetupWithManager(mgr); err != nil {
|
maocli, isLocalDevelopmentMode, role)).SetupWithManager(mgr); err != nil {
|
||||||
return fmt.Errorf("unable to create controller %s: %v", machine.ControllerName, err)
|
return fmt.Errorf("unable to create controller %s: %v", machine.ControllerName, err)
|
||||||
}
|
}
|
||||||
if err = (banner.NewReconciler(
|
if err = (banner.NewReconciler(
|
||||||
|
@ -237,24 +232,23 @@ func operator(ctx context.Context, log *logrus.Entry) error {
|
||||||
}
|
}
|
||||||
if err = (serviceprincipalchecker.NewReconciler(
|
if err = (serviceprincipalchecker.NewReconciler(
|
||||||
log.WithField("controller", serviceprincipalchecker.ControllerName),
|
log.WithField("controller", serviceprincipalchecker.ControllerName),
|
||||||
arocli, kubernetescli, role)).SetupWithManager(mgr); err != nil {
|
kubernetescli, role)).SetupWithManager(mgr); err != nil {
|
||||||
return fmt.Errorf("unable to create controller %s: %v", serviceprincipalchecker.ControllerName, err)
|
return fmt.Errorf("unable to create controller %s: %v", serviceprincipalchecker.ControllerName, err)
|
||||||
}
|
}
|
||||||
if err = (clusterdnschecker.NewReconciler(
|
if err = (clusterdnschecker.NewReconciler(
|
||||||
log.WithField("controller", clusterdnschecker.ControllerName),
|
log.WithField("controller", clusterdnschecker.ControllerName),
|
||||||
arocli, operatorcli, role)).SetupWithManager(mgr); err != nil {
|
operatorcli, role)).SetupWithManager(mgr); err != nil {
|
||||||
return fmt.Errorf("unable to create controller %s: %v", clusterdnschecker.ControllerName, err)
|
return fmt.Errorf("unable to create controller %s: %v", clusterdnschecker.ControllerName, err)
|
||||||
}
|
}
|
||||||
if err = (ingresscertificatechecker.NewReconciler(
|
if err = (ingresscertificatechecker.NewReconciler(
|
||||||
log.WithField("controller", ingresscertificatechecker.ControllerName),
|
log.WithField("controller", ingresscertificatechecker.ControllerName),
|
||||||
arocli, operatorcli, configcli, role)).SetupWithManager(mgr); err != nil {
|
operatorcli, configcli, role)).SetupWithManager(mgr); err != nil {
|
||||||
return fmt.Errorf("unable to create controller %s: %v", ingresscertificatechecker.ControllerName, err)
|
return fmt.Errorf("unable to create controller %s: %v", ingresscertificatechecker.ControllerName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = (internetchecker.NewReconciler(
|
if err = (internetchecker.NewReconciler(
|
||||||
log.WithField("controller", internetchecker.ControllerName),
|
log.WithField("controller", internetchecker.ControllerName), role)).SetupWithManager(mgr); err != nil {
|
||||||
arocli, role)).SetupWithManager(mgr); err != nil {
|
|
||||||
return fmt.Errorf("unable to create controller %s: %v", internetchecker.ControllerName, err)
|
return fmt.Errorf("unable to create controller %s: %v", internetchecker.ControllerName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"sigs.k8s.io/controller-runtime/pkg/source"
|
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
|
|
||||||
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/conditions"
|
"github.com/Azure/ARO-RP/pkg/util/conditions"
|
||||||
)
|
)
|
||||||
|
@ -40,18 +39,16 @@ type Reconciler struct {
|
||||||
log *logrus.Entry
|
log *logrus.Entry
|
||||||
role string
|
role string
|
||||||
|
|
||||||
arocli aroclient.Interface
|
|
||||||
checker clusterDNSChecker
|
checker clusterDNSChecker
|
||||||
|
|
||||||
client client.Client
|
client client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReconciler(log *logrus.Entry, arocli aroclient.Interface, operatorcli operatorclient.Interface, role string) *Reconciler {
|
func NewReconciler(log *logrus.Entry, operatorcli operatorclient.Interface, role string) *Reconciler {
|
||||||
return &Reconciler{
|
return &Reconciler{
|
||||||
log: log,
|
log: log,
|
||||||
role: role,
|
role: role,
|
||||||
|
|
||||||
arocli: arocli,
|
|
||||||
checker: newClusterDNSChecker(operatorcli),
|
checker: newClusterDNSChecker(operatorcli),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +70,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
|
||||||
checkErr := r.checker.Check(ctx)
|
checkErr := r.checker.Check(ctx)
|
||||||
condition := r.condition(checkErr)
|
condition := r.condition(checkErr)
|
||||||
|
|
||||||
err = conditions.SetCondition(ctx, r.arocli, condition, r.role)
|
err = conditions.SetCondition(ctx, r.client, condition, r.role)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return reconcile.Result{}, err
|
return reconcile.Result{}, err
|
||||||
}
|
}
|
||||||
|
@ -91,7 +88,7 @@ func (r *Reconciler) reconcileDisabled(ctx context.Context) (ctrl.Result, error)
|
||||||
Status: operatorv1.ConditionUnknown,
|
Status: operatorv1.ConditionUnknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
return reconcile.Result{}, conditions.SetCondition(ctx, r.arocli, condition, r.role)
|
return reconcile.Result{}, conditions.SetCondition(ctx, r.client, condition, r.role)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reconciler) condition(checkErr error) *operatorv1.OperatorCondition {
|
func (r *Reconciler) condition(checkErr error) *operatorv1.OperatorCondition {
|
||||||
|
|
|
@ -12,12 +12,12 @@ import (
|
||||||
|
|
||||||
operatorv1 "github.com/openshift/api/operator/v1"
|
operatorv1 "github.com/openshift/api/operator/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
arofake "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/fake"
|
|
||||||
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/azureclient"
|
"github.com/Azure/ARO-RP/pkg/util/azureclient"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/cmp"
|
"github.com/Azure/ARO-RP/pkg/util/cmp"
|
||||||
|
@ -83,7 +83,6 @@ func TestReconcile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clientFake := fake.NewClientBuilder().WithObjects(instance).Build()
|
clientFake := fake.NewClientBuilder().WithObjects(instance).Build()
|
||||||
arocliFake := arofake.NewSimpleClientset(instance)
|
|
||||||
|
|
||||||
r := &Reconciler{
|
r := &Reconciler{
|
||||||
log: utillog.GetLogger(),
|
log: utillog.GetLogger(),
|
||||||
|
@ -91,7 +90,6 @@ func TestReconcile(t *testing.T) {
|
||||||
checker: fakeChecker(func(ctx context.Context) error {
|
checker: fakeChecker(func(ctx context.Context) error {
|
||||||
return tt.checkerReturnErr
|
return tt.checkerReturnErr
|
||||||
}),
|
}),
|
||||||
arocli: arocliFake,
|
|
||||||
client: clientFake,
|
client: clientFake,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +103,7 @@ func TestReconcile(t *testing.T) {
|
||||||
t.Error(cmp.Diff(tt.wantResult, result))
|
t.Error(cmp.Diff(tt.wantResult, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
instance, err = arocliFake.AroV1alpha1().Clusters().Get(ctx, arov1alpha1.SingletonClusterName, metav1.GetOptions{})
|
err = r.client.Get(ctx, types.NamespacedName{Name: arov1alpha1.SingletonClusterName}, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"sigs.k8s.io/controller-runtime/pkg/source"
|
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
|
|
||||||
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/conditions"
|
"github.com/Azure/ARO-RP/pkg/util/conditions"
|
||||||
)
|
)
|
||||||
|
@ -43,18 +42,16 @@ type Reconciler struct {
|
||||||
log *logrus.Entry
|
log *logrus.Entry
|
||||||
role string
|
role string
|
||||||
|
|
||||||
arocli aroclient.Interface
|
|
||||||
checker ingressCertificateChecker
|
checker ingressCertificateChecker
|
||||||
|
|
||||||
client client.Client
|
client client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReconciler(log *logrus.Entry, arocli aroclient.Interface, operatorcli operatorclient.Interface, configcli configclient.Interface, role string) *Reconciler {
|
func NewReconciler(log *logrus.Entry, operatorcli operatorclient.Interface, configcli configclient.Interface, role string) *Reconciler {
|
||||||
return &Reconciler{
|
return &Reconciler{
|
||||||
log: log,
|
log: log,
|
||||||
role: role,
|
role: role,
|
||||||
|
|
||||||
arocli: arocli,
|
|
||||||
checker: newIngressCertificateChecker(operatorcli, configcli),
|
checker: newIngressCertificateChecker(operatorcli, configcli),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +73,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
|
||||||
checkErr := r.checker.Check(ctx)
|
checkErr := r.checker.Check(ctx)
|
||||||
condition := r.condition(checkErr)
|
condition := r.condition(checkErr)
|
||||||
|
|
||||||
err = conditions.SetCondition(ctx, r.arocli, condition, r.role)
|
err = conditions.SetCondition(ctx, r.client, condition, r.role)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return reconcile.Result{}, err
|
return reconcile.Result{}, err
|
||||||
}
|
}
|
||||||
|
@ -101,7 +98,7 @@ func (r *Reconciler) reconcileDisabled(ctx context.Context) (ctrl.Result, error)
|
||||||
Status: operatorv1.ConditionUnknown,
|
Status: operatorv1.ConditionUnknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
return reconcile.Result{}, conditions.SetCondition(ctx, r.arocli, condition, r.role)
|
return reconcile.Result{}, conditions.SetCondition(ctx, r.client, condition, r.role)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reconciler) condition(checkErr error) *operatorv1.OperatorCondition {
|
func (r *Reconciler) condition(checkErr error) *operatorv1.OperatorCondition {
|
||||||
|
|
|
@ -12,12 +12,12 @@ import (
|
||||||
|
|
||||||
operatorv1 "github.com/openshift/api/operator/v1"
|
operatorv1 "github.com/openshift/api/operator/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
arofake "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/fake"
|
|
||||||
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/azureclient"
|
"github.com/Azure/ARO-RP/pkg/util/azureclient"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/cmp"
|
"github.com/Azure/ARO-RP/pkg/util/cmp"
|
||||||
|
@ -90,7 +90,6 @@ func TestReconcile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clientFake := fake.NewClientBuilder().WithObjects(instance).Build()
|
clientFake := fake.NewClientBuilder().WithObjects(instance).Build()
|
||||||
arocliFake := arofake.NewSimpleClientset(instance)
|
|
||||||
|
|
||||||
r := &Reconciler{
|
r := &Reconciler{
|
||||||
log: utillog.GetLogger(),
|
log: utillog.GetLogger(),
|
||||||
|
@ -99,7 +98,6 @@ func TestReconcile(t *testing.T) {
|
||||||
return tt.checkerReturnErr
|
return tt.checkerReturnErr
|
||||||
}),
|
}),
|
||||||
client: clientFake,
|
client: clientFake,
|
||||||
arocli: arocliFake,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := r.Reconcile(ctx, ctrl.Request{})
|
result, err := r.Reconcile(ctx, ctrl.Request{})
|
||||||
|
@ -112,7 +110,7 @@ func TestReconcile(t *testing.T) {
|
||||||
t.Error(cmp.Diff(tt.wantResult, result))
|
t.Error(cmp.Diff(tt.wantResult, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
instance, err = arocliFake.AroV1alpha1().Clusters().Get(ctx, arov1alpha1.SingletonClusterName, metav1.GetOptions{})
|
err = r.client.Get(ctx, types.NamespacedName{Name: arov1alpha1.SingletonClusterName}, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
|
|
||||||
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/conditions"
|
"github.com/Azure/ARO-RP/pkg/util/conditions"
|
||||||
)
|
)
|
||||||
|
@ -37,18 +36,16 @@ type Reconciler struct {
|
||||||
log *logrus.Entry
|
log *logrus.Entry
|
||||||
role string
|
role string
|
||||||
|
|
||||||
arocli aroclient.Interface
|
|
||||||
checker internetChecker
|
checker internetChecker
|
||||||
|
|
||||||
client client.Client
|
client client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReconciler(log *logrus.Entry, arocli aroclient.Interface, role string) *Reconciler {
|
func NewReconciler(log *logrus.Entry, role string) *Reconciler {
|
||||||
return &Reconciler{
|
return &Reconciler{
|
||||||
log: log,
|
log: log,
|
||||||
role: role,
|
role: role,
|
||||||
|
|
||||||
arocli: arocli,
|
|
||||||
checker: newInternetChecker(),
|
checker: newInternetChecker(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +67,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
|
||||||
checkErr := r.checker.Check(instance.Spec.InternetChecker.URLs)
|
checkErr := r.checker.Check(instance.Spec.InternetChecker.URLs)
|
||||||
condition := r.condition(checkErr)
|
condition := r.condition(checkErr)
|
||||||
|
|
||||||
err = conditions.SetCondition(ctx, r.arocli, condition, r.role)
|
err = conditions.SetCondition(ctx, r.client, condition, r.role)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return reconcile.Result{}, err
|
return reconcile.Result{}, err
|
||||||
}
|
}
|
||||||
|
@ -88,7 +85,7 @@ func (r *Reconciler) reconcileDisabled(ctx context.Context) (ctrl.Result, error)
|
||||||
Status: operatorv1.ConditionUnknown,
|
Status: operatorv1.ConditionUnknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
return reconcile.Result{}, conditions.SetCondition(ctx, r.arocli, condition, r.role)
|
return reconcile.Result{}, conditions.SetCondition(ctx, r.client, condition, r.role)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reconciler) condition(checkErr error) *operatorv1.OperatorCondition {
|
func (r *Reconciler) condition(checkErr error) *operatorv1.OperatorCondition {
|
||||||
|
|
|
@ -12,13 +12,13 @@ import (
|
||||||
|
|
||||||
operatorv1 "github.com/openshift/api/operator/v1"
|
operatorv1 "github.com/openshift/api/operator/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
|
||||||
"github.com/Azure/ARO-RP/pkg/operator"
|
"github.com/Azure/ARO-RP/pkg/operator"
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
arofake "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/fake"
|
|
||||||
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/cmp"
|
"github.com/Azure/ARO-RP/pkg/util/cmp"
|
||||||
utillog "github.com/Azure/ARO-RP/pkg/util/log"
|
utillog "github.com/Azure/ARO-RP/pkg/util/log"
|
||||||
|
@ -90,7 +90,6 @@ func TestReconcile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clientFake := fake.NewClientBuilder().WithObjects(instance).Build()
|
clientFake := fake.NewClientBuilder().WithObjects(instance).Build()
|
||||||
arocliFake := arofake.NewSimpleClientset(instance)
|
|
||||||
|
|
||||||
r := &Reconciler{
|
r := &Reconciler{
|
||||||
log: utillog.GetLogger(),
|
log: utillog.GetLogger(),
|
||||||
|
@ -102,7 +101,6 @@ func TestReconcile(t *testing.T) {
|
||||||
|
|
||||||
return tt.checkerReturnErr
|
return tt.checkerReturnErr
|
||||||
}),
|
}),
|
||||||
arocli: arocliFake,
|
|
||||||
client: clientFake,
|
client: clientFake,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +114,7 @@ func TestReconcile(t *testing.T) {
|
||||||
t.Error(cmp.Diff(tt.wantResult, result))
|
t.Error(cmp.Diff(tt.wantResult, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
instance, err = arocliFake.AroV1alpha1().Clusters().Get(ctx, arov1alpha1.SingletonClusterName, metav1.GetOptions{})
|
err = r.client.Get(ctx, types.NamespacedName{Name: arov1alpha1.SingletonClusterName}, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"sigs.k8s.io/controller-runtime/pkg/source"
|
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
|
|
||||||
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/clusterauthorizer"
|
"github.com/Azure/ARO-RP/pkg/util/clusterauthorizer"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/conditions"
|
"github.com/Azure/ARO-RP/pkg/util/conditions"
|
||||||
|
@ -42,18 +41,16 @@ type Reconciler struct {
|
||||||
log *logrus.Entry
|
log *logrus.Entry
|
||||||
role string
|
role string
|
||||||
|
|
||||||
arocli aroclient.Interface
|
|
||||||
checker servicePrincipalChecker
|
checker servicePrincipalChecker
|
||||||
|
|
||||||
client client.Client
|
client client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReconciler(log *logrus.Entry, arocli aroclient.Interface, kubernetescli kubernetes.Interface, role string) *Reconciler {
|
func NewReconciler(log *logrus.Entry, kubernetescli kubernetes.Interface, role string) *Reconciler {
|
||||||
return &Reconciler{
|
return &Reconciler{
|
||||||
log: log,
|
log: log,
|
||||||
role: role,
|
role: role,
|
||||||
|
|
||||||
arocli: arocli,
|
|
||||||
checker: newServicePrincipalChecker(log, kubernetescli),
|
checker: newServicePrincipalChecker(log, kubernetescli),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +72,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
|
||||||
checkErr := r.checker.Check(ctx, instance.Spec.AZEnvironment)
|
checkErr := r.checker.Check(ctx, instance.Spec.AZEnvironment)
|
||||||
condition := r.condition(checkErr)
|
condition := r.condition(checkErr)
|
||||||
|
|
||||||
err = conditions.SetCondition(ctx, r.arocli, condition, r.role)
|
err = conditions.SetCondition(ctx, r.client, condition, r.role)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return reconcile.Result{}, err
|
return reconcile.Result{}, err
|
||||||
}
|
}
|
||||||
|
@ -93,7 +90,7 @@ func (r *Reconciler) reconcileDisabled(ctx context.Context) (ctrl.Result, error)
|
||||||
Status: operatorv1.ConditionUnknown,
|
Status: operatorv1.ConditionUnknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
return reconcile.Result{}, conditions.SetCondition(ctx, r.arocli, condition, r.role)
|
return reconcile.Result{}, conditions.SetCondition(ctx, r.client, condition, r.role)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reconciler) condition(checkErr error) *operatorv1.OperatorCondition {
|
func (r *Reconciler) condition(checkErr error) *operatorv1.OperatorCondition {
|
||||||
|
|
|
@ -12,12 +12,12 @@ import (
|
||||||
|
|
||||||
operatorv1 "github.com/openshift/api/operator/v1"
|
operatorv1 "github.com/openshift/api/operator/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
arofake "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/fake"
|
|
||||||
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
checkercommon "github.com/Azure/ARO-RP/pkg/operator/controllers/checkers/common"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/azureclient"
|
"github.com/Azure/ARO-RP/pkg/util/azureclient"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/cmp"
|
"github.com/Azure/ARO-RP/pkg/util/cmp"
|
||||||
|
@ -83,7 +83,6 @@ func TestReconcile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clientFake := fake.NewClientBuilder().WithObjects(instance).Build()
|
clientFake := fake.NewClientBuilder().WithObjects(instance).Build()
|
||||||
arocliFake := arofake.NewSimpleClientset(instance)
|
|
||||||
|
|
||||||
r := &Reconciler{
|
r := &Reconciler{
|
||||||
log: utillog.GetLogger(),
|
log: utillog.GetLogger(),
|
||||||
|
@ -95,7 +94,6 @@ func TestReconcile(t *testing.T) {
|
||||||
|
|
||||||
return tt.checkerReturnErr
|
return tt.checkerReturnErr
|
||||||
}),
|
}),
|
||||||
arocli: arocliFake,
|
|
||||||
client: clientFake,
|
client: clientFake,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +107,7 @@ func TestReconcile(t *testing.T) {
|
||||||
t.Error(cmp.Diff(tt.wantResult, result))
|
t.Error(cmp.Diff(tt.wantResult, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
instance, err = arocliFake.AroV1alpha1().Clusters().Get(ctx, arov1alpha1.SingletonClusterName, metav1.GetOptions{})
|
err = r.client.Get(ctx, types.NamespacedName{Name: arov1alpha1.SingletonClusterName}, instance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
ctrlfake "sigs.k8s.io/controller-runtime/pkg/client/fake"
|
ctrlfake "sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
arofake "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/fake"
|
|
||||||
_ "github.com/Azure/ARO-RP/pkg/util/scheme"
|
_ "github.com/Azure/ARO-RP/pkg/util/scheme"
|
||||||
"github.com/Azure/ARO-RP/pkg/util/version"
|
"github.com/Azure/ARO-RP/pkg/util/version"
|
||||||
testdatabase "github.com/Azure/ARO-RP/test/database"
|
testdatabase "github.com/Azure/ARO-RP/test/database"
|
||||||
|
@ -37,7 +36,6 @@ func TestGenevaLoggingDaemonset(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
request ctrl.Request
|
request ctrl.Request
|
||||||
arocli *arofake.Clientset
|
|
||||||
operatorFlags arov1alpha1.OperatorFlags
|
operatorFlags arov1alpha1.OperatorFlags
|
||||||
validateDaemonset func(*appsv1.DaemonSet) []error
|
validateDaemonset func(*appsv1.DaemonSet) []error
|
||||||
}{
|
}{
|
||||||
|
|
|
@ -17,7 +17,6 @@ import (
|
||||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
|
|
||||||
"github.com/Azure/ARO-RP/pkg/util/conditions"
|
"github.com/Azure/ARO-RP/pkg/util/conditions"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,7 +29,6 @@ const (
|
||||||
type Reconciler struct {
|
type Reconciler struct {
|
||||||
log *logrus.Entry
|
log *logrus.Entry
|
||||||
|
|
||||||
arocli aroclient.Interface
|
|
||||||
maocli machineclient.Interface
|
maocli machineclient.Interface
|
||||||
|
|
||||||
isLocalDevelopmentMode bool
|
isLocalDevelopmentMode bool
|
||||||
|
@ -39,10 +37,9 @@ type Reconciler struct {
|
||||||
client client.Client
|
client client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReconciler(log *logrus.Entry, arocli aroclient.Interface, maocli machineclient.Interface, isLocalDevelopmentMode bool, role string) *Reconciler {
|
func NewReconciler(log *logrus.Entry, maocli machineclient.Interface, isLocalDevelopmentMode bool, role string) *Reconciler {
|
||||||
return &Reconciler{
|
return &Reconciler{
|
||||||
log: log,
|
log: log,
|
||||||
arocli: arocli,
|
|
||||||
maocli: maocli,
|
maocli: maocli,
|
||||||
isLocalDevelopmentMode: isLocalDevelopmentMode,
|
isLocalDevelopmentMode: isLocalDevelopmentMode,
|
||||||
role: role,
|
role: role,
|
||||||
|
@ -83,7 +80,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
|
||||||
cond.Message = sb.String()
|
cond.Message = sb.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
return reconcile.Result{}, conditions.SetCondition(ctx, r.arocli, cond, r.role)
|
return reconcile.Result{}, conditions.SetCondition(ctx, r.client, cond, r.role)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
|
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||||
|
|
|
@ -16,11 +16,11 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
kruntime "k8s.io/apimachinery/pkg/runtime"
|
kruntime "k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
arofake "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/fake"
|
|
||||||
_ "github.com/Azure/ARO-RP/pkg/util/scheme"
|
_ "github.com/Azure/ARO-RP/pkg/util/scheme"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,7 +72,6 @@ func TestMachineReconciler(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
request ctrl.Request
|
request ctrl.Request
|
||||||
maocli *machinefake.Clientset
|
maocli *machinefake.Clientset
|
||||||
arocli *arofake.Clientset
|
|
||||||
wantConditions []operatorv1.OperatorCondition
|
wantConditions []operatorv1.OperatorCondition
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -148,6 +147,8 @@ func TestMachineReconciler(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
baseCluster := arov1alpha1.Cluster{
|
baseCluster := arov1alpha1.Cluster{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "cluster"},
|
ObjectMeta: metav1.ObjectMeta{Name: "cluster"},
|
||||||
Status: arov1alpha1.ClusterStatus{Conditions: []operatorv1.OperatorCondition{}},
|
Status: arov1alpha1.ClusterStatus{Conditions: []operatorv1.OperatorCondition{}},
|
||||||
|
@ -159,23 +160,22 @@ func TestMachineReconciler(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
clientFake := fake.NewClientBuilder().WithObjects(&baseCluster).Build()
|
clientFake := fake.NewClientBuilder().WithObjects(&baseCluster).Build()
|
||||||
arocliFake := arofake.NewSimpleClientset(&baseCluster)
|
|
||||||
|
|
||||||
r := &Reconciler{
|
r := &Reconciler{
|
||||||
maocli: tt.maocli,
|
maocli: tt.maocli,
|
||||||
log: logrus.NewEntry(logrus.StandardLogger()),
|
log: logrus.NewEntry(logrus.StandardLogger()),
|
||||||
arocli: arocliFake,
|
|
||||||
isLocalDevelopmentMode: false,
|
isLocalDevelopmentMode: false,
|
||||||
role: "master",
|
role: "master",
|
||||||
client: clientFake,
|
client: clientFake,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := r.Reconcile(context.Background(), tt.request)
|
_, err := r.Reconcile(ctx, tt.request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cluster, err := r.arocli.AroV1alpha1().Clusters().Get(context.Background(), arov1alpha1.SingletonClusterName, metav1.GetOptions{})
|
cluster := &arov1alpha1.Cluster{}
|
||||||
|
err = r.client.Get(ctx, types.NamespacedName{Name: arov1alpha1.SingletonClusterName}, cluster)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,13 @@ import (
|
||||||
|
|
||||||
operatorv1 "github.com/openshift/api/operator/v1"
|
operatorv1 "github.com/openshift/api/operator/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
"k8s.io/apimachinery/pkg/util/clock"
|
||||||
"k8s.io/client-go/util/retry"
|
"k8s.io/client-go/util/retry"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
"github.com/Azure/ARO-RP/pkg/operator"
|
"github.com/Azure/ARO-RP/pkg/operator"
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
|
|
||||||
"github.com/Azure/ARO-RP/pkg/util/version"
|
"github.com/Azure/ARO-RP/pkg/util/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,13 +22,14 @@ import (
|
||||||
// This variable makes it easier to test conditions.
|
// This variable makes it easier to test conditions.
|
||||||
var kubeclock clock.Clock = &clock.RealClock{}
|
var kubeclock clock.Clock = &clock.RealClock{}
|
||||||
|
|
||||||
// TODO: Need to get rid of dependency on aroclient.Interface and replace it with a client from controller-runtime.
|
func SetCondition(ctx context.Context, c client.Client, cond *operatorv1.OperatorCondition, role string) error {
|
||||||
func SetCondition(ctx context.Context, arocli aroclient.Interface, cond *operatorv1.OperatorCondition, role string) error {
|
|
||||||
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
||||||
if cond == nil {
|
if cond == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cluster, err := arocli.AroV1alpha1().Clusters().Get(ctx, arov1alpha1.SingletonClusterName, metav1.GetOptions{})
|
|
||||||
|
cluster := &arov1alpha1.Cluster{}
|
||||||
|
err := c.Get(ctx, types.NamespacedName{Name: arov1alpha1.SingletonClusterName}, cluster)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -43,8 +45,7 @@ func SetCondition(ctx context.Context, arocli aroclient.Interface, cond *operato
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = arocli.AroV1alpha1().Clusters().UpdateStatus(ctx, cluster, metav1.UpdateOptions{})
|
return c.Status().Update(ctx, cluster)
|
||||||
return err
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,19 +5,19 @@ package conditions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
operatorv1 "github.com/openshift/api/operator/v1"
|
operatorv1 "github.com/openshift/api/operator/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
kruntime "k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/clock"
|
"k8s.io/apimachinery/pkg/util/clock"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||||
|
|
||||||
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
|
||||||
aroclient "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned"
|
|
||||||
arofake "github.com/Azure/ARO-RP/pkg/operator/clientset/versioned/fake"
|
|
||||||
"github.com/Azure/ARO-RP/pkg/util/cmp"
|
"github.com/Azure/ARO-RP/pkg/util/cmp"
|
||||||
|
_ "github.com/Azure/ARO-RP/pkg/util/scheme"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSetCondition(t *testing.T) {
|
func TestSetCondition(t *testing.T) {
|
||||||
|
@ -26,13 +26,12 @@ func TestSetCondition(t *testing.T) {
|
||||||
objectName := "cluster"
|
objectName := "cluster"
|
||||||
version := "unknown"
|
version := "unknown"
|
||||||
|
|
||||||
kubeclock = &clock.FakeClock{}
|
kubeclock = clock.NewFakeClock(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC))
|
||||||
var transitionTime = metav1.Time{Time: kubeclock.Now()}
|
var transitionTime = metav1.Time{Time: kubeclock.Now()}
|
||||||
|
|
||||||
for _, tt := range []struct {
|
for _, tt := range []struct {
|
||||||
name string
|
name string
|
||||||
aroclient aroclient.Interface
|
objects []client.Object
|
||||||
objects []kruntime.Object
|
|
||||||
input *operatorv1.OperatorCondition
|
input *operatorv1.OperatorCondition
|
||||||
|
|
||||||
expected arov1alpha1.ClusterStatus
|
expected arov1alpha1.ClusterStatus
|
||||||
|
@ -40,7 +39,7 @@ func TestSetCondition(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no condition provided",
|
name: "no condition provided",
|
||||||
objects: []kruntime.Object{&arov1alpha1.Cluster{
|
objects: []client.Object{&arov1alpha1.Cluster{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: objectName,
|
Name: objectName,
|
||||||
},
|
},
|
||||||
|
@ -49,7 +48,7 @@ func TestSetCondition(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "new condition provided",
|
name: "new condition provided",
|
||||||
objects: []kruntime.Object{&arov1alpha1.Cluster{
|
objects: []client.Object{&arov1alpha1.Cluster{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: objectName,
|
Name: objectName,
|
||||||
},
|
},
|
||||||
|
@ -67,6 +66,7 @@ func TestSetCondition(t *testing.T) {
|
||||||
{
|
{
|
||||||
Type: arov1alpha1.InternetReachableFromMaster,
|
Type: arov1alpha1.InternetReachableFromMaster,
|
||||||
Status: operatorv1.ConditionFalse,
|
Status: operatorv1.ConditionFalse,
|
||||||
|
LastTransitionTime: transitionTime,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
OperatorVersion: version,
|
OperatorVersion: version,
|
||||||
|
@ -74,7 +74,7 @@ func TestSetCondition(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "condition provided without status change - only update operator version",
|
name: "condition provided without status change - only update operator version",
|
||||||
objects: []kruntime.Object{&arov1alpha1.Cluster{
|
objects: []client.Object{&arov1alpha1.Cluster{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: objectName,
|
Name: objectName,
|
||||||
},
|
},
|
||||||
|
@ -104,7 +104,7 @@ func TestSetCondition(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "condition provided without status change - no update",
|
name: "condition provided without status change - no update",
|
||||||
objects: []kruntime.Object{&arov1alpha1.Cluster{
|
objects: []client.Object{&arov1alpha1.Cluster{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: objectName,
|
Name: objectName,
|
||||||
},
|
},
|
||||||
|
@ -113,7 +113,7 @@ func TestSetCondition(t *testing.T) {
|
||||||
{
|
{
|
||||||
Type: arov1alpha1.InternetReachableFromMaster,
|
Type: arov1alpha1.InternetReachableFromMaster,
|
||||||
Status: operatorv1.ConditionFalse,
|
Status: operatorv1.ConditionFalse,
|
||||||
LastTransitionTime: metav1.Time{Time: time.Date(1970, 0, 0, 0, 0, 0, 0, time.UTC)},
|
LastTransitionTime: metav1.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
OperatorVersion: version,
|
OperatorVersion: version,
|
||||||
|
@ -122,14 +122,14 @@ func TestSetCondition(t *testing.T) {
|
||||||
input: &operatorv1.OperatorCondition{
|
input: &operatorv1.OperatorCondition{
|
||||||
Type: arov1alpha1.InternetReachableFromMaster,
|
Type: arov1alpha1.InternetReachableFromMaster,
|
||||||
Status: operatorv1.ConditionFalse,
|
Status: operatorv1.ConditionFalse,
|
||||||
LastTransitionTime: metav1.Time{Time: time.Date(2021, 0, 0, 0, 0, 0, 0, time.UTC)},
|
LastTransitionTime: metav1.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
},
|
},
|
||||||
expected: arov1alpha1.ClusterStatus{
|
expected: arov1alpha1.ClusterStatus{
|
||||||
Conditions: []operatorv1.OperatorCondition{
|
Conditions: []operatorv1.OperatorCondition{
|
||||||
{
|
{
|
||||||
Type: arov1alpha1.InternetReachableFromMaster,
|
Type: arov1alpha1.InternetReachableFromMaster,
|
||||||
Status: operatorv1.ConditionFalse,
|
Status: operatorv1.ConditionFalse,
|
||||||
LastTransitionTime: metav1.Time{Time: time.Date(1970, 0, 0, 0, 0, 0, 0, time.UTC)},
|
LastTransitionTime: metav1.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
OperatorVersion: version,
|
OperatorVersion: version,
|
||||||
|
@ -137,7 +137,7 @@ func TestSetCondition(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "update one of the existing conditions",
|
name: "update one of the existing conditions",
|
||||||
objects: []kruntime.Object{&arov1alpha1.Cluster{
|
objects: []client.Object{&arov1alpha1.Cluster{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: objectName,
|
Name: objectName,
|
||||||
},
|
},
|
||||||
|
@ -176,7 +176,7 @@ func TestSetCondition(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "cleanup stale conditions",
|
name: "cleanup stale conditions",
|
||||||
objects: []kruntime.Object{&arov1alpha1.Cluster{
|
objects: []client.Object{&arov1alpha1.Cluster{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: objectName,
|
Name: objectName,
|
||||||
},
|
},
|
||||||
|
@ -207,20 +207,28 @@ func TestSetCondition(t *testing.T) {
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
client := arofake.NewSimpleClientset(tt.objects...)
|
clientFake := fake.NewClientBuilder().WithObjects(tt.objects...).Build()
|
||||||
|
|
||||||
err := SetCondition(ctx, client, tt.input, role)
|
err := SetCondition(ctx, clientFake, tt.input, role)
|
||||||
if err != nil && tt.wantErr != nil {
|
if err != nil && tt.wantErr != nil {
|
||||||
t.Fatal(err.Error())
|
t.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := client.AroV1alpha1().Clusters().Get(ctx, objectName, metav1.GetOptions{})
|
result := &arov1alpha1.Cluster{}
|
||||||
|
err = clientFake.Get(ctx, types.NamespacedName{Name: arov1alpha1.SingletonClusterName}, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err.Error())
|
t.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(result.Status, tt.expected) {
|
// cmp.Diff correctly compares times the same time, but in different timezones
|
||||||
t.Fatal(cmp.Diff(result.Status, tt.expected))
|
// unlike reflect.DeepEqual which compares field by field.
|
||||||
|
// We need this because fake client marshals and unmarshals objects
|
||||||
|
// due to this line[1] in apimachiner time than gets converted to a local time.
|
||||||
|
//
|
||||||
|
// [1] https://github.com/kubernetes/apimachinery/blob/24bec8a7ae9ed9efe31aa9239cc616d751c2bc69/pkg/apis/meta/v1/time.go#L115
|
||||||
|
diff := cmp.Diff(result.Status, tt.expected)
|
||||||
|
if diff != "" {
|
||||||
|
t.Fatal(diff)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче