Skip to content

Commit

Permalink
feature: add aro cluster to workaround
Browse files Browse the repository at this point in the history
Adds aro cluster instance to IsRequires check
to allow for feature flags checking.

Signed-off-by: Petr Kotas <[email protected]>
  • Loading branch information
petrkotas committed Mar 16, 2022
1 parent 3564784 commit 61a18d2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pkg/operator/controllers/workaround/ifreload.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"

arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/util/version"
)

Expand All @@ -36,7 +37,7 @@ func (*ifReload) Name() string {
return "ifReload"
}

func (i *ifReload) IsRequired(clusterVersion *version.Version) bool {
func (i *ifReload) IsRequired(clusterVersion *version.Version, cluster *arov1alpha1.Cluster) bool {
return clusterVersion.Lt(i.versionFixed)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/operator/controllers/workaround/systemreserved.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
kruntime "k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/util/dynamichelper"
"github.com/Azure/ARO-RP/pkg/util/version"
)
Expand Down Expand Up @@ -45,7 +46,7 @@ func (sr *systemreserved) Name() string {
return "SystemReserved fix for bz-1857446"
}

func (sr *systemreserved) IsRequired(clusterVersion *version.Version) bool {
func (sr *systemreserved) IsRequired(clusterVersion *version.Version, cluster *arov1alpha1.Cluster) bool {
return clusterVersion.Lt(sr.versionFixed)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/operator/controllers/workaround/workaround.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package workaround
import (
"context"

arov1alpha1 "github.com/Azure/ARO-RP/pkg/operator/apis/aro.openshift.io/v1alpha1"
"github.com/Azure/ARO-RP/pkg/util/version"
)

Expand All @@ -14,7 +15,7 @@ type Workaround interface {
Name() string
// IsRequired returns true when the clusterversion is indicates that the cluster
// is effected by the bug that the workaround fixes.
IsRequired(clusterVersion *version.Version) bool
IsRequired(clusterVersion *version.Version, cluster *arov1alpha1.Cluster) bool
// Ensure will apply the workaround to the cluster.
Ensure(context.Context) error
// Remove will remove the workaround from the cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.
}

for _, wa := range r.workarounds {
if wa.IsRequired(clusterVersion) {
if wa.IsRequired(clusterVersion, instance) {
err = wa.Ensure(ctx)
} else {
err = wa.Remove(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ func TestWorkaroundReconciler(t *testing.T) {
{
name: "is required",
mocker: func(mw *mock_workaround.MockWorkaround) {
c := mw.EXPECT().IsRequired(gomock.Any()).Return(true)
c := mw.EXPECT().IsRequired(gomock.Any(), gomock.Any()).Return(true)
mw.EXPECT().Ensure(gomock.Any()).After(c).Return(nil)
},
want: ctrl.Result{RequeueAfter: time.Hour},
},
{
name: "is not required",
mocker: func(mw *mock_workaround.MockWorkaround) {
c := mw.EXPECT().IsRequired(gomock.Any()).Return(false)
c := mw.EXPECT().IsRequired(gomock.Any(), gomock.Any()).Return(false)
mw.EXPECT().Remove(gomock.Any()).After(c).Return(nil)
},
want: ctrl.Result{RequeueAfter: time.Hour},
},
{
name: "has error",
mocker: func(mw *mock_workaround.MockWorkaround) {
mw.EXPECT().IsRequired(gomock.Any()).Return(true)
mw.EXPECT().IsRequired(gomock.Any(), gomock.Any()).Return(true)
mw.EXPECT().Name().Return("test").AnyTimes()
mw.EXPECT().Ensure(gomock.Any()).Return(fmt.Errorf("oops"))
},
Expand Down
9 changes: 5 additions & 4 deletions pkg/util/mocks/operator/controllers/workaround/workaround.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 61a18d2

Please sign in to comment.